blob: 860cf494bfadbc2797dac300d8f8ff53cab34828 [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 */
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301177 peer = wlan_hdd_tdls_find_peer(pAdapter, mac, FALSE);
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
Gopichand Nakkala4ddf0192013-03-27 13:41:20 -07001190 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
1191
1192 if (NULL == pHddTdlsCtx)
1193 {
1194 vos_mem_free(peer);
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301195 mutex_unlock(&pHddCtx->tdls_lock);
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05301196 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
1197 FL("pHddTdlsCtx is NULL"));
Gopichand Nakkala4ddf0192013-03-27 13:41:20 -07001198 return NULL;
1199 }
1200
1201 key = wlan_hdd_tdls_hash_key(mac);
1202 head = &pHddTdlsCtx->peer_list[key];
Chilam NG571c65a2013-01-19 12:27:36 +05301203
Hoonki Lee387663d2013-02-05 18:08:43 -08001204 vos_mem_zero(peer, sizeof(hddTdlsPeer_t));
1205 vos_mem_copy(peer->peerMac, mac, sizeof(peer->peerMac));
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001206 peer->pHddTdlsCtx = pHddTdlsCtx;
Hoonki Lee387663d2013-02-05 18:08:43 -08001207
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001208 vos_timer_init(&peer->peerIdleTimer,
1209 VOS_TIMER_TYPE_SW,
1210 wlan_hdd_tdls_idle_cb,
1211 peer);
1212
Hoonki Lee14621352013-04-16 17:51:19 -07001213 vos_timer_init(&peer->initiatorWaitTimeoutTimer,
1214 VOS_TIMER_TYPE_SW,
1215 wlan_hdd_tdls_initiator_wait_cb,
1216 peer);
1217
Hoonki Lee387663d2013-02-05 18:08:43 -08001218 list_add_tail(&peer->node, head);
Hoonki Lee387663d2013-02-05 18:08:43 -08001219
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301220 EXIT();
Hoonki Lee387663d2013-02-05 18:08:43 -08001221 return peer;
1222}
1223
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001224int wlan_hdd_tdls_set_cap(hdd_adapter_t *pAdapter,
Hoonki Lee27511902013-03-14 18:19:06 -07001225 u8* mac,
1226 tTDLSCapType cap)
1227{
1228 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301229 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Lee27511902013-03-14 18:19:06 -07001230
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301231 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1232 return -EINVAL;
1233
1234 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001235 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee27511902013-03-14 18:19:06 -07001236 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301237 {
1238 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1239 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301240 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001241 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301242 }
Hoonki Lee27511902013-03-14 18:19:06 -07001243
1244 curr_peer->tdls_support = cap;
1245
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301246 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001247 return 0;
Hoonki Lee27511902013-03-14 18:19:06 -07001248}
1249
Atul Mittal115287b2014-07-08 13:26:33 +05301250void wlan_hdd_tdls_set_peer_link_status(hddTdlsPeer_t *curr_peer,
1251 tTDLSLinkStatus status,
1252 tTDLSLinkReason reason)
Hoonki Lee387663d2013-02-05 18:08:43 -08001253{
Atul Mittal115287b2014-07-08 13:26:33 +05301254 /*EXT TDLS*/
1255 tANI_S32 state = 0;
1256 tANI_S32 res = 0;
1257 /*EXT TDLS*/
Hoonki Lee387663d2013-02-05 18:08:43 -08001258 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301259 {
1260 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1261 "%s: curr_peer is NULL", __func__);
Hoonki Lee387663d2013-02-05 18:08:43 -08001262 return;
c_hpothu7f63e882013-10-02 19:13:35 +05301263 }
Hoonki Lee387663d2013-02-05 18:08:43 -08001264
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001265 hddLog(VOS_TRACE_LEVEL_WARN, "tdls set peer " MAC_ADDRESS_STR " link status to %u",
Chilam Ng01120412013-02-19 18:32:21 -08001266 MAC_ADDR_ARRAY(curr_peer->peerMac), status);
Chilam NG571c65a2013-01-19 12:27:36 +05301267
1268 curr_peer->link_status = status;
1269
Atul Mittal115287b2014-07-08 13:26:33 +05301270 /*EXT TDLS*/
1271 if (curr_peer->isForcedPeer && curr_peer->state_change_notification)
1272 {
1273 /*save the reason for any further query*/
1274 curr_peer->reason = reason;
1275 wlan_hdd_tdls_get_wifi_hal_state(curr_peer, &state, &res);
1276
1277 (curr_peer->state_change_notification)(
1278 curr_peer->peerMac,
1279 state,
1280 res,
1281 curr_peer->pHddTdlsCtx->pAdapter);
1282
1283 }
1284 /*EXT TDLS*/
1285
Chilam NG571c65a2013-01-19 12:27:36 +05301286}
1287
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001288void wlan_hdd_tdls_set_link_status(hdd_adapter_t *pAdapter,
1289 u8* mac,
Atul Mittal115287b2014-07-08 13:26:33 +05301290 tTDLSLinkStatus linkStatus,
1291 tTDLSLinkReason reason)
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001292{
Atul Mittal115287b2014-07-08 13:26:33 +05301293
1294 /*EXT TDLS*/
1295 tANI_S32 state = 0;
1296 tANI_S32 res = 0;
1297 /*EXT TDLS*/
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001298 hddTdlsPeer_t *curr_peer;
1299
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301300 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001301 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301302 {
1303 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1304 "%s: curr_peer is NULL", __func__);
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001305 return;
c_hpothu7f63e882013-10-02 19:13:35 +05301306 }
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001307
1308 curr_peer->link_status= linkStatus;
1309
Atul Mittal115287b2014-07-08 13:26:33 +05301310 /*EXT TDLS*/
1311
1312 if (curr_peer->isForcedPeer && curr_peer->state_change_notification)
1313 {
1314 /*save the reason for any further query*/
1315 curr_peer->reason = reason;
1316 wlan_hdd_tdls_get_wifi_hal_state(curr_peer, &state, &res);
1317
1318 (*curr_peer->state_change_notification)(mac,
1319 state,
1320 res,
1321 curr_peer->pHddTdlsCtx->pAdapter);
1322
1323 }
1324 /*EXT TDLS*/
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001325 return;
1326}
1327
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001328int wlan_hdd_tdls_recv_discovery_resp(hdd_adapter_t *pAdapter, u8 *mac)
Chilam NG571c65a2013-01-19 12:27:36 +05301329{
1330 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001331 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301332 hdd_context_t *pHddCtx;
1333
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301334 ENTER();
1335
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301336 if ( NULL == pHddTdlsCtx )
c_hpothu7f63e882013-10-02 19:13:35 +05301337 {
1338 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05301339 FL("pHddTdlsCtx is NULL device mode = %d"), pAdapter->device_mode);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301340 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301341 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301342
1343 pHddCtx = WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter);
1344
c_hpothu7f63e882013-10-02 19:13:35 +05301345 if(0 != (wlan_hdd_validate_context(pHddCtx)))
1346 {
c_hpothu7f63e882013-10-02 19:13:35 +05301347 return 0;
1348 }
Chilam NG571c65a2013-01-19 12:27:36 +05301349
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301350 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001351 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001352
1353 if (NULL == curr_peer)
c_hpothu7f63e882013-10-02 19:13:35 +05301354 {
1355 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1356 FL("curr_peer is NULL"));
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301357 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001358 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301359 }
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301360 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001361
1362 if (pHddTdlsCtx->discovery_sent_cnt)
1363 pHddTdlsCtx->discovery_sent_cnt--;
1364
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301365 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301366
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001367 wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301368
1369 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001370 if (0 == pHddTdlsCtx->discovery_sent_cnt)
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07001371 {
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001372 vos_timer_stop(&pHddTdlsCtx->peerDiscoveryTimeoutTimer);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07001373 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001374
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301375 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001376 "Discovery(%u) Response from " MAC_ADDRESS_STR " link_status %d",
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001377 pHddTdlsCtx->discovery_sent_cnt, MAC_ADDR_ARRAY(curr_peer->peerMac),
1378 curr_peer->link_status);
1379
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001380 if (eTDLS_LINK_DISCOVERING == curr_peer->link_status)
Gopichand Nakkala901e8922013-03-04 23:45:58 -08001381 {
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001382 /* Since we are here, it means Throughput threshold is alredy met. Make sure RSSI
1383 threshold is also met before setting up TDLS link*/
1384 if ((tANI_S32) curr_peer->rssi > (tANI_S32) pHddTdlsCtx->threshold_config.rssi_trigger_threshold)
1385 {
Atul Mittal115287b2014-07-08 13:26:33 +05301386 wlan_hdd_tdls_set_peer_link_status(curr_peer,
1387 eTDLS_LINK_DISCOVERED,
1388 eTDLS_LINK_SUCCESS);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301389 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001390 "Rssi Threshold met: "MAC_ADDRESS_STR" rssi = %d threshold= %d" ,
1391 MAC_ADDR_ARRAY(curr_peer->peerMac), curr_peer->rssi,
1392 pHddTdlsCtx->threshold_config.rssi_trigger_threshold);
1393 cfg80211_tdls_oper_request(pAdapter->dev, curr_peer->peerMac, NL80211_TDLS_SETUP, FALSE, GFP_KERNEL);
1394 }
1395 else
1396 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301397 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001398 "Rssi Threshold not met: "MAC_ADDRESS_STR" rssi = %d threshold = %d ",
1399 MAC_ADDR_ARRAY(curr_peer->peerMac), curr_peer->rssi,
1400 pHddTdlsCtx->threshold_config.rssi_trigger_threshold);
Sunil Duttb0d39242014-09-10 23:54:51 +05301401
1402 /* if RSSI threshold is not met then allow further discovery
1403 * attempts by decrementing count for the last attempt
1404 */
1405 if (curr_peer->discovery_attempt)
1406 curr_peer->discovery_attempt--;
1407
Atul Mittal115287b2014-07-08 13:26:33 +05301408 wlan_hdd_tdls_set_peer_link_status(curr_peer,
1409 eTDLS_LINK_IDLE,
1410 eTDLS_LINK_UNSPECIFIED);
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001411 }
Gopichand Nakkala901e8922013-03-04 23:45:58 -08001412 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07001413 else
1414 {
1415 wlan_hdd_tdls_check_bmps(pAdapter);
1416 }
Chilam NG571c65a2013-01-19 12:27:36 +05301417
Gopichand Nakkala901e8922013-03-04 23:45:58 -08001418 curr_peer->tdls_support = eTDLS_CAP_SUPPORTED;
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301419 EXIT();
Hoonki Lee387663d2013-02-05 18:08:43 -08001420 return 0;
Chilam NG571c65a2013-01-19 12:27:36 +05301421}
1422
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301423int wlan_hdd_tdls_set_peer_caps(hdd_adapter_t *pAdapter,
1424 u8 *mac,
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301425 tCsrStaParams *StaParams,
1426 tANI_BOOLEAN isBufSta,
1427 tANI_BOOLEAN isOffChannelSupported)
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301428{
1429 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301430 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301431
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301432 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1433 return -EINVAL;
1434
1435 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301436 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
1437 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301438 {
1439 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1440 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301441 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301442 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301443 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301444
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301445 curr_peer->uapsdQueues = StaParams->uapsd_queues;
1446 curr_peer->maxSp = StaParams->max_sp;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301447 curr_peer->isBufSta = isBufSta;
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301448 curr_peer->isOffChannelSupported = isOffChannelSupported;
1449
1450 vos_mem_copy(curr_peer->supported_channels,
1451 StaParams->supported_channels,
1452 StaParams->supported_channels_len);
1453
1454 curr_peer->supported_channels_len =
1455 StaParams->supported_channels_len;
1456
1457 vos_mem_copy(curr_peer->supported_oper_classes,
1458 StaParams->supported_oper_classes,
1459 StaParams->supported_oper_classes_len);
1460
1461 curr_peer->supported_oper_classes_len =
1462 StaParams->supported_oper_classes_len;
Agarwal Ashish16020c42014-12-29 22:01:11 +05301463 curr_peer->qos = StaParams->capability & CAPABILITIES_QOS_OFFSET;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301464
1465 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301466 return 0;
1467}
1468
1469int wlan_hdd_tdls_get_link_establish_params(hdd_adapter_t *pAdapter, u8 *mac,
1470 tCsrTdlsLinkEstablishParams* tdlsLinkEstablishParams)
1471{
1472 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301473 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301474
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301475 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1476 return -EINVAL;
1477
1478 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301479 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
1480 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301481 {
1482 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1483 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301484 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301485 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301486 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301487
1488 tdlsLinkEstablishParams->isResponder = curr_peer->is_responder;
1489 tdlsLinkEstablishParams->uapsdQueues = curr_peer->uapsdQueues;
1490 tdlsLinkEstablishParams->maxSp = curr_peer->maxSp;
1491 tdlsLinkEstablishParams->isBufSta = curr_peer->isBufSta;
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301492 tdlsLinkEstablishParams->isOffChannelSupported =
1493 curr_peer->isOffChannelSupported;
1494
1495 vos_mem_copy(tdlsLinkEstablishParams->supportedChannels,
1496 curr_peer->supported_channels,
1497 curr_peer->supported_channels_len);
1498
1499 tdlsLinkEstablishParams->supportedChannelsLen =
1500 curr_peer->supported_channels_len;
1501
1502 vos_mem_copy(tdlsLinkEstablishParams->supportedOperClasses,
1503 curr_peer->supported_oper_classes,
1504 curr_peer->supported_oper_classes_len);
1505
1506 tdlsLinkEstablishParams->supportedOperClassesLen =
1507 curr_peer->supported_oper_classes_len;
Agarwal Ashish16020c42014-12-29 22:01:11 +05301508 tdlsLinkEstablishParams->qos = curr_peer->qos;
1509
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301510 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301511 return 0;
1512}
1513
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001514int wlan_hdd_tdls_set_rssi(hdd_adapter_t *pAdapter, u8 *mac, tANI_S8 rxRssi)
Chilam NG571c65a2013-01-19 12:27:36 +05301515{
1516 hddTdlsPeer_t *curr_peer;
Chilam NG571c65a2013-01-19 12:27:36 +05301517
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301518 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Hoonki Lee387663d2013-02-05 18:08:43 -08001519 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301520 {
1521 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1522 "%s: curr_peer is NULL", __func__);
Hoonki Lee387663d2013-02-05 18:08:43 -08001523 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301524 }
Chilam NG571c65a2013-01-19 12:27:36 +05301525
1526 curr_peer->rssi = rxRssi;
1527
Hoonki Lee387663d2013-02-05 18:08:43 -08001528 return 0;
Chilam NG571c65a2013-01-19 12:27:36 +05301529}
1530
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001531int wlan_hdd_tdls_set_responder(hdd_adapter_t *pAdapter, u8 *mac, tANI_U8 responder)
Hoonki Leea34dd892013-02-05 22:56:02 -08001532{
1533 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301534 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Leea34dd892013-02-05 22:56:02 -08001535
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301536 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1537 return -EINVAL;
1538
1539 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001540 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001541 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301542 {
1543 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1544 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301545 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leea34dd892013-02-05 22:56:02 -08001546 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301547 }
Hoonki Leea34dd892013-02-05 22:56:02 -08001548
1549 curr_peer->is_responder = responder;
1550
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301551 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leea34dd892013-02-05 22:56:02 -08001552 return 0;
1553}
1554
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001555int wlan_hdd_tdls_get_responder(hdd_adapter_t *pAdapter, u8 *mac)
Hoonki Leea34dd892013-02-05 22:56:02 -08001556{
1557 hddTdlsPeer_t *curr_peer;
1558
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301559 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001560 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301561 {
1562 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1563 "%s: curr_peer is NULL", __func__);
Hoonki Leea34dd892013-02-05 22:56:02 -08001564 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301565 }
Hoonki Leea34dd892013-02-05 22:56:02 -08001566
1567 return (curr_peer->is_responder);
1568}
1569
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001570int wlan_hdd_tdls_set_signature(hdd_adapter_t *pAdapter, u8 *mac, tANI_U8 uSignature)
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001571{
1572 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301573 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001574
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301575 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1576 return -EINVAL;
1577
1578 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001579 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001580 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301581 {
1582 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1583 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301584 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001585 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301586 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001587
1588 curr_peer->signature = uSignature;
1589
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301590 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001591 return 0;
1592}
1593
Hoonki Leea34dd892013-02-05 22:56:02 -08001594
Hoonki Lee387663d2013-02-05 18:08:43 -08001595void wlan_hdd_tdls_extract_da(struct sk_buff *skb, u8 *mac)
Chilam NG571c65a2013-01-19 12:27:36 +05301596{
Chilam NG571c65a2013-01-19 12:27:36 +05301597 memcpy(mac, skb->data, 6);
Chilam NG571c65a2013-01-19 12:27:36 +05301598}
1599
Hoonki Lee387663d2013-02-05 18:08:43 -08001600void wlan_hdd_tdls_extract_sa(struct sk_buff *skb, u8 *mac)
Chilam Ng1279e232013-01-25 15:06:52 -08001601{
Chilam Ng1279e232013-01-25 15:06:52 -08001602 memcpy(mac, skb->data+6, 6);
Chilam Ng1279e232013-01-25 15:06:52 -08001603}
1604
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001605int wlan_hdd_tdls_increment_pkt_count(hdd_adapter_t *pAdapter, u8 *mac, u8 tx)
Chilam NG571c65a2013-01-19 12:27:36 +05301606{
Hoonki Lee387663d2013-02-05 18:08:43 -08001607 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001608 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Chilam NG571c65a2013-01-19 12:27:36 +05301609
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301610 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1611 return -EINVAL;
1612
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001613 if (eTDLS_SUPPORT_ENABLED != pHddCtx->tdls_mode)
1614 return -1;
Hoonki Leebfee0342013-01-21 16:43:45 -08001615
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301616 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001617 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee387663d2013-02-05 18:08:43 -08001618 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301619 {
c_hpothue21931b2014-09-08 14:02:14 +05301620 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
1621 FL("curr_peer is NULL"));
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301622 mutex_unlock(&pHddCtx->tdls_lock);
Chilam NG571c65a2013-01-19 12:27:36 +05301623 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301624 }
Chilam NG571c65a2013-01-19 12:27:36 +05301625
Chilam Ng1279e232013-01-25 15:06:52 -08001626 if (tx)
1627 curr_peer->tx_pkt++;
1628 else
1629 curr_peer->rx_pkt++;
Chilam NG571c65a2013-01-19 12:27:36 +05301630
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301631 mutex_unlock(&pHddCtx->tdls_lock);
Chilam NG571c65a2013-01-19 12:27:36 +05301632 return 0;
1633}
1634
Hoonki Lee27511902013-03-14 18:19:06 -07001635static int wlan_hdd_tdls_check_config(tdls_config_params_t *config)
1636{
1637 if (config->tdls > 2)
1638 {
1639 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 1st argument %d. <0...2>", __func__, config->tdls);
1640 return -1;
1641 }
1642 if (config->tx_period_t < CFG_TDLS_TX_STATS_PERIOD_MIN ||
1643 config->tx_period_t > CFG_TDLS_TX_STATS_PERIOD_MAX)
1644 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001645 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 2nd argument %d. <%d...%ld>", __func__, config->tx_period_t,
Hoonki Lee27511902013-03-14 18:19:06 -07001646 CFG_TDLS_TX_STATS_PERIOD_MIN, CFG_TDLS_TX_STATS_PERIOD_MAX);
1647 return -1;
1648 }
1649 if (config->tx_packet_n < CFG_TDLS_TX_PACKET_THRESHOLD_MIN ||
1650 config->tx_packet_n > CFG_TDLS_TX_PACKET_THRESHOLD_MAX)
1651 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001652 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 3rd argument %d. <%d...%ld>", __func__, config->tx_packet_n,
Hoonki Lee27511902013-03-14 18:19:06 -07001653 CFG_TDLS_TX_PACKET_THRESHOLD_MIN, CFG_TDLS_TX_PACKET_THRESHOLD_MAX);
1654 return -1;
1655 }
1656 if (config->discovery_period_t < CFG_TDLS_DISCOVERY_PERIOD_MIN ||
1657 config->discovery_period_t > CFG_TDLS_DISCOVERY_PERIOD_MAX)
1658 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001659 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 4th argument %d. <%d...%ld>", __func__, config->discovery_period_t,
Hoonki Lee27511902013-03-14 18:19:06 -07001660 CFG_TDLS_DISCOVERY_PERIOD_MIN, CFG_TDLS_DISCOVERY_PERIOD_MAX);
1661 return -1;
1662 }
1663 if (config->discovery_tries_n < CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MIN ||
1664 config->discovery_tries_n > CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MAX)
1665 {
1666 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 5th argument %d. <%d...%d>", __func__, config->discovery_tries_n,
1667 CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MIN, CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MAX);
1668 return -1;
1669 }
1670 if (config->idle_timeout_t < CFG_TDLS_IDLE_TIMEOUT_MIN ||
1671 config->idle_timeout_t > CFG_TDLS_IDLE_TIMEOUT_MAX)
1672 {
1673 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 6th argument %d. <%d...%d>", __func__, config->idle_timeout_t,
1674 CFG_TDLS_IDLE_TIMEOUT_MIN, CFG_TDLS_IDLE_TIMEOUT_MAX);
1675 return -1;
1676 }
1677 if (config->idle_packet_n < CFG_TDLS_IDLE_PACKET_THRESHOLD_MIN ||
1678 config->idle_packet_n > CFG_TDLS_IDLE_PACKET_THRESHOLD_MAX)
1679 {
1680 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 7th argument %d. <%d...%d>", __func__, config->idle_packet_n,
1681 CFG_TDLS_IDLE_PACKET_THRESHOLD_MIN, CFG_TDLS_IDLE_PACKET_THRESHOLD_MAX);
1682 return -1;
1683 }
1684 if (config->rssi_hysteresis < CFG_TDLS_RSSI_HYSTERESIS_MIN ||
1685 config->rssi_hysteresis > CFG_TDLS_RSSI_HYSTERESIS_MAX)
1686 {
1687 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 8th argument %d. <%d...%d>", __func__, config->rssi_hysteresis,
1688 CFG_TDLS_RSSI_HYSTERESIS_MIN, CFG_TDLS_RSSI_HYSTERESIS_MAX);
1689 return -1;
1690 }
1691 if (config->rssi_trigger_threshold < CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MIN ||
1692 config->rssi_trigger_threshold > CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MAX)
1693 {
1694 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 9th argument %d. <%d...%d>", __func__, config->rssi_trigger_threshold,
1695 CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MIN, CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MAX);
1696 return -1;
1697 }
1698 if (config->rssi_teardown_threshold < CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MIN ||
1699 config->rssi_teardown_threshold > CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MAX)
1700 {
1701 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 10th argument %d. <%d...%d>", __func__, config->rssi_teardown_threshold,
1702 CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MIN, CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MAX);
1703 return -1;
1704 }
1705 return 0;
1706}
1707
Chilam Ng01120412013-02-19 18:32:21 -08001708int wlan_hdd_tdls_set_params(struct net_device *dev, tdls_config_params_t *config)
Chilam NG571c65a2013-01-19 12:27:36 +05301709{
Chilam Ng01120412013-02-19 18:32:21 -08001710 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
1711 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001712 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Hoonki Lee27511902013-03-14 18:19:06 -07001713 eTDLSSupportMode req_tdls_mode;
Hoonki Leebfee0342013-01-21 16:43:45 -08001714
Hoonki Lee27511902013-03-14 18:19:06 -07001715 if (NULL == pHddTdlsCtx)
1716 {
c_hpothu7f63e882013-10-02 19:13:35 +05301717 hddLog(VOS_TRACE_LEVEL_ERROR, FL("TDLS not enabled!"));
Hoonki Lee27511902013-03-14 18:19:06 -07001718 return -1;
Chilam Ng01120412013-02-19 18:32:21 -08001719 }
Chilam NG571c65a2013-01-19 12:27:36 +05301720
Hoonki Lee27511902013-03-14 18:19:06 -07001721 if (wlan_hdd_tdls_check_config(config) != 0)
1722 {
1723 return -1;
1724 }
1725
1726 /* config->tdls is mapped to 0->1, 1->2, 2->3 */
1727 req_tdls_mode = config->tdls + 1;
1728 if (pHddCtx->tdls_mode == req_tdls_mode)
1729 {
1730 hddLog(VOS_TRACE_LEVEL_ERROR, "%s already in mode %d", __func__, config->tdls);
1731 return -1;
1732 }
1733
1734 /* copy the configuration only when given tdls mode is implicit trigger enable */
1735 if (eTDLS_SUPPORT_ENABLED == req_tdls_mode)
1736 {
Chilam Ng01120412013-02-19 18:32:21 -08001737 memcpy(&pHddTdlsCtx->threshold_config, config, sizeof(tdls_config_params_t));
1738 }
Chilam NG571c65a2013-01-19 12:27:36 +05301739
Chilam Ng01120412013-02-19 18:32:21 -08001740 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1741 "iw set tdls params: %d %d %d %d %d %d %d %d %d %d",
1742 config->tdls,
1743 config->tx_period_t,
1744 config->tx_packet_n,
1745 config->discovery_period_t,
1746 config->discovery_tries_n,
1747 config->idle_timeout_t,
1748 config->idle_packet_n,
1749 config->rssi_hysteresis,
1750 config->rssi_trigger_threshold,
1751 config->rssi_teardown_threshold);
Chilam NG571c65a2013-01-19 12:27:36 +05301752
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07001753 wlan_hdd_tdls_set_mode(pHddCtx, req_tdls_mode, TRUE);
Chilam Ng01120412013-02-19 18:32:21 -08001754
Chilam NG571c65a2013-01-19 12:27:36 +05301755 return 0;
1756}
1757
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001758int wlan_hdd_tdls_set_sta_id(hdd_adapter_t *pAdapter, u8 *mac, u8 staId)
Kiran V1ccee932012-12-12 14:49:46 -08001759{
Hoonki Lee387663d2013-02-05 18:08:43 -08001760 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301761 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kiran V1ccee932012-12-12 14:49:46 -08001762
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301763 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1764 return -EINVAL;
1765
1766 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001767 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee387663d2013-02-05 18:08:43 -08001768 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301769 {
1770 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1771 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301772 mutex_unlock(&pHddCtx->tdls_lock);
Chilam NG571c65a2013-01-19 12:27:36 +05301773 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301774 }
Chilam NG571c65a2013-01-19 12:27:36 +05301775
Hoonki Lee387663d2013-02-05 18:08:43 -08001776 curr_peer->staId = staId;
Chilam NG571c65a2013-01-19 12:27:36 +05301777
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301778 mutex_unlock(&pHddCtx->tdls_lock);
Chilam NG571c65a2013-01-19 12:27:36 +05301779 return 0;
Kiran V1ccee932012-12-12 14:49:46 -08001780}
1781
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301782int wlan_hdd_tdls_set_force_peer(hdd_adapter_t *pAdapter, u8 *mac,
1783 tANI_BOOLEAN forcePeer)
Sunil Dutt41de4e22013-11-14 18:09:02 +05301784{
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301785 hddTdlsPeer_t *curr_peer;
Sunil Dutt41de4e22013-11-14 18:09:02 +05301786 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1787
1788 if ((NULL == pHddCtx)) return -1;
1789
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301790 mutex_lock(&pHddCtx->tdls_lock);
1791
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301792 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, FALSE);
1793 if (curr_peer == NULL)
Sunil Dutt41de4e22013-11-14 18:09:02 +05301794 goto error;
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301795 curr_peer->isForcedPeer = forcePeer;
Naresh Jayaramca7bc3a2014-02-04 23:03:04 +05301796
1797 mutex_unlock(&pHddCtx->tdls_lock);
1798 return 0;
Sunil Dutt41de4e22013-11-14 18:09:02 +05301799error:
1800 mutex_unlock(&pHddCtx->tdls_lock);
1801 return -1;
1802}
1803
Hoonki Lee387663d2013-02-05 18:08:43 -08001804/* if peerMac is found, then it returns pointer to hddTdlsPeer_t
1805 otherwise, it returns NULL
1806*/
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301807hddTdlsPeer_t *wlan_hdd_tdls_find_peer(hdd_adapter_t *pAdapter, u8 *mac,
1808 tANI_BOOLEAN mutexLock)
Kiran V1ccee932012-12-12 14:49:46 -08001809{
Hoonki Lee387663d2013-02-05 18:08:43 -08001810 u8 key;
1811 struct list_head *pos;
1812 struct list_head *head;
1813 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001814 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301815 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Lee387663d2013-02-05 18:08:43 -08001816
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301817 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05301818 if(0 != (wlan_hdd_validate_context(pHddCtx)))
1819 {
c_hpothu7f63e882013-10-02 19:13:35 +05301820 return 0;
1821 }
Hoonki Lee387663d2013-02-05 18:08:43 -08001822
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301823 if ( mutexLock )
Hoonki Lee387663d2013-02-05 18:08:43 -08001824 {
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301825 mutex_lock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001826 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001827 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08001828 if (NULL == pHddTdlsCtx)
1829 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301830 if ( mutexLock )
1831 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08001832 return NULL;
1833 }
1834
1835 key = wlan_hdd_tdls_hash_key(mac);
1836
1837 head = &pHddTdlsCtx->peer_list[key];
Hoonki Lee387663d2013-02-05 18:08:43 -08001838
1839 list_for_each(pos, head) {
1840 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
1841 if (!memcmp(mac, curr_peer->peerMac, 6)) {
1842 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
1843 "findTdlsPeer: found staId %d", curr_peer->staId);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301844 if ( mutexLock )
1845 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001846 return curr_peer;
1847 }
1848 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301849 if ( mutexLock )
1850 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301851
1852 EXIT();
Hoonki Lee387663d2013-02-05 18:08:43 -08001853 return NULL;
1854}
1855
Hoonki Leea6d49be2013-04-05 09:43:25 -07001856hddTdlsPeer_t *wlan_hdd_tdls_find_all_peer(hdd_context_t *pHddCtx, u8 *mac)
1857{
1858 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
1859 hdd_adapter_t *pAdapter = NULL;
1860 tdlsCtx_t *pHddTdlsCtx = NULL;
1861 hddTdlsPeer_t *curr_peer= NULL;
1862 VOS_STATUS status = 0;
1863
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301864 mutex_lock(&pHddCtx->tdls_lock);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001865 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
1866 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
1867 {
1868 pAdapter = pAdapterNode->pAdapter;
1869
1870 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
1871 if (NULL != pHddTdlsCtx)
1872 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301873 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, FALSE);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001874 if (curr_peer)
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301875 {
1876 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001877 return curr_peer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301878 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07001879 }
1880 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
1881 pAdapterNode = pNext;
1882 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301883 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001884 return curr_peer;
1885}
1886
1887
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001888int wlan_hdd_tdls_reset_peer(hdd_adapter_t *pAdapter, u8 *mac)
Hoonki Lee387663d2013-02-05 18:08:43 -08001889{
Chilam Ng01120412013-02-19 18:32:21 -08001890 hdd_context_t *pHddCtx;
Chilam NG571c65a2013-01-19 12:27:36 +05301891 hddTdlsPeer_t *curr_peer;
Kiran V1ccee932012-12-12 14:49:46 -08001892
Chilam Ng01120412013-02-19 18:32:21 -08001893 pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
1894
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301895 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1896 return -EINVAL;
1897
1898 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001899 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee387663d2013-02-05 18:08:43 -08001900 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301901 {
1902 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1903 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301904 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001905 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301906 }
Chilam NG571c65a2013-01-19 12:27:36 +05301907
Atul Mittal115287b2014-07-08 13:26:33 +05301908 wlan_hdd_tdls_set_peer_link_status(curr_peer,
1909 eTDLS_LINK_IDLE,
1910 eTDLS_LINK_UNSPECIFIED);
Hoonki Leecdd8e962013-01-20 00:45:46 -08001911 curr_peer->staId = 0;
Hoonki Lee387663d2013-02-05 18:08:43 -08001912
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05301913 /* Throughput Monitor shall disable the split scan when
1914 * TDLS scan coexistance is disabled.At this point of time
1915 * since TDLS scan coexistance is not meeting the criteria
1916 * to be operational, explicitly make it false to enable
1917 * throughput monitor takes the control of split scan.
1918 */
1919 if (pHddCtx->isTdlsScanCoexistence == TRUE)
1920 {
1921 pHddCtx->isTdlsScanCoexistence = FALSE;
1922 }
1923
Chilam Ng01120412013-02-19 18:32:21 -08001924 if(eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode) {
Chilam Nga75d8b62013-01-29 01:35:59 -08001925 vos_timer_stop( &curr_peer->peerIdleTimer );
Chilam Nga75d8b62013-01-29 01:35:59 -08001926 }
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301927
1928 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001929 return 0;
Hoonki Leecdd8e962013-01-20 00:45:46 -08001930}
1931
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07001932/* Caller has to take the lock before calling this function */
Hoonki Lee27511902013-03-14 18:19:06 -07001933static void wlan_tdd_tdls_reset_tx_rx(tdlsCtx_t *pHddTdlsCtx)
1934{
1935 int i;
1936 struct list_head *head;
1937 hddTdlsPeer_t *tmp;
1938 struct list_head *pos, *q;
1939
Hoonki Lee27511902013-03-14 18:19:06 -07001940 for (i = 0; i < 256; i++) {
1941 head = &pHddTdlsCtx->peer_list[i];
1942 list_for_each_safe (pos, q, head) {
1943 tmp = list_entry(pos, hddTdlsPeer_t, node);
1944 tmp->tx_pkt = 0;
1945 tmp->rx_pkt = 0;
1946 }
1947 }
Hoonki Lee27511902013-03-14 18:19:06 -07001948
1949 return ;
1950}
1951
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07001952/* Caller has to take the lock before calling this function */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001953static tANI_S32 wlan_hdd_tdls_peer_reset_discovery_processed(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001954{
1955 int i;
1956 struct list_head *head;
1957 hddTdlsPeer_t *tmp;
1958 struct list_head *pos, *q;
1959
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001960 pHddTdlsCtx->discovery_peer_cnt = 0;
1961
1962 for (i = 0; i < 256; i++) {
1963 head = &pHddTdlsCtx->peer_list[i];
1964 list_for_each_safe (pos, q, head) {
1965 tmp = list_entry(pos, hddTdlsPeer_t, node);
1966 tmp->discovery_processed = 0;
1967 }
1968 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001969
1970 return 0;
1971}
1972
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001973static tANI_S32 wlan_hdd_get_tdls_discovery_peer_cnt(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001974{
1975 int i;
1976 struct list_head *head;
1977 struct list_head *pos, *q;
1978 int discovery_peer_cnt=0;
1979 hddTdlsPeer_t *tmp;
1980
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08001981 /*
1982 * This function expects the callers to acquire the Mutex.
1983 */
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001984
1985 for (i = 0; i < 256; i++) {
1986 head = &pHddTdlsCtx->peer_list[i];
1987 list_for_each_safe (pos, q, head) {
1988 tmp = list_entry(pos, hddTdlsPeer_t, node);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301989 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Chilam Ng01120412013-02-19 18:32:21 -08001990 "%s, %d, " MAC_ADDRESS_STR, __func__, i,
1991 MAC_ADDR_ARRAY(tmp->peerMac));
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001992 discovery_peer_cnt++;
1993 }
1994 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001995 return discovery_peer_cnt;
1996}
1997
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001998tANI_U16 wlan_hdd_tdlsConnectedPeers(hdd_adapter_t *pAdapter)
Lee Hoonkic1262f22013-01-24 21:59:00 -08001999{
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302000 hdd_context_t *pHddCtx = NULL;
2001
2002 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
2003 {
2004 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2005 FL("invalid pAdapter: %p"), pAdapter);
2006 return 0;
2007 }
2008 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002009
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302010 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302011 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2012 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002013 return 0;
c_hpothu7f63e882013-10-02 19:13:35 +05302014 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302015 EXIT();
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002016 return pHddCtx->connected_peer_count;
Lee Hoonkic1262f22013-01-24 21:59:00 -08002017}
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002018
Pradeep Reddy POTTETIe309c152015-02-06 13:21:07 +05302019hddTdlsPeer_t *wlan_hdd_tdls_get_connected_peer(hdd_adapter_t *pAdapter)
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302020{
2021 int i;
2022 struct list_head *head;
2023 struct list_head *pos;
2024 hddTdlsPeer_t *curr_peer = NULL;
2025 tdlsCtx_t *pHddTdlsCtx;
2026 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2027
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302028 ENTER();
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302029 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2030 {
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302031 return NULL;
2032 }
2033
2034 mutex_lock(&pHddCtx->tdls_lock);
2035 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2036 if (NULL == pHddTdlsCtx) {
2037 mutex_unlock(&pHddCtx->tdls_lock);
2038 return NULL;
2039 }
2040 for (i = 0; i < 256; i++) {
2041 head = &pHddTdlsCtx->peer_list[i];
2042
2043 list_for_each(pos, head) {
2044 curr_peer= list_entry (pos, hddTdlsPeer_t, node);
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05302045 if (curr_peer && (curr_peer->link_status == eTDLS_LINK_CONNECTED))
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302046 {
2047 mutex_unlock(&pHddCtx->tdls_lock);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302048 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05302049 "%s: " MAC_ADDRESS_STR " eTDLS_LINK_CONNECTED",
2050 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302051 return curr_peer;
2052 }
2053 }
2054 }
2055 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302056
2057 EXIT();
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302058 return NULL;
2059}
2060
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002061int wlan_hdd_tdls_get_all_peers(hdd_adapter_t *pAdapter, char *buf, int buflen)
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002062{
2063 int i;
2064 int len, init_len;
Hoonki Lee387663d2013-02-05 18:08:43 -08002065 struct list_head *head;
2066 struct list_head *pos;
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002067 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002068 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302069 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2070
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302071 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302072 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2073 {
c_hpothu7f63e882013-10-02 19:13:35 +05302074 return 0;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302075 }
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002076
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002077 init_len = buflen;
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002078 len = scnprintf(buf, buflen, "\n%-18s%-3s%-4s%-3s%-5s\n",
2079 "MAC", "Id", "cap", "up", "RSSI");
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002080 buf += len;
2081 buflen -= len;
2082 /* 1234567890123456789012345678901234567 */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002083 len = scnprintf(buf, buflen, "---------------------------------\n");
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002084 buf += len;
2085 buflen -= len;
2086
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302087 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002088 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002089 if (NULL == pHddTdlsCtx) {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302090 mutex_unlock(&pHddCtx->tdls_lock);
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002091 len = scnprintf(buf, buflen, "TDLS not enabled\n");
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002092 return len;
2093 }
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002094 for (i = 0; i < 256; i++) {
Hoonki Lee387663d2013-02-05 18:08:43 -08002095 head = &pHddTdlsCtx->peer_list[i];
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002096
Hoonki Lee387663d2013-02-05 18:08:43 -08002097 list_for_each(pos, head) {
2098 curr_peer= list_entry (pos, hddTdlsPeer_t, node);
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002099
Hoonki Lee387663d2013-02-05 18:08:43 -08002100 if (buflen < 32+1)
2101 break;
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002102 len = scnprintf(buf, buflen,
Chilam Ng01120412013-02-19 18:32:21 -08002103 MAC_ADDRESS_STR"%3d%4s%3s%5d\n",
2104 MAC_ADDR_ARRAY(curr_peer->peerMac),
Hoonki Lee387663d2013-02-05 18:08:43 -08002105 curr_peer->staId,
2106 (curr_peer->tdls_support == eTDLS_CAP_SUPPORTED) ? "Y":"N",
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002107 TDLS_IS_CONNECTED(curr_peer) ? "Y":"N",
Hoonki Lee387663d2013-02-05 18:08:43 -08002108 curr_peer->rssi);
2109 buf += len;
2110 buflen -= len;
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002111 }
2112 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302113 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302114
2115 EXIT();
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002116 return init_len-buflen;
2117}
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002118
2119void wlan_hdd_tdls_connection_callback(hdd_adapter_t *pAdapter)
2120{
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302121 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302122 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala9d76a9b2013-02-28 15:38:37 -08002123
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302124 if ((NULL == pHddCtx))
c_hpothu7f63e882013-10-02 19:13:35 +05302125 {
Agarwal Ashishbf98caf2014-03-25 13:29:11 +05302126 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
2127 FL("pHddCtx or pHddTdlsCtx points to NULL"));
c_hpothu7f63e882013-10-02 19:13:35 +05302128 return;
2129 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302130
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302131 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07002132
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302133 if (0 != wlan_hdd_sta_tdls_init(pAdapter))
2134 {
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302135 mutex_unlock(&pHddCtx->tdls_lock);
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302136 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wlan_hdd_sta_tdls_init failed",__func__);
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302137 return;
2138 }
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302139
2140 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2141 if ((NULL == pHddTdlsCtx))
2142 {
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302143 mutex_unlock(&pHddCtx->tdls_lock);
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302144 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
2145 FL("pHddCtx or pHddTdlsCtx points to NULL device mode = %d"), pAdapter->device_mode);
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302146 return;
2147 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302148 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002149 "%s, update %d discover %d", __func__,
2150 pHddTdlsCtx->threshold_config.tx_period_t,
2151 pHddTdlsCtx->threshold_config.discovery_period_t);
2152
Gopichand Nakkala9d76a9b2013-02-28 15:38:37 -08002153 if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode)
2154 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002155 wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002156 pHddTdlsCtx->discovery_sent_cnt = 0;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002157 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002158
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002159#ifdef FEATURE_WLAN_TDLS_INTERNAL
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002160 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2161 &pHddTdlsCtx->peerDiscoverTimer,
2162 pHddTdlsCtx->threshold_config.discovery_period_t);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002163#endif
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002164 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2165 &pHddTdlsCtx->peerUpdateTimer,
2166 pHddTdlsCtx->threshold_config.tx_period_t);
Gopichand Nakkala9d76a9b2013-02-28 15:38:37 -08002167 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302168 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002169
2170}
2171
2172void wlan_hdd_tdls_disconnection_callback(hdd_adapter_t *pAdapter)
2173{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002174 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302175 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2176
Deepthi Gowribfd17132014-11-14 17:59:04 +05302177 if (NULL == pHddCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302178 {
2179 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Deepthi Gowribfd17132014-11-14 17:59:04 +05302180 FL(" pHddCtx points to NULL"));
c_hpothu7f63e882013-10-02 19:13:35 +05302181 return;
2182 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002183
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302184 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"%s", __func__);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002185
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002186 if (NULL == pHddTdlsCtx)
2187 {
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302188 mutex_unlock(&pHddCtx->tdls_lock);
c_hpothu7f63e882013-10-02 19:13:35 +05302189 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2190 FL("pHddTdlsCtx is NULL"));
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002191 return;
2192 }
Masti, Narayanraddide96b992015-01-08 13:00:58 +05302193
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +05302194 mutex_lock(&pHddCtx->tdls_lock);
Masti, Narayanraddide96b992015-01-08 13:00:58 +05302195
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002196 pHddTdlsCtx->discovery_sent_cnt = 0;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002197 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002198
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +05302199 wlan_hdd_tdls_exit(pAdapter, TRUE);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002200
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302201 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002202}
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002203
2204void wlan_hdd_tdls_mgmt_completion_callback(hdd_adapter_t *pAdapter, tANI_U32 statusCode)
2205{
2206 pAdapter->mgmtTxCompletionStatus = statusCode;
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302207 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2208 "%s: Mgmt TX Completion %d",__func__, statusCode);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002209 complete(&pAdapter->tdls_mgmt_comp);
2210}
2211
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002212void wlan_hdd_tdls_increment_peer_count(hdd_adapter_t *pAdapter)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002213{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002214 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002215
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302216 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302217 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2218 {
c_hpothu7f63e882013-10-02 19:13:35 +05302219 return;
2220 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002221
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302222 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302223
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002224 pHddCtx->connected_peer_count++;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002225 wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002226
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302227 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: %d",
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002228 __func__, pHddCtx->connected_peer_count);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302229
2230 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302231
2232 EXIT();
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002233}
2234
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002235void wlan_hdd_tdls_decrement_peer_count(hdd_adapter_t *pAdapter)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002236{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002237 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002238
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302239 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302240 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2241 {
c_hpothu7f63e882013-10-02 19:13:35 +05302242 return;
2243 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002244
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302245 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302246
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002247 if (pHddCtx->connected_peer_count)
2248 pHddCtx->connected_peer_count--;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002249 wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002250
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302251 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: %d",
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002252 __func__, pHddCtx->connected_peer_count);
2253
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302254 mutex_unlock(&pHddCtx->tdls_lock);
2255
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302256 EXIT();
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002257}
2258
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002259void wlan_hdd_tdls_check_bmps(hdd_adapter_t *pAdapter)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002260{
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302261
2262 tdlsCtx_t *pHddTdlsCtx = NULL;
2263 hdd_context_t *pHddCtx = NULL;
Hoonki Lee14621352013-04-16 17:51:19 -07002264 hddTdlsPeer_t *curr_peer;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002265
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302266 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
2267 {
2268 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2269 FL("invalid pAdapter: %p"), pAdapter);
2270 return;
2271 }
2272
2273 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2274 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2275
c_hpothu7f63e882013-10-02 19:13:35 +05302276 if ((NULL == pHddCtx) || (NULL == pHddTdlsCtx))
2277 {
Sushant Kaushik125ae692014-11-25 17:38:48 +05302278 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
c_hpothu7f63e882013-10-02 19:13:35 +05302279 FL(" pHddCtx or pHddTdlsCtx points to NULL"));
2280 return;
2281 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002282
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302283 curr_peer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, TRUE);
Hoonki Lee14621352013-04-16 17:51:19 -07002284 if (NULL != curr_peer)
2285 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302286 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee14621352013-04-16 17:51:19 -07002287 "%s: tdls in progress. Dont check for BMPS " MAC_ADDRESS_STR,
2288 __func__, MAC_ADDR_ARRAY (curr_peer->peerMac));
2289 return;
2290 }
2291
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002292 if ((TDLS_CTX_MAGIC != pHddCtx->tdls_scan_ctxt.magic) &&
2293 (0 == pHddCtx->connected_peer_count) &&
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002294 (0 == pHddTdlsCtx->discovery_sent_cnt))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002295 {
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002296 if (FALSE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
2297 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302298 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002299 "%s: No TDLS peer connected/discovery sent. Enable BMPS",
2300 __func__);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002301 hdd_enable_bmps_imps(pHddCtx);
2302 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002303 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002304 else
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002305 {
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002306 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
2307 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302308 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002309 "%s: TDLS peer connected. Disable BMPS", __func__);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002310 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
2311 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002312 }
2313 return;
2314}
2315
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002316u8 wlan_hdd_tdls_is_peer_progress(hdd_adapter_t *pAdapter, u8 *mac)
2317{
2318 hddTdlsPeer_t *curr_peer;
2319
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302320 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002321 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05302322 {
2323 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2324 "%s: curr_peer is NULL", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002325 return 0;
c_hpothu7f63e882013-10-02 19:13:35 +05302326 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002327
2328 return (eTDLS_LINK_CONNECTING == curr_peer->link_status);
2329}
2330
Hoonki Leefb8df672013-04-10 18:20:34 -07002331/* return pointer to hddTdlsPeer_t if TDLS is ongoing. Otherwise return NULL.
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002332 * mac - if NULL check for all the peer list, otherwise, skip this mac when skip_self is TRUE
2333 * skip_self - if TRUE, skip this mac. otherwise, check all the peer list. if
2334 mac is NULL, this argument is ignored, and check for all the peer list.
2335 */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302336static hddTdlsPeer_t *wlan_hdd_tdls_find_progress_peer(hdd_adapter_t *pAdapter, u8 *mac, u8 skip_self)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002337{
2338 int i;
2339 struct list_head *head;
2340 hddTdlsPeer_t *curr_peer;
2341 struct list_head *pos;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302342 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302343
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302344 if (NULL == pHddTdlsCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302345 {
2346 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2347 FL("pHddTdlsCtx is NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302348 return NULL;
c_hpothu7f63e882013-10-02 19:13:35 +05302349 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302350
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002351 for (i = 0; i < 256; i++) {
2352 head = &pHddTdlsCtx->peer_list[i];
2353 list_for_each(pos, head) {
2354 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
2355 if (skip_self && mac && !memcmp(mac, curr_peer->peerMac, 6)) {
2356 continue;
2357 }
2358 else
2359 {
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08002360 if (eTDLS_LINK_CONNECTING == curr_peer->link_status)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002361 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302362 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002363 "%s:" MAC_ADDRESS_STR " eTDLS_LINK_CONNECTING",
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002364 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
Hoonki Leefb8df672013-04-10 18:20:34 -07002365 return curr_peer;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002366 }
2367 }
2368 }
2369 }
Hoonki Leefb8df672013-04-10 18:20:34 -07002370 return NULL;
2371}
2372
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302373hddTdlsPeer_t *wlan_hdd_tdls_is_progress(hdd_context_t *pHddCtx, u8 *mac,
2374 u8 skip_self, tANI_BOOLEAN mutexLock)
Hoonki Leefb8df672013-04-10 18:20:34 -07002375{
2376 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2377 hdd_adapter_t *pAdapter = NULL;
2378 tdlsCtx_t *pHddTdlsCtx = NULL;
2379 hddTdlsPeer_t *curr_peer= NULL;
2380 VOS_STATUS status = 0;
2381
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302382 if (mutexLock)
2383 {
2384 mutex_lock(&pHddCtx->tdls_lock);
2385 }
Hoonki Leefb8df672013-04-10 18:20:34 -07002386 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2387 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2388 {
2389 pAdapter = pAdapterNode->pAdapter;
2390
2391 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2392 if (NULL != pHddTdlsCtx)
2393 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302394 curr_peer = wlan_hdd_tdls_find_progress_peer(pAdapter, mac, skip_self);
Hoonki Leefb8df672013-04-10 18:20:34 -07002395 if (curr_peer)
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302396 {
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302397 if (mutexLock)
2398 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leefb8df672013-04-10 18:20:34 -07002399 return curr_peer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302400 }
Hoonki Leefb8df672013-04-10 18:20:34 -07002401 }
2402 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2403 pAdapterNode = pNext;
2404 }
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302405 if (mutexLock)
2406 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leefb8df672013-04-10 18:20:34 -07002407 return NULL;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002408}
Hoonki Lee27511902013-03-14 18:19:06 -07002409
2410static void wlan_hdd_tdls_implicit_disable(tdlsCtx_t *pHddTdlsCtx)
2411{
Hoonki Lee27511902013-03-14 18:19:06 -07002412 wlan_hdd_tdls_timers_stop(pHddTdlsCtx);
Hoonki Lee27511902013-03-14 18:19:06 -07002413}
2414
2415static void wlan_hdd_tdls_implicit_enable(tdlsCtx_t *pHddTdlsCtx)
2416{
2417 wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002418 pHddTdlsCtx->discovery_sent_cnt = 0;
Hoonki Lee27511902013-03-14 18:19:06 -07002419 wlan_tdd_tdls_reset_tx_rx(pHddTdlsCtx);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002420 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002421
Hoonki Lee27511902013-03-14 18:19:06 -07002422
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002423#ifdef FEATURE_WLAN_TDLS_INTERNAL
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002424 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2425 &pHddTdlsCtx->peerDiscoverTimer,
2426 pHddTdlsCtx->threshold_config.discovery_period_t);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002427#endif
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002428 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2429 &pHddTdlsCtx->peerUpdateTimer,
2430 pHddTdlsCtx->threshold_config.tx_period_t);
Hoonki Lee27511902013-03-14 18:19:06 -07002431}
2432
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002433void wlan_hdd_tdls_set_mode(hdd_context_t *pHddCtx,
2434 eTDLSSupportMode tdls_mode,
2435 v_BOOL_t bUpdateLast)
Hoonki Lee27511902013-03-14 18:19:06 -07002436{
2437 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2438 VOS_STATUS status;
2439 hdd_adapter_t *pAdapter;
2440 tdlsCtx_t *pHddTdlsCtx;
2441
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302442 ENTER();
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302443 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2444 "%s mode %d", __func__, (int)tdls_mode);
c_hpothu7f63e882013-10-02 19:13:35 +05302445
2446 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2447 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302448 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302449 }
Hoonki Lee27511902013-03-14 18:19:06 -07002450
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302451 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07002452
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002453 if (pHddCtx->tdls_mode == tdls_mode)
2454 {
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302455 mutex_unlock(&pHddCtx->tdls_lock);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302456 hddLog(VOS_TRACE_LEVEL_INFO, "%s already in mode %d", __func__,
2457 (int)tdls_mode);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002458 return;
2459 }
2460
Hoonki Lee27511902013-03-14 18:19:06 -07002461 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2462
2463 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2464 {
2465 pAdapter = pAdapterNode->pAdapter;
Hoonki Leea6d49be2013-04-05 09:43:25 -07002466 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2467 if (NULL != pHddTdlsCtx)
Hoonki Lee27511902013-03-14 18:19:06 -07002468 {
Hoonki Leea6d49be2013-04-05 09:43:25 -07002469 if(eTDLS_SUPPORT_ENABLED == tdls_mode)
2470 wlan_hdd_tdls_implicit_enable(pHddTdlsCtx);
2471 else if((eTDLS_SUPPORT_DISABLED == tdls_mode) ||
2472 (eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == tdls_mode))
2473 wlan_hdd_tdls_implicit_disable(pHddTdlsCtx);
Hoonki Lee27511902013-03-14 18:19:06 -07002474 }
2475 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2476 pAdapterNode = pNext;
2477 }
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002478 if(bUpdateLast)
2479 {
2480 pHddCtx->tdls_mode_last = tdls_mode;
2481 }
2482 else
2483 {
2484 pHddCtx->tdls_mode_last = pHddCtx->tdls_mode;
2485 }
Hoonki Lee27511902013-03-14 18:19:06 -07002486 pHddCtx->tdls_mode = tdls_mode;
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002487
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302488 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302489
2490 EXIT();
Hoonki Lee27511902013-03-14 18:19:06 -07002491}
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002492
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302493static
2494void wlan_hdd_tdls_implicit_send_discovery_request(tdlsCtx_t * pHddTdlsCtx)
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002495{
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302496 hdd_context_t *pHddCtx = NULL;
2497 hddTdlsPeer_t *curr_peer = NULL, *temp_peer = NULL;
Hoonki Leed37cbb32013-04-20 00:31:14 -07002498
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302499 ENTER();
Hoonki Leed37cbb32013-04-20 00:31:14 -07002500 if (NULL == pHddTdlsCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302501 {
2502 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2503 FL("pHddTdlsCtx is NULL"));
Hoonki Leed37cbb32013-04-20 00:31:14 -07002504 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302505 }
Hoonki Leed37cbb32013-04-20 00:31:14 -07002506
Hoonki Leed37cbb32013-04-20 00:31:14 -07002507 pHddCtx = WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter);
Hoonki Leefb8df672013-04-10 18:20:34 -07002508
c_hpothu7f63e882013-10-02 19:13:35 +05302509 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2510 {
Hoonki Leefb8df672013-04-10 18:20:34 -07002511 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302512 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002513
Hoonki Leed37cbb32013-04-20 00:31:14 -07002514 curr_peer = pHddTdlsCtx->curr_candidate;
Hoonki Leed37cbb32013-04-20 00:31:14 -07002515 if (NULL == curr_peer)
c_hpothu7f63e882013-10-02 19:13:35 +05302516 {
2517 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2518 FL("curr_peer is NULL"));
2519
Hoonki Leed37cbb32013-04-20 00:31:14 -07002520 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302521 }
Hoonki Leed37cbb32013-04-20 00:31:14 -07002522
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002523 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter)))
2524 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302525 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2526 "%s: Disable BMPS", __func__);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002527 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
2528 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002529
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302530 /* This function is called in mutex_lock */
2531 temp_peer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, FALSE);
Hoonki Leefb8df672013-04-10 18:20:34 -07002532 if (NULL != temp_peer)
2533 {
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302534 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2535 "%s: " MAC_ADDRESS_STR " ongoing. pre_setup ignored",
2536 __func__, MAC_ADDR_ARRAY(temp_peer->peerMac));
Hoonki Leed37cbb32013-04-20 00:31:14 -07002537 goto done;
Hoonki Leefb8df672013-04-10 18:20:34 -07002538 }
2539
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002540 if (eTDLS_CAP_UNKNOWN != curr_peer->tdls_support)
Atul Mittal115287b2014-07-08 13:26:33 +05302541 wlan_hdd_tdls_set_peer_link_status(curr_peer,
2542 eTDLS_LINK_DISCOVERING,
2543 eTDLS_LINK_SUCCESS);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002544
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302545 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2546 "%s: Implicit TDLS, Send Discovery request event", __func__);
Hoonki Leed37cbb32013-04-20 00:31:14 -07002547
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302548 cfg80211_tdls_oper_request(pHddTdlsCtx->pAdapter->dev,
2549 curr_peer->peerMac,
2550 NL80211_TDLS_DISCOVERY_REQ,
2551 FALSE,
2552 GFP_KERNEL);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002553 pHddTdlsCtx->discovery_sent_cnt++;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302554
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002555 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302556
Pradeep Reddy POTTETI219ced32014-11-14 16:33:57 +05302557 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2558 &pHddTdlsCtx->peerDiscoveryTimeoutTimer,
2559 pHddTdlsCtx->threshold_config.tx_period_t - TDLS_DISCOVERY_TIMEOUT_BEFORE_UPDATE);
2560
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302561 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2562 "%s: discovery count %u timeout %u msec",
2563 __func__, pHddTdlsCtx->discovery_sent_cnt,
2564 pHddTdlsCtx->threshold_config.tx_period_t - TDLS_DISCOVERY_TIMEOUT_BEFORE_UPDATE);
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002565
Hoonki Leed37cbb32013-04-20 00:31:14 -07002566done:
2567 pHddTdlsCtx->curr_candidate = NULL;
2568 pHddTdlsCtx->magic = 0;
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302569 EXIT();
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002570 return;
2571}
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002572
2573tANI_U32 wlan_hdd_tdls_discovery_sent_cnt(hdd_context_t *pHddCtx)
2574{
2575 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2576 hdd_adapter_t *pAdapter = NULL;
2577 tdlsCtx_t *pHddTdlsCtx = NULL;
2578 VOS_STATUS status = 0;
2579 tANI_U32 count = 0;
2580
2581 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2582 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2583 {
2584 pAdapter = pAdapterNode->pAdapter;
2585
Hoonki Leea6d49be2013-04-05 09:43:25 -07002586 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2587 if (NULL != pHddTdlsCtx)
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002588 {
Hoonki Leea6d49be2013-04-05 09:43:25 -07002589 count = count + pHddTdlsCtx->discovery_sent_cnt;
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002590 }
2591 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2592 pAdapterNode = pNext;
2593 }
2594 return count;
2595}
2596
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002597void wlan_hdd_tdls_check_power_save_prohibited(hdd_adapter_t *pAdapter)
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002598{
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302599 tdlsCtx_t *pHddTdlsCtx = NULL;
2600 hdd_context_t *pHddCtx = NULL;
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05302601
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302602
2603 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
2604 {
2605 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2606 FL("invalid pAdapter: %p"), pAdapter);
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05302607 return;
2608 }
2609
2610 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2611 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002612
2613 if ((NULL == pHddTdlsCtx) || (NULL == pHddCtx))
c_hpothu7f63e882013-10-02 19:13:35 +05302614 {
2615 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2616 FL(" pHddCtx or pHddTdlsCtx points to NULL"));
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002617 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302618 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002619
2620 if ((0 == pHddCtx->connected_peer_count) &&
2621 (0 == wlan_hdd_tdls_discovery_sent_cnt(pHddCtx)))
2622 {
2623 sme_SetTdlsPowerSaveProhibited(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter), 0);
2624 return;
2625 }
2626 sme_SetTdlsPowerSaveProhibited(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter), 1);
2627 return;
2628}
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002629
2630void wlan_hdd_tdls_free_scan_request (tdls_scan_context_t *tdls_scan_ctx)
2631{
2632 if (NULL == tdls_scan_ctx)
c_hpothu7f63e882013-10-02 19:13:35 +05302633 {
2634 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2635 FL("tdls_scan_ctx is NULL"));
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002636 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302637 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002638
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002639 tdls_scan_ctx->attempt = 0;
Hoonki Leefb8df672013-04-10 18:20:34 -07002640 tdls_scan_ctx->reject = 0;
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002641 tdls_scan_ctx->magic = 0;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002642 tdls_scan_ctx->scan_request = NULL;
2643 return;
2644}
2645
2646int wlan_hdd_tdls_copy_scan_context(hdd_context_t *pHddCtx,
2647 struct wiphy *wiphy,
2648#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2649 struct net_device *dev,
2650#endif
2651 struct cfg80211_scan_request *request)
2652{
2653 tdls_scan_context_t *scan_ctx;
2654
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302655 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302656 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2657 {
c_hpothu7f63e882013-10-02 19:13:35 +05302658 return 0;
2659 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002660
2661 scan_ctx = &pHddCtx->tdls_scan_ctxt;
2662
2663 scan_ctx->wiphy = wiphy;
2664#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2665 scan_ctx->dev = dev;
2666#endif
2667
2668 scan_ctx->scan_request = request;
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302669
2670 EXIT();
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002671 return 0;
2672}
2673
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002674static void wlan_hdd_tdls_scan_init_work(hdd_context_t *pHddCtx,
2675 struct wiphy *wiphy,
2676#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2677 struct net_device *dev,
2678#endif
2679 struct cfg80211_scan_request *request,
2680 unsigned long delay)
2681{
2682 if (TDLS_CTX_MAGIC != pHddCtx->tdls_scan_ctxt.magic)
2683 {
2684#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2685 wlan_hdd_tdls_copy_scan_context(pHddCtx, wiphy, dev, request);
2686#else
2687 wlan_hdd_tdls_copy_scan_context(pHddCtx, wiphy, request);
2688#endif
2689 pHddCtx->tdls_scan_ctxt.attempt = 0;
2690 pHddCtx->tdls_scan_ctxt.magic = TDLS_CTX_MAGIC;
2691 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002692 schedule_delayed_work(&pHddCtx->tdls_scan_ctxt.tdls_scan_work, delay);
2693}
2694
2695/* return negative = caller should stop and return error code immediately
2696 return 0 = caller should stop and return success immediately
2697 return 1 = caller can continue to scan
2698 */
2699int wlan_hdd_tdls_scan_callback (hdd_adapter_t *pAdapter,
2700 struct wiphy *wiphy,
2701#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2702 struct net_device *dev,
2703#endif
2704 struct cfg80211_scan_request *request)
2705{
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002706 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2707 u16 connectedTdlsPeers;
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302708 hddTdlsPeer_t *curr_peer, *connected_peer;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002709 unsigned long delay;
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302710 hdd_config_t *cfg_param = pHddCtx->cfg_ini;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002711
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302712 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302713 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2714 {
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002715 return 0;
c_hpothu7f63e882013-10-02 19:13:35 +05302716 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002717
2718 /* if tdls is not enabled, then continue scan */
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +05302719 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
2720 (pHddCtx->is_tdls_btc_enabled == FALSE))
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002721 return 1;
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302722 curr_peer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, TRUE);
Hoonki Leefb8df672013-04-10 18:20:34 -07002723 if (NULL != curr_peer)
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002724 {
Hoonki Leefb8df672013-04-10 18:20:34 -07002725 if (pHddCtx->tdls_scan_ctxt.reject++ >= TDLS_MAX_SCAN_REJECT)
2726 {
2727 pHddCtx->tdls_scan_ctxt.reject = 0;
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302728 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Leefb8df672013-04-10 18:20:34 -07002729 "%s: " MAC_ADDRESS_STR ". scan rejected %d. force it to idle",
2730 __func__, MAC_ADDR_ARRAY (curr_peer->peerMac), pHddCtx->tdls_scan_ctxt.reject);
2731
Atul Mittal115287b2014-07-08 13:26:33 +05302732 wlan_hdd_tdls_set_peer_link_status (curr_peer,
2733 eTDLS_LINK_IDLE,
2734 eTDLS_LINK_UNSPECIFIED);
Hoonki Leefb8df672013-04-10 18:20:34 -07002735 return 1;
2736 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302737 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Leefb8df672013-04-10 18:20:34 -07002738 "%s: tdls in progress. scan rejected %d",
2739 __func__, pHddCtx->tdls_scan_ctxt.reject);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002740 return -EBUSY;
2741 }
2742
2743 /* tdls teardown is ongoing */
2744 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
2745 {
2746 connectedTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
2747 if (connectedTdlsPeers && (pHddCtx->tdls_scan_ctxt.attempt < TDLS_MAX_SCAN_SCHEDULE))
2748 {
2749 delay = (unsigned long)(TDLS_DELAY_SCAN_PER_CONNECTION*connectedTdlsPeers);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302750 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002751 "%s: tdls disabled, but still connected_peers %d attempt %d. schedule scan %lu msec",
2752 __func__, connectedTdlsPeers, pHddCtx->tdls_scan_ctxt.attempt, delay);
2753
2754 wlan_hdd_tdls_scan_init_work (pHddCtx, wiphy,
2755#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2756 dev,
2757#endif
2758 request,
2759 msecs_to_jiffies(delay));
2760 /* scan should not continue */
2761 return 0;
2762 }
2763 /* no connected peer or max retry reached, scan continue */
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302764 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002765 "%s: tdls disabled. connected_peers %d attempt %d. scan allowed",
2766 __func__, connectedTdlsPeers, pHddCtx->tdls_scan_ctxt.attempt);
2767 return 1;
2768 }
Agarwal Ashishef54a182014-12-16 15:07:31 +05302769
2770 /* if fEnableTDLSScan flag is 1 ; driverwill allow scan even if
2771 * peer station is not buffer STA capable
2772 *
2773 * RX: If there is any RX activity, device will lose RX packets,
2774 * as peer will not be aware that device is off channel.
2775 * TX: TX is stopped whenever device initiate scan.
2776 */
2777 if (pHddCtx->cfg_ini->fEnableTDLSScan == 1)
2778 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302779 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Agarwal Ashishef54a182014-12-16 15:07:31 +05302780 FL("Allow SCAN in all TDLS cases"));
2781 return 1;
2782 }
2783
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002784 /* while tdls is up, first time scan */
2785 else if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode ||
2786 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == pHddCtx->tdls_mode)
2787 {
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002788 connectedTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302789
2790 /* check the TDLS link and Scan coexistance Capability */
2791 if ( (TRUE == pHddCtx->cfg_ini->fEnableTDLSScanCoexSupport) &&
2792 (TRUE == sme_IsFeatureSupportedByFW(TDLS_SCAN_COEXISTENCE)) &&
2793 (connectedTdlsPeers == 1) )
2794 {
2795 /* get connected peer information */
Pradeep Reddy POTTETIe309c152015-02-06 13:21:07 +05302796 connected_peer = wlan_hdd_tdls_get_connected_peer(pAdapter);
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302797 if (NULL == connected_peer) {
2798 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2799 "%s: Invalid connected_peer, Continue Scanning", __func__);
2800 /* scan should continue */
2801 return 1;
2802 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302803 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302804 ("%s: TDLS Scan Co-exist supported connectedTdlsPeers =%d buffersta =%d"),
2805 __func__,connectedTdlsPeers,connected_peer->isBufSta);
2806
2807 if (connected_peer->isBufSta)
2808 {
2809 pHddCtx->isTdlsScanCoexistence = TRUE;
2810 if ((cfg_param->dynSplitscan) && (!pHddCtx->issplitscan_enabled))
2811 {
2812 pHddCtx->issplitscan_enabled = TRUE;
2813 sme_enable_disable_split_scan(
2814 WLAN_HDD_GET_HAL_CTX(pAdapter),
2815 cfg_param->nNumStaChanCombinedConc,
2816 cfg_param->nNumP2PChanCombinedConc);
2817 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302818 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302819 ("%s:%d TDLS Scan Co-exist supported splitscan_enabled =%d "),
2820 __func__, __LINE__, pHddCtx->issplitscan_enabled);
2821 return 1;
2822 }
2823
2824 }
2825 else
2826 {
2827 /* Throughput Monitor shall disable the split scan when
2828 * TDLS scan coexistance is disabled.At this point of time
2829 * since TDLS scan coexistance is not meeting the criteria
2830 * to be operational, explicitly make it false to enable
2831 * throughput monitor takes the control of split scan.
2832 */
2833 pHddCtx->isTdlsScanCoexistence = FALSE;
2834 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302835 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302836 ("%s: TDLS Scan Co-exist not supported connectedTdlsPeers =%d"
2837 " TDLSScanCoexSupport param =%d TDLS_SCAN_COEXISTENCE =%d"),
2838 __func__, connectedTdlsPeers,
2839 pHddCtx->cfg_ini->fEnableTDLSScanCoexSupport,
2840 sme_IsFeatureSupportedByFW(TDLS_SCAN_COEXISTENCE));
2841
Atul Mittal5803b342014-09-04 15:31:19 +05302842 /* disable implicit trigger logic & tdls operatoin */
2843 wlan_hdd_tdls_set_mode(pHddCtx, eTDLS_SUPPORT_DISABLED, FALSE);
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302844 /* fall back to the implementation of teardown the peers on the scan
2845 * when the number of connected peers are more than one. TDLS Scan
2846 * coexistance feature is exercised only when a single peer is
2847 * connected and the DUT shall not advertize the Buffer Sta capability,
2848 * so that the peer shall not go to the TDLS power save
2849 */
2850
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002851 if (connectedTdlsPeers)
2852 {
2853 tANI_U8 staIdx;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002854 hddTdlsPeer_t *curr_peer;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002855
2856 for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
2857 {
2858 if (pHddCtx->tdlsConnInfo[staIdx].staId)
2859 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302860 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2861 ("%s: indicate TDLS teardown (staId %d)"), __func__, pHddCtx->tdlsConnInfo[staIdx].staId) ;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002862
2863#ifdef CONFIG_TDLS_IMPLICIT
Hoonki Leea6d49be2013-04-05 09:43:25 -07002864 curr_peer = wlan_hdd_tdls_find_all_peer(pHddCtx, pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes);
2865 if(curr_peer)
2866 wlan_hdd_tdls_indicate_teardown(curr_peer->pHddTdlsCtx->pAdapter, curr_peer, eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002867#endif
2868 }
2869 }
2870 /* schedule scan */
2871 delay = (unsigned long)(TDLS_DELAY_SCAN_PER_CONNECTION*connectedTdlsPeers);
2872
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302873 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002874 "%s: tdls enabled (mode %d), connected_peers %d. schedule scan %lu msec",
2875 __func__, pHddCtx->tdls_mode, wlan_hdd_tdlsConnectedPeers(pAdapter),
2876 delay);
2877
2878 wlan_hdd_tdls_scan_init_work (pHddCtx, wiphy,
2879#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2880 dev,
2881#endif
2882 request,
2883 msecs_to_jiffies(delay));
2884 /* scan should not continue */
2885 return 0;
2886 }
2887 /* no connected peer, scan continue */
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302888 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002889 "%s: tdls_mode %d, and no tdls connection. scan allowed",
2890 __func__, pHddCtx->tdls_mode);
2891 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302892 EXIT();
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002893 return 1;
2894}
2895
2896void wlan_hdd_tdls_scan_done_callback(hdd_adapter_t *pAdapter)
2897{
2898 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002899
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302900 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302901 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2902 {
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002903 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302904 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002905
Pradeep Reddy POTTETIc7822df2015-02-19 20:15:41 +05302906 /* if tdls is not enabled or BtCoex is on then don't revert tdls mode */
2907 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
Chandrasekaran, Manishekar0de84dc2015-03-10 15:12:34 +05302908 (pHddCtx->is_tdls_btc_enabled == FALSE)) {
2909 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to revert: Mode=%d, BTC enabled=%d"),
2910 pHddCtx->tdls_mode, pHddCtx->is_tdls_btc_enabled);
Pradeep Reddy POTTETIc7822df2015-02-19 20:15:41 +05302911 return;
Chandrasekaran, Manishekar0de84dc2015-03-10 15:12:34 +05302912 }
Sunil Dutt41de4e22013-11-14 18:09:02 +05302913
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002914 /* free allocated memory at scan time */
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002915 wlan_hdd_tdls_free_scan_request (&pHddCtx->tdls_scan_ctxt);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002916
2917 /* if tdls was enabled before scan, re-enable tdls mode */
2918 if(eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode_last ||
2919 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == pHddCtx->tdls_mode_last)
2920 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302921 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002922 ("%s: revert tdls mode %d"), __func__, pHddCtx->tdls_mode_last);
2923
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002924 wlan_hdd_tdls_set_mode(pHddCtx, pHddCtx->tdls_mode_last, FALSE);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002925 }
2926 wlan_hdd_tdls_check_bmps(pAdapter);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302927
2928 EXIT();
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002929}
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002930
2931void wlan_hdd_tdls_timer_restart(hdd_adapter_t *pAdapter,
2932 vos_timer_t *timer,
2933 v_U32_t expirationTime)
2934{
2935 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
2936
2937 if (NULL == pHddStaCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302938 {
2939 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2940 FL("pHddStaCtx is NULL"));
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002941 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302942 }
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002943
2944 /* Check whether driver load unload is in progress */
2945 if(vos_is_load_unload_in_progress( VOS_MODULE_ID_VOSS, NULL))
2946 {
2947 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
2948 "%s: Driver load/unload is in progress.", __func__);
2949 return;
2950 }
2951
2952 if (hdd_connIsConnected(pHddStaCtx))
2953 {
2954 vos_timer_stop(timer);
2955 vos_timer_start(timer, expirationTime);
2956 }
2957}
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002958void wlan_hdd_tdls_indicate_teardown(hdd_adapter_t *pAdapter,
2959 hddTdlsPeer_t *curr_peer,
2960 tANI_U16 reason)
2961{
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05302962 hdd_context_t *pHddCtx;
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302963
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302964 if ((NULL == pAdapter || WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic) ||
2965 (NULL == curr_peer))
c_hpothu7f63e882013-10-02 19:13:35 +05302966 {
2967 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2968 FL("parameters passed are invalid"));
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002969 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302970 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002971
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05302972 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2973
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002974 if (eTDLS_LINK_CONNECTED != curr_peer->link_status)
2975 return;
2976
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302977 /* Throughput Monitor shall disable the split scan when
2978 * TDLS scan coexistance is disabled.At this point of time
2979 * since TDLS scan coexistance is not meeting the criteria
2980 * to be operational, explicitly make it false to enable
2981 * throughput monitor takes the control of split scan.
2982 */
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05302983 if (pHddCtx && (pHddCtx->isTdlsScanCoexistence == TRUE))
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302984 {
2985 pHddCtx->isTdlsScanCoexistence = FALSE;
2986 }
2987
Atul Mittal115287b2014-07-08 13:26:33 +05302988 wlan_hdd_tdls_set_peer_link_status(curr_peer,
2989 eTDLS_LINK_TEARING,
Atul Mittal271a7652014-09-12 13:18:22 +05302990 eTDLS_LINK_UNSPECIFIED);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002991 cfg80211_tdls_oper_request(pAdapter->dev,
2992 curr_peer->peerMac,
2993 NL80211_TDLS_TEARDOWN,
2994 reason,
2995 GFP_KERNEL);
2996}
Atul Mittal115287b2014-07-08 13:26:33 +05302997
2998
2999/*EXT TDLS*/
3000int wlan_hdd_set_callback(hddTdlsPeer_t *curr_peer,
3001 cfg80211_exttdls_callback callback)
3002{
3003
3004 hdd_context_t *pHddCtx;
3005 hdd_adapter_t *pAdapter;
3006
3007 if (!curr_peer) return -1;
3008
3009 pAdapter = curr_peer->pHddTdlsCtx->pAdapter;
3010 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3011 if ((NULL == pHddCtx)) return -1;
3012
3013 mutex_lock(&pHddCtx->tdls_lock);
3014
3015 curr_peer->state_change_notification = callback;
3016
3017 mutex_unlock(&pHddCtx->tdls_lock);
3018 return 0;
3019
3020
3021}
3022
3023void wlan_hdd_tdls_get_wifi_hal_state(hddTdlsPeer_t *curr_peer,
3024 tANI_S32 *state,
3025 tANI_S32 *reason)
3026{
3027 *reason = curr_peer->reason;
3028
3029 switch(curr_peer->link_status)
3030 {
3031 case eTDLS_LINK_IDLE:
Atul Mittal115287b2014-07-08 13:26:33 +05303032 case eTDLS_LINK_DISCOVERED:
3033 *state = WIFI_TDLS_ENABLED;
3034 break;
Atul Mittalad630e42014-10-07 19:19:14 +05303035 case eTDLS_LINK_DISCOVERING:
Atul Mittal115287b2014-07-08 13:26:33 +05303036 case eTDLS_LINK_CONNECTING:
3037 *state = WIFI_TDLS_TRYING;
3038 break;
3039 case eTDLS_LINK_CONNECTED:
Pradeep Reddy POTTETIf3148e82015-04-16 12:10:33 +05303040 if (TRUE == curr_peer->isOffChannelEstablished)
Pradeep Reddy POTTETI16d83332015-03-26 18:28:13 +05303041 {
3042 *state = WIFI_TDLS_ESTABLISHED_OFF_CHANNEL;
3043 }
3044 else
3045 {
3046 *state = WIFI_TDLS_ESTABLISHED;
3047 }
Atul Mittal115287b2014-07-08 13:26:33 +05303048 break;
3049 case eTDLS_LINK_TEARING:
3050 *state = WIFI_TDLS_DROPPED;
3051 break;
3052 }
3053
3054}
3055
3056int wlan_hdd_tdls_get_status(hdd_adapter_t *pAdapter,
3057 tANI_U8* mac,
3058 tANI_S32 *state,
3059 tANI_S32 *reason)
3060{
3061
3062 hddTdlsPeer_t *curr_peer;
Atul Mittala75fced2014-10-06 13:59:07 +05303063 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Atul Mittal115287b2014-07-08 13:26:33 +05303064 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
3065 if (curr_peer == NULL)
3066 {
Atul Mittala75fced2014-10-06 13:59:07 +05303067 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Atul Mittal115287b2014-07-08 13:26:33 +05303068 FL("curr_peer is NULL"));
Atul Mittal115287b2014-07-08 13:26:33 +05303069
Atul Mittala75fced2014-10-06 13:59:07 +05303070 *state = WIFI_TDLS_DISABLED;
3071 *reason = eTDLS_LINK_UNSPECIFIED;
3072 }
3073 else
3074 {
3075 if (pHddCtx->cfg_ini->fTDLSExternalControl &&
3076 (FALSE == curr_peer->isForcedPeer))
3077 {
3078 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3079 FL("curr_peer is not Forced"));
3080 *state = WIFI_TDLS_DISABLED;
3081 *reason = eTDLS_LINK_UNSPECIFIED;
3082 }
3083 else
3084 {
3085 wlan_hdd_tdls_get_wifi_hal_state(curr_peer, state, reason);
3086 }
3087 }
Atul Mittal115287b2014-07-08 13:26:33 +05303088 return (0);
3089}
3090
Agarwal Ashishef54a182014-12-16 15:07:31 +05303091int hdd_set_tdls_scan_type(hdd_adapter_t *pAdapter,
3092 tANI_U8 *ptr)
3093{
3094 int tdls_scan_type;
Hema Aparna Medicharla26b98042015-01-21 15:02:01 +05303095 hdd_context_t *pHddCtx;
Agarwal Ashishef54a182014-12-16 15:07:31 +05303096 if (NULL == pAdapter)
3097 {
3098 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3099 "%s: pAdapter is NULL", __func__);
3100 return -EINVAL;
3101 }
Hema Aparna Medicharla26b98042015-01-21 15:02:01 +05303102 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Agarwal Ashishef54a182014-12-16 15:07:31 +05303103 tdls_scan_type = ptr[9] - '0';
3104
3105 if (tdls_scan_type <= 2)
3106 {
3107 pHddCtx->cfg_ini->fEnableTDLSScan = tdls_scan_type;
3108 return 0;
3109 }
3110 else
3111 {
3112 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3113 " Wrong value is given for tdls_scan_type "
3114 " Making fEnableTDLSScan as 0 ");
3115 pHddCtx->cfg_ini->fEnableTDLSScan = 0;
3116 return -EINVAL;
3117 }
3118}
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +05303119int wlan_hdd_validate_tdls_context(hdd_context_t *pHddCtx,
3120 tdlsCtx_t *pHddTdlsCtx)
3121{
3122 VOS_STATUS status;
3123 int found = 0;
3124 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
3125 hdd_adapter_t *pAdapter;
Agarwal Ashishef54a182014-12-16 15:07:31 +05303126
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +05303127 if (NULL == pHddTdlsCtx)
3128 {
3129 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3130 FL("TDLS context is NULL"));
3131 return -EINVAL;
3132 }
3133 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
3134 while (NULL != pAdapterNode && VOS_STATUS_SUCCESS == status)
3135 {
3136 pAdapter = pAdapterNode->pAdapter;
3137 if (NULL != pAdapter)
3138 {
3139 if (pHddTdlsCtx == pAdapter->sessionCtx.station.pHddTdlsCtx &&
3140 (NULL != pHddTdlsCtx->pAdapter) &&
3141 (WLAN_HDD_ADAPTER_MAGIC == pHddTdlsCtx->pAdapter->magic))
3142 {
3143 found = 1;
3144 break;
3145 }
3146 }
3147 status = hdd_get_next_adapter (pHddCtx, pAdapterNode, &pNext);
3148 pAdapterNode = pNext;
3149 }
3150 if (found == 1)
3151 {
3152 return 0;
3153 }
3154 else
3155 {
3156 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3157 FL("TDLS context doesnot belongs to valid adapter"));
3158 return -EINVAL;
3159 }
3160}
Atul Mittal115287b2014-07-08 13:26:33 +05303161/*EXT TDLS*/
3162