blob: 3d69137c18fa3ee940682b9121ce8f0a9383d64f [file] [log] [blame]
Kiran V1ccee932012-12-12 14:49:46 -08001/*
Pradeep Reddy POTTETIc7822df2015-02-19 20:15:41 +05302 * Copyright (c) 2012-2015 The Linux Foundation. All rights reserved.
Kiet Lam842dad02014-02-18 18:44:02 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
Gopichand Nakkala0c1331e2013-01-07 22:49:07 -080020 */
Kiet Lam842dad02014-02-18 18:44:02 -080021
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
Kiran V1ccee932012-12-12 14:49:46 -080028/**========================================================================
29
30 \file wlan_hdd_tdls.c
31
Chilam NG571c65a2013-01-19 12:27:36 +053032 \brief WLAN Host Device Driver implementation for TDLS
Kiran V1ccee932012-12-12 14:49:46 -080033
Kiran V1ccee932012-12-12 14:49:46 -080034 ========================================================================*/
35
36#include <wlan_hdd_includes.h>
37#include <wlan_hdd_hostapd.h>
38#include <net/cfg80211.h>
39#include <linux/netdevice.h>
40#include <linux/skbuff.h>
Chilam NG571c65a2013-01-19 12:27:36 +053041#include <linux/list.h>
Kiran V1ccee932012-12-12 14:49:46 -080042#include <linux/etherdevice.h>
43#include <net/ieee80211_radiotap.h>
44#include "wlan_hdd_tdls.h"
Chilam NG571c65a2013-01-19 12:27:36 +053045#include "wlan_hdd_cfg80211.h"
Masti, Narayanraddi1fb32a92015-06-29 13:14:06 +053046#include "wlan_hdd_assoc.h"
47#include "sme_Api.h"
Mahesh A Saptasagar8b231b32014-08-11 11:58:15 +053048#include "vos_sched.h"
Chilam NG571c65a2013-01-19 12:27:36 +053049
Gopichand Nakkala4327a152013-03-04 23:22:42 -080050static tANI_S32 wlan_hdd_get_tdls_discovery_peer_cnt(tdlsCtx_t *pHddTdlsCtx);
51static tANI_S32 wlan_hdd_tdls_peer_reset_discovery_processed(tdlsCtx_t *pHddTdlsCtx);
52static void wlan_hdd_tdls_timers_destroy(tdlsCtx_t *pHddTdlsCtx);
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +053053static void wlan_hdd_tdls_peer_timers_destroy(tdlsCtx_t *pHddTdlsCtx);
Sunil Dutt41de4e22013-11-14 18:09:02 +053054int wpa_tdls_is_allowed_force_peer(tdlsCtx_t *pHddTdlsCtx, u8 *mac);
Hoonki Leed37cbb32013-04-20 00:31:14 -070055#ifdef CONFIG_TDLS_IMPLICIT
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +053056static void wlan_hdd_tdls_implicit_send_discovery_request(tdlsCtx_t *pHddTdlsCtx);
Hoonki Leed37cbb32013-04-20 00:31:14 -070057#endif
Chilam NG571c65a2013-01-19 12:27:36 +053058
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +053059static u8 wlan_hdd_tdls_hash_key (
60#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
61 const u8 *mac
62#else
63 u8 *mac
64#endif
65 )
Hoonki Leef63df0d2013-01-16 19:29:14 -080066{
67 int i;
Hoonki Lee387663d2013-02-05 18:08:43 -080068 u8 key = 0;
69
70 for (i = 0; i < 6; i++)
71 key ^= mac[i];
72
73 return key;
74}
75
Masti, Narayanraddifdde4d02015-04-16 14:41:51 +053076/**
77 * wlan_hdd_tdls_disable_offchan_and_teardown_links - Disable offchannel
78 * and teardown TDLS links
79 * @hddCtx : pointer to hdd context
80 *
81 * Return: None
82 */
83void wlan_hdd_tdls_disable_offchan_and_teardown_links(hdd_context_t *hddctx)
84{
85 u16 connected_tdls_peers = 0;
Masti, Narayanraddi1fb32a92015-06-29 13:14:06 +053086 u8 staIdx;
Masti, Narayanraddi471e9382015-07-23 18:51:29 +053087 hddTdlsPeer_t *curr_peer = NULL;
Masti, Narayanraddifdde4d02015-04-16 14:41:51 +053088 hdd_adapter_t *adapter = NULL;
89
90 if (eTDLS_SUPPORT_NOT_ENABLED == hddctx->tdls_mode) {
91 hddLog(LOG1, FL("TDLS mode is disabled OR not enabled in FW"));
92 return ;
93 }
94
95 adapter = hdd_get_adapter(hddctx, WLAN_HDD_INFRA_STATION);
96
97 if (adapter == NULL) {
98 hddLog(LOGE, FL("Station Adapter Not Found"));
Masti, Narayanraddi70e5b472015-08-04 12:54:16 +053099 goto done;
Masti, Narayanraddifdde4d02015-04-16 14:41:51 +0530100 }
101
102 connected_tdls_peers = wlan_hdd_tdlsConnectedPeers(adapter);
Masti, Narayanraddi1fb32a92015-06-29 13:14:06 +0530103 if (!connected_tdls_peers) {
Masti, Narayanraddi70e5b472015-08-04 12:54:16 +0530104 hddLog(LOG1, FL("No TDLS connected peers to delete TDLS peers"));
105 goto done;
Masti, Narayanraddi1fb32a92015-06-29 13:14:06 +0530106 }
Masti, Narayanraddifdde4d02015-04-16 14:41:51 +0530107
Masti, Narayanraddi471e9382015-07-23 18:51:29 +0530108 /* TDLS is not supported in case of concurrency
109 * Disable TDLS Offchannel to avoid more than two concurrent channels.
110 */
111 if (connected_tdls_peers == 1) {
112 curr_peer = wlan_hdd_tdls_get_connected_peer(adapter);
113 if (curr_peer && (curr_peer->isOffChannelConfigured == TRUE)) {
114 hddLog(LOG1, FL("%s: Concurrency detected, Disable "
115 "TDLS channel switch"), __func__);
116 curr_peer->isOffChannelEstablished = FALSE;
117 sme_SendTdlsChanSwitchReq(WLAN_HDD_GET_HAL_CTX(adapter),
118 adapter->sessionId,
119 curr_peer->peerMac,
120 curr_peer->peerParams.channel,
121 TDLS_OFF_CHANNEL_BW_OFFSET,
122 TDLS_CHANNEL_SWITCH_DISABLE);
Masti, Narayanraddifdde4d02015-04-16 14:41:51 +0530123 }
124 }
Masti, Narayanraddi471e9382015-07-23 18:51:29 +0530125
126 /* Send Msg to PE for sending deauth and deleting all the TDLS peers */
127 sme_DeleteAllTDLSPeers(hddctx->hHal, adapter->sessionId);
128
129 /* As mentioned above TDLS is not supported in case of concurrency
130 * Find the connected peer and generate TDLS teardown indication to
131 * supplicant.
132 */
133 for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++) {
134 if (!hddctx->tdlsConnInfo[staIdx].staId)
135 continue;
136
137 curr_peer = wlan_hdd_tdls_find_all_peer(hddctx,
138 hddctx->tdlsConnInfo[staIdx].peerMac.bytes);
139
140 if (!curr_peer)
141 continue;
142
143 /* Del Sta happened already as part of sme_DeleteAllTDLSPeers
144 * Hence clear hdd data structure.
145 */
146 hdd_roamDeregisterTDLSSTA(adapter,
147 hddctx->tdlsConnInfo[staIdx].staId);
148 wlan_hdd_tdls_decrement_peer_count(adapter);
149 wlan_hdd_tdls_reset_peer(adapter, curr_peer->peerMac);
150
151 hddctx->tdlsConnInfo[staIdx].staId = 0 ;
152 hddctx->tdlsConnInfo[staIdx].sessionId = 255;
153 vos_mem_zero(&hddctx->tdlsConnInfo[staIdx].peerMac,
154 sizeof(v_MACADDR_t)) ;
155 wlan_hdd_tdls_check_bmps(adapter);
156
157 hddLog(LOG1, FL("indicate TDLS teardown (staId %d)"),
158 curr_peer->staId);
159
160 /* Indicate teardown to supplicant */
161 wlan_hdd_tdls_indicate_teardown(
162 curr_peer->pHddTdlsCtx->pAdapter,
163 curr_peer,
164 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
165 }
166
Masti, Narayanraddi70e5b472015-08-04 12:54:16 +0530167done:
Masti, Narayanraddifdde4d02015-04-16 14:41:51 +0530168 wlan_hdd_tdls_set_mode(hddctx, eTDLS_SUPPORT_DISABLED, FALSE);
169 hddLog(LOG1, FL("TDLS Support Disabled"));
170}
171
172/**
173 * hdd_tdls_notify_mode_change - Notify mode change
174 * @adapter: pointer to hdd adapter
175 * @hddCtx : pointer to hdd context
176 *
177 * Return: None
178 */
179void hdd_tdls_notify_mode_change(hdd_adapter_t *adapter, hdd_context_t *hddctx)
180{
Masti, Narayanraddifdde4d02015-04-16 14:41:51 +0530181 wlan_hdd_tdls_disable_offchan_and_teardown_links(hddctx);
182}
183
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800184static v_VOID_t wlan_hdd_tdls_start_peer_discover_timer(tdlsCtx_t *pHddTdlsCtx,
185 tANI_BOOLEAN mutexLock,
186 v_U32_t discoveryExpiry)
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800187{
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800188 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530189 hdd_context_t *pHddCtx;
190
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530191 ENTER();
192
c_hpothu7f63e882013-10-02 19:13:35 +0530193 if ((NULL == pHddTdlsCtx) || (NULL == pHddTdlsCtx->pAdapter) )
194 {
195 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
196 FL(" pHddTdlsCtx or pAdapter points to NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530197 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530198 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530199
200 pHddCtx = WLAN_HDD_GET_CTX( pHddTdlsCtx->pAdapter );
201
c_hpothu7f63e882013-10-02 19:13:35 +0530202 if(0 != (wlan_hdd_validate_context(pHddCtx)))
203 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530204 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530205 }
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800206
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800207 if ( mutexLock )
208 {
Rajesh Chauhana34c6e62014-03-25 16:37:58 +0530209 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800210 }
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800211
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800212 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pHddTdlsCtx->pAdapter);
Deepthi Gowri681c9432015-05-14 11:51:11 +0530213
Gopichand Nakkala3046fc92013-03-23 13:56:43 -0700214 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "beacon rssi: %d",
215 pHddTdlsCtx->ap_rssi);
216
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800217 if ( mutexLock )
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530218 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800219
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530220 EXIT();
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800221 return;
222}
223
Hoonki Leed37cbb32013-04-20 00:31:14 -0700224#ifdef TDLS_USE_SEPARATE_DISCOVERY_TIMER
Hoonki Lee387663d2013-02-05 18:08:43 -0800225static v_VOID_t wlan_hdd_tdls_discover_peer_cb( v_PVOID_t userData )
226{
227 int i;
228 struct list_head *head;
229 struct list_head *pos;
Chilam NG571c65a2013-01-19 12:27:36 +0530230 hddTdlsPeer_t *curr_peer;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530231 hdd_context_t *pHddCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530232 tdlsCtx_t *pHddTdlsCtx;
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800233 int discover_req_sent = 0;
234 v_U32_t discover_expiry = TDLS_SUB_DISCOVERY_PERIOD;
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800235 tANI_BOOLEAN doMutexLock = eANI_BOOLEAN_TRUE;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530236 v_CONTEXT_t pVosContext;
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800237
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530238 ENTER();
239
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530240 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
241 if (NULL == pVosContext)
c_hpothu7f63e882013-10-02 19:13:35 +0530242 {
243 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530244 FL("pVosContext points to NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530245 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530246 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530247
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530248 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
249 if (0 != (wlan_hdd_validate_context(pHddCtx)))
Sushant Kaushik15c4c522014-08-14 12:24:49 +0530250 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530251 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530252 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530253
Rajesh Chauhana34c6e62014-03-25 16:37:58 +0530254 mutex_lock(&pHddCtx->tdls_lock);
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530255 pHddTdlsCtx = (tdlsCtx_t *)userData;
256 if (0 != (wlan_hdd_validate_tdls_context(pHddCtx, pHddTdlsCtx)))
257 {
258 mutex_unlock(&pHddCtx->tdls_lock);
259 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
260 FL("Invalid pHddTdlsCtx context"));
261 return;
262 }
Hoonki Leebfee0342013-01-21 16:43:45 -0800263
Hoonki Lee387663d2013-02-05 18:08:43 -0800264 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: ", __func__);
265
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800266 if (0 == pHddTdlsCtx->discovery_peer_cnt)
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800267 pHddTdlsCtx->discovery_peer_cnt = wlan_hdd_get_tdls_discovery_peer_cnt(pHddTdlsCtx);
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800268
Chilam NG571c65a2013-01-19 12:27:36 +0530269 for (i = 0; i < 256; i++) {
Hoonki Lee387663d2013-02-05 18:08:43 -0800270 head = &pHddTdlsCtx->peer_list[i];
Chilam NG571c65a2013-01-19 12:27:36 +0530271
Hoonki Lee387663d2013-02-05 18:08:43 -0800272 list_for_each (pos, head) {
273 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
Chilam NG571c65a2013-01-19 12:27:36 +0530274
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530275 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Chilam Ng01120412013-02-19 18:32:21 -0800276 "%d " MAC_ADDRESS_STR " %d %d, %d %d %d %d", i,
277 MAC_ADDR_ARRAY(curr_peer->peerMac),
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800278 curr_peer->discovery_processed,
279 discover_req_sent,
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -0800280 curr_peer->tdls_support,
281 curr_peer->link_status,
282 curr_peer->discovery_attempt,
283 pHddTdlsCtx->threshold_config.discovery_tries_n);
Hoonki Lee387663d2013-02-05 18:08:43 -0800284
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800285 if (discover_req_sent < TDLS_MAX_DISCOVER_REQS_PER_TIMER) {
286 if (!curr_peer->discovery_processed) {
Chilam NG571c65a2013-01-19 12:27:36 +0530287
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800288 curr_peer->discovery_processed = 1;
289 discover_req_sent++;
290 pHddTdlsCtx->discovery_peer_cnt--;
291
292 if ((eTDLS_CAP_UNKNOWN == curr_peer->tdls_support) &&
Gopichand Nakkala901e8922013-03-04 23:45:58 -0800293 (eTDLS_LINK_IDLE == curr_peer->link_status) &&
Gopichand Nakkalab88f6772013-02-27 18:12:56 -0800294 (curr_peer->tx_pkt >=
295 pHddTdlsCtx->threshold_config.tx_packet_n)) {
Gopichand Nakkala273d5a02013-02-19 15:15:09 -0800296
297 if (curr_peer->discovery_attempt <
298 pHddTdlsCtx->threshold_config.discovery_tries_n) {
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +0530299 cfg80211_tdls_oper_request(
300 pHddTdlsCtx->pAdapter->dev,
301 curr_peer->peerMac,
302 NL80211_TDLS_DISCOVERY_REQ,
303 FALSE,
304 GFP_KERNEL);
Gopichand Nakkala273d5a02013-02-19 15:15:09 -0800305 curr_peer->discovery_attempt++;
306 }
307 else
308 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530309 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala273d5a02013-02-19 15:15:09 -0800310 "%s: Maximum Discovery retries reached", __func__);
311 curr_peer->tdls_support = eTDLS_CAP_NOT_SUPPORTED;
312 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800313
314 }
315 }
Chilam NG571c65a2013-01-19 12:27:36 +0530316 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800317 else
318 goto exit_loop;
Hoonki Lee387663d2013-02-05 18:08:43 -0800319 }
Hoonki Leef63df0d2013-01-16 19:29:14 -0800320 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800321exit_loop:
Hoonki Leef63df0d2013-01-16 19:29:14 -0800322
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800323 if (0 != pHddTdlsCtx->discovery_peer_cnt) {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530324 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800325 "discovery_peer_cnt is %d , Starting SUB_DISCOVERY_TIMER",
326 pHddTdlsCtx->discovery_peer_cnt);
327 discover_expiry = TDLS_SUB_DISCOVERY_PERIOD;
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800328 doMutexLock = eANI_BOOLEAN_FALSE;
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800329 goto done;
330 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800331 discover_expiry = pHddTdlsCtx->threshold_config.discovery_period_t;
332
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800333 wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
Chilam NG571c65a2013-01-19 12:27:36 +0530334
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530335 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala638ebc72013-03-21 18:04:02 -0700336
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800337 /* Commenting out the following function as it was introducing
338 * a race condition when pHddTdlsCtx is deleted. Also , this
339 * function is consuming more time in the timer callback.
340 * RSSI based trigger needs to revisit this part of the code.
341 */
342
343 /*
344 * wlan_hdd_get_rssi(pAdapter, &pHddTdlsCtx->ap_rssi);
345 */
Chilam NG571c65a2013-01-19 12:27:36 +0530346
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800347done:
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800348 wlan_hdd_tdls_start_peer_discover_timer(pHddTdlsCtx, doMutexLock, discover_expiry);
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800349
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800350 if ( !doMutexLock )
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530351 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530352 EXIT();
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800353 return;
Hoonki Leef63df0d2013-01-16 19:29:14 -0800354}
Hoonki Leed37cbb32013-04-20 00:31:14 -0700355#endif
Chilam NG571c65a2013-01-19 12:27:36 +0530356
Hoonki Lee387663d2013-02-05 18:08:43 -0800357static v_VOID_t wlan_hdd_tdls_update_peer_cb( v_PVOID_t userData )
Chilam NG571c65a2013-01-19 12:27:36 +0530358{
359 int i;
Hoonki Lee387663d2013-02-05 18:08:43 -0800360 struct list_head *head;
361 struct list_head *pos;
Chilam NG571c65a2013-01-19 12:27:36 +0530362 hddTdlsPeer_t *curr_peer;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530363 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530364 hdd_context_t *pHddCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530365 v_CONTEXT_t pVosContext;
Hoonki Leebfee0342013-01-21 16:43:45 -0800366
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530367 ENTER();
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530368 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
369 if (NULL == pVosContext)
c_hpothu7f63e882013-10-02 19:13:35 +0530370 {
371 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530372 FL("pVosContext points to NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530373 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530374 }
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530375 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
376 if (0 != (wlan_hdd_validate_context(pHddCtx)))
Sushant Kaushik15c4c522014-08-14 12:24:49 +0530377 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530378 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530379 }
Rajesh Chauhana34c6e62014-03-25 16:37:58 +0530380 mutex_lock(&pHddCtx->tdls_lock);
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530381 pHddTdlsCtx = (tdlsCtx_t *)userData;
382 if (0 != (wlan_hdd_validate_tdls_context(pHddCtx, pHddTdlsCtx)))
383 {
384 mutex_unlock(&pHddCtx->tdls_lock);
385 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
386 FL("Invalid pHddTdlsCtx context"));
387 return;
388 }
Chilam NG571c65a2013-01-19 12:27:36 +0530389 for (i = 0; i < 256; i++) {
Hoonki Lee387663d2013-02-05 18:08:43 -0800390 head = &pHddTdlsCtx->peer_list[i];
Chilam NG571c65a2013-01-19 12:27:36 +0530391
Hoonki Lee387663d2013-02-05 18:08:43 -0800392 list_for_each (pos, head) {
393 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
Chilam NG571c65a2013-01-19 12:27:36 +0530394
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530395 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee66b75f32013-04-16 18:30:07 -0700396 "%s: " MAC_ADDRESS_STR " link_status %d"
397 " tdls_support %d", __func__, MAC_ADDR_ARRAY(curr_peer->peerMac),
Gopichand Nakkala34d1b062013-03-19 15:28:33 -0700398 curr_peer->link_status, curr_peer->tdls_support);
Hoonki Lee387663d2013-02-05 18:08:43 -0800399
Chilam NG571c65a2013-01-19 12:27:36 +0530400 if (eTDLS_CAP_SUPPORTED == curr_peer->tdls_support) {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530401 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee66b75f32013-04-16 18:30:07 -0700402 "tx %d, rx %d (thr.pkt %d/idle %d), rssi %d (thr.trig %d/hys %d/tear %d)",
403 curr_peer->tx_pkt, curr_peer->rx_pkt,
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800404 pHddTdlsCtx->threshold_config.tx_packet_n,
Hoonki Lee66b75f32013-04-16 18:30:07 -0700405 pHddTdlsCtx->threshold_config.idle_packet_n,
406 curr_peer->rssi,
407 pHddTdlsCtx->threshold_config.rssi_trigger_threshold,
408 pHddTdlsCtx->threshold_config.rssi_hysteresis,
409 pHddTdlsCtx->threshold_config.rssi_teardown_threshold);
Chilam Ng01120412013-02-19 18:32:21 -0800410
Gopichand Nakkala901e8922013-03-04 23:45:58 -0800411 if ((eTDLS_LINK_IDLE == curr_peer->link_status) ||
412 (eTDLS_LINK_DISCOVERING == curr_peer->link_status)){
Sunil Dutt961ecbd2013-11-28 20:04:07 +0530413
414 if (pHddCtx->cfg_ini->fTDLSExternalControl &&
415 (FALSE == curr_peer->isForcedPeer)) {
Ganesh Kondabattini2d7b6a42015-09-01 18:45:18 +0530416 goto next_peer;
Sunil Dutt961ecbd2013-11-28 20:04:07 +0530417 }
418
Chilam NG571c65a2013-01-19 12:27:36 +0530419 if (curr_peer->tx_pkt >=
420 pHddTdlsCtx->threshold_config.tx_packet_n) {
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800421
Gopichand Nakkala8b00c632013-03-08 19:47:52 -0800422 if (HDD_MAX_NUM_TDLS_STA > wlan_hdd_tdlsConnectedPeers(pHddTdlsCtx->pAdapter))
Gopichand Nakkalab977a972013-02-18 19:15:09 -0800423 {
424
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530425 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
426 "Tput trigger TDLS pre-setup");
Chilam NG571c65a2013-01-19 12:27:36 +0530427#ifdef CONFIG_TDLS_IMPLICIT
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +0530428 pHddTdlsCtx->curr_candidate = curr_peer;
429 wlan_hdd_tdls_implicit_send_discovery_request(pHddTdlsCtx);
Chilam NG571c65a2013-01-19 12:27:36 +0530430#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -0800431 }
432 else
433 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530434 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala8b00c632013-03-08 19:47:52 -0800435 "%s: Maximum peer connected already! %d",
436 __func__, wlan_hdd_tdlsConnectedPeers(pHddTdlsCtx->pAdapter) );
Gopichand Nakkalab977a972013-02-18 19:15:09 -0800437 }
Hoonki Leecdd8e962013-01-20 00:45:46 -0800438 goto next_peer;
Chilam NG571c65a2013-01-19 12:27:36 +0530439 }
Hoonki Leefb8df672013-04-10 18:20:34 -0700440 }
441 else if (eTDLS_LINK_CONNECTED == curr_peer->link_status) {
Chilam Ng01120412013-02-19 18:32:21 -0800442 if ((tANI_S32)curr_peer->rssi <
443 (tANI_S32)pHddTdlsCtx->threshold_config.rssi_teardown_threshold) {
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800444
Chilam Ng01120412013-02-19 18:32:21 -0800445 VOS_TRACE( VOS_MODULE_ID_HDD,
446 VOS_TRACE_LEVEL_WARN,
447 "Tear down - low RSSI: " MAC_ADDRESS_STR "!",
448 MAC_ADDR_ARRAY(curr_peer->peerMac));
449#ifdef CONFIG_TDLS_IMPLICIT
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -0700450 wlan_hdd_tdls_indicate_teardown(pHddTdlsCtx->pAdapter,
451 curr_peer,
452 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
Chilam Ng01120412013-02-19 18:32:21 -0800453#endif
Hoonki Leecdd8e962013-01-20 00:45:46 -0800454 goto next_peer;
Chilam NG571c65a2013-01-19 12:27:36 +0530455 }
Chilam Ng01120412013-02-19 18:32:21 -0800456
Naresh Jayaramdb4514b2013-11-25 18:08:10 +0530457 /* Only teardown based on non zero idle packet threshold, to address a use
458 * case where this threshold does not get consider for TEAR DOWN.
459 */
460
461 if (( 0 != pHddTdlsCtx->threshold_config.idle_packet_n ) &&
462 ((curr_peer->tx_pkt <
Chilam Ng01120412013-02-19 18:32:21 -0800463 pHddTdlsCtx->threshold_config.idle_packet_n) &&
464 (curr_peer->rx_pkt <
Naresh Jayaramdb4514b2013-11-25 18:08:10 +0530465 pHddTdlsCtx->threshold_config.idle_packet_n))) {
Chilam Ng01120412013-02-19 18:32:21 -0800466 if (VOS_TIMER_STATE_RUNNING !=
467 vos_timer_getCurrentState(&curr_peer->peerIdleTimer)) {
468 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
469 "Tx/Rx Idle timer start: " MAC_ADDRESS_STR "!",
470 MAC_ADDR_ARRAY(curr_peer->peerMac));
Gopichand Nakkala3046fc92013-03-23 13:56:43 -0700471 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
472 &curr_peer->peerIdleTimer,
473 pHddTdlsCtx->threshold_config.idle_timeout_t);
Chilam Ng01120412013-02-19 18:32:21 -0800474 }
475 } else {
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800476 if (VOS_TIMER_STATE_RUNNING ==
477 vos_timer_getCurrentState(&curr_peer->peerIdleTimer)) {
Chilam Ng01120412013-02-19 18:32:21 -0800478 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
479 "Tx/Rx Idle timer stop: " MAC_ADDRESS_STR "!",
480 MAC_ADDR_ARRAY(curr_peer->peerMac));
481 vos_timer_stop( &curr_peer->peerIdleTimer);
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800482 }
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800483 }
Chilam Ng01120412013-02-19 18:32:21 -0800484
Hoonki Leecdd8e962013-01-20 00:45:46 -0800485// if (curr_peer->rssi <
486// (pHddTdlsCtx->threshold_config.rssi_hysteresis +
487// pHddTdlsCtx->ap_rssi)) {
488//
489//#ifdef CONFIG_TDLS_IMPLICIT
490// cfg80211_tdls_oper_request(pHddTdlsCtx->dev,
491// curr_peer->peerMac,
492// NL80211_TDLS_TEARDOWN, FALSE,
493// GFP_KERNEL);
494//#endif
495// }
Chilam NG571c65a2013-01-19 12:27:36 +0530496 }
Chilam Ng01120412013-02-19 18:32:21 -0800497 } else if (eTDLS_CAP_UNKNOWN == curr_peer->tdls_support) {
Sunil Dutt961ecbd2013-11-28 20:04:07 +0530498
499 if (pHddCtx->cfg_ini->fTDLSExternalControl &&
500 (FALSE == curr_peer->isForcedPeer)) {
Ganesh Kondabattini2d7b6a42015-09-01 18:45:18 +0530501 goto next_peer;
Sunil Dutt961ecbd2013-11-28 20:04:07 +0530502 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -0700503 if (!TDLS_IS_CONNECTED(curr_peer)) {
Chilam Ng01120412013-02-19 18:32:21 -0800504 if (curr_peer->tx_pkt >=
505 pHddTdlsCtx->threshold_config.tx_packet_n) {
Chilam Ng01120412013-02-19 18:32:21 -0800506
Sunil Duttb0d39242014-09-10 23:54:51 +0530507 /* Ignore discovery attempt if External Control is enabled, that
508 * is, peer is forced. In that case, continue discovery attempt
509 * regardless attempt count
510 */
511 if (curr_peer->isForcedPeer || curr_peer->discovery_attempt++ <
Chilam Ng01120412013-02-19 18:32:21 -0800512 pHddTdlsCtx->threshold_config.discovery_tries_n) {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530513 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
514 "TDLS UNKNOWN discover ");
Hoonki Leed37cbb32013-04-20 00:31:14 -0700515#ifdef CONFIG_TDLS_IMPLICIT
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +0530516 pHddTdlsCtx->curr_candidate = curr_peer;
517 wlan_hdd_tdls_implicit_send_discovery_request(pHddTdlsCtx);
Hoonki Leed37cbb32013-04-20 00:31:14 -0700518#endif
Chilam Ng01120412013-02-19 18:32:21 -0800519 }
Gopichand Nakkala901e8922013-03-04 23:45:58 -0800520 else
Gopichand Nakkala8b00c632013-03-08 19:47:52 -0800521 {
Gopichand Nakkala901e8922013-03-04 23:45:58 -0800522 curr_peer->tdls_support = eTDLS_CAP_NOT_SUPPORTED;
Atul Mittal115287b2014-07-08 13:26:33 +0530523 wlan_hdd_tdls_set_peer_link_status(
524 curr_peer,
525 eTDLS_LINK_IDLE,
526 eTDLS_LINK_NOT_SUPPORTED);
527
Gopichand Nakkala8b00c632013-03-08 19:47:52 -0800528 }
Chilam Ng01120412013-02-19 18:32:21 -0800529 }
530 }
Chilam NG571c65a2013-01-19 12:27:36 +0530531 }
532
Hoonki Leecdd8e962013-01-20 00:45:46 -0800533next_peer:
Chilam NG571c65a2013-01-19 12:27:36 +0530534 curr_peer->tx_pkt = 0;
Chilam Ng1279e232013-01-25 15:06:52 -0800535 curr_peer->rx_pkt = 0;
Hoonki Lee387663d2013-02-05 18:08:43 -0800536 }
Chilam NG571c65a2013-01-19 12:27:36 +0530537 }
538
Gopichand Nakkala3046fc92013-03-23 13:56:43 -0700539 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
540 &pHddTdlsCtx->peerUpdateTimer,
541 pHddTdlsCtx->threshold_config.tx_period_t);
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530542 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530543 EXIT();
Chilam NG571c65a2013-01-19 12:27:36 +0530544}
545
Chilam Ng1279e232013-01-25 15:06:52 -0800546static v_VOID_t wlan_hdd_tdls_idle_cb( v_PVOID_t userData )
547{
Lee Hoonkic1262f22013-01-24 21:59:00 -0800548#ifdef CONFIG_TDLS_IMPLICIT
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530549 hddTdlsPeer_t *curr_peer;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530550 tdlsCtx_t *pHddTdlsCtx;
551 hdd_context_t *pHddCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530552 v_CONTEXT_t pVosContext;
Chilam Ng1279e232013-01-25 15:06:52 -0800553
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530554 ENTER();
555
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530556 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
557 if (NULL == pVosContext)
558 {
559 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
560 FL("pVosContext points to NULL"));
561 return;
562 }
563 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
564 if (0 != (wlan_hdd_validate_context(pHddCtx)))
565 {
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530566 return;
567 }
568
569 mutex_lock(&pHddCtx->tdls_lock);
570
571 curr_peer = (hddTdlsPeer_t *)userData;
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700572 if (NULL == curr_peer)
573 {
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530574 mutex_unlock(&pHddCtx->tdls_lock);
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700575 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu7f63e882013-10-02 19:13:35 +0530576 FL("Invalid tdls idle timer expired"));
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700577 return;
578 }
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530579
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530580 pHddTdlsCtx = curr_peer->pHddTdlsCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530581 if (0 != (wlan_hdd_validate_tdls_context(pHddCtx, pHddTdlsCtx)))
c_hpothu7f63e882013-10-02 19:13:35 +0530582 {
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530583 mutex_unlock(&pHddCtx->tdls_lock);
c_hpothu7f63e882013-10-02 19:13:35 +0530584 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530585 FL("Invalid pHddTdlsCtx context"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530586 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530587 }
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700588
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530589 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -0800590 "%s: Tx/Rx Idle " MAC_ADDRESS_STR " tx_pkt: %d, rx_pkt: %d, idle_packet_n: %d",
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700591 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac),
592 curr_peer->tx_pkt,
593 curr_peer->rx_pkt,
594 curr_peer->pHddTdlsCtx->threshold_config.idle_packet_n);
595
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700596 /* Check tx/rx statistics on this tdls link for recent activities and
597 * then decide whether to tear down the link or keep it.
598 */
599 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))
600 {
601 /* this tdls link got back to normal, so keep it */
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530602 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700603 "%s: tdls link to " MAC_ADDRESS_STR " back to normal, will stay",
604 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
605 }
606 else
607 {
608 /* this tdls link needs to get torn down */
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530609 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700610 "%s: trigger tdls link to " MAC_ADDRESS_STR " down",
611 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
612
613 wlan_hdd_tdls_indicate_teardown(curr_peer->pHddTdlsCtx->pAdapter,
614 curr_peer,
615 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
616 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530617 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530618 EXIT();
Chilam Ng1279e232013-01-25 15:06:52 -0800619#endif
620}
621
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700622static v_VOID_t wlan_hdd_tdls_discovery_timeout_peer_cb(v_PVOID_t userData)
623{
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700624 int i;
625 struct list_head *head;
626 hddTdlsPeer_t *tmp;
627 struct list_head *pos, *q;
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700628 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530629 hdd_context_t *pHddCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530630 v_CONTEXT_t pVosContext;
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700631
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530632 ENTER();
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530633 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
634 if (NULL == pVosContext)
c_hpothu7f63e882013-10-02 19:13:35 +0530635 {
636 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530637 FL("pVosContext points to NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530638 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530639 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530640
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530641 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
642 if (0 != (wlan_hdd_validate_context(pHddCtx)))
Sushant Kaushik15c4c522014-08-14 12:24:49 +0530643 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530644 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530645 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530646
Rajesh Chauhana34c6e62014-03-25 16:37:58 +0530647 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700648
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530649 pHddTdlsCtx = (tdlsCtx_t *)userData;
650 if (0 != (wlan_hdd_validate_tdls_context(pHddCtx, pHddTdlsCtx)))
651 {
652 mutex_unlock(&pHddCtx->tdls_lock);
653 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
654 FL("Invalid pHddTdlsCtx context"));
655 return;
656 }
657
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700658 for (i = 0; i < 256; i++) {
659 head = &pHddTdlsCtx->peer_list[i];
660 list_for_each_safe (pos, q, head) {
661 tmp = list_entry(pos, hddTdlsPeer_t, node);
662 if (eTDLS_LINK_DISCOVERING == tmp->link_status)
663 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530664 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700665 "%s: " MAC_ADDRESS_STR " to idle state", __func__,
666 MAC_ADDR_ARRAY(tmp->peerMac));
Atul Mittal115287b2014-07-08 13:26:33 +0530667 wlan_hdd_tdls_set_peer_link_status(
668 tmp,
669 eTDLS_LINK_IDLE,
Atul Mittalad630e42014-10-07 19:19:14 +0530670 eTDLS_LINK_NOT_SUPPORTED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700671 }
672 }
673 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700674
675 pHddTdlsCtx->discovery_sent_cnt = 0;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -0700676 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700677
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530678 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700679
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700680 wlan_hdd_tdls_check_bmps(pHddTdlsCtx->pAdapter);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530681 EXIT();
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700682 return;
683}
684
Hoonki Lee14621352013-04-16 17:51:19 -0700685static v_VOID_t wlan_hdd_tdls_initiator_wait_cb( v_PVOID_t userData )
686{
687 hddTdlsPeer_t *curr_peer = (hddTdlsPeer_t *)userData;
688 tdlsCtx_t *pHddTdlsCtx;
689
Mahesh A Saptasagar4534e2b2015-03-05 20:45:41 +0530690 ENTER();
Hoonki Lee14621352013-04-16 17:51:19 -0700691 if ( NULL == curr_peer )
c_hpothu7f63e882013-10-02 19:13:35 +0530692 {
693 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
694 FL("curr_peer is NULL"));
Hoonki Lee14621352013-04-16 17:51:19 -0700695 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530696 }
Hoonki Lee14621352013-04-16 17:51:19 -0700697
698 pHddTdlsCtx = curr_peer->pHddTdlsCtx;
699
700 if ( NULL == pHddTdlsCtx )
c_hpothu7f63e882013-10-02 19:13:35 +0530701 {
Ratheesh S P36dbc932015-08-07 14:28:57 +0530702 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
c_hpothu7f63e882013-10-02 19:13:35 +0530703 FL("pHddTdlsCtx is NULL"));
Hoonki Lee14621352013-04-16 17:51:19 -0700704 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530705 }
Mahesh A Saptasagar4534e2b2015-03-05 20:45:41 +0530706 if (0 != (wlan_hdd_validate_context(
707 WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter))))
708 {
709 return;
710 }
Hoonki Lee14621352013-04-16 17:51:19 -0700711 WLANTL_ResumeDataTx( (WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter))->pvosContext,
712 (v_U8_t *)&curr_peer->staId);
Mahesh A Saptasagar4534e2b2015-03-05 20:45:41 +0530713 EXIT();
Hoonki Lee14621352013-04-16 17:51:19 -0700714}
715
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800716static void wlan_hdd_tdls_free_list(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800717{
718 int i;
719 struct list_head *head;
720 hddTdlsPeer_t *tmp;
721 struct list_head *pos, *q;
722
c_hpothu7f63e882013-10-02 19:13:35 +0530723 if (NULL == pHddTdlsCtx)
724 {
Ratheesh S P36dbc932015-08-07 14:28:57 +0530725 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
c_hpothu7f63e882013-10-02 19:13:35 +0530726 FL("pHddTdlsCtx is NULL"));
727 return;
728 }
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800729
730 for (i = 0; i < 256; i++) {
731 head = &pHddTdlsCtx->peer_list[i];
732 list_for_each_safe (pos, q, head) {
733 tmp = list_entry(pos, hddTdlsPeer_t, node);
734 list_del(pos);
735 vos_mem_free(tmp);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -0800736 tmp = NULL;
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800737 }
738 }
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800739}
740
Sameer Thalappilbee426e2013-10-30 10:30:30 -0700741static void wlan_hdd_tdls_schedule_scan(struct work_struct *work)
742{
743 tdls_scan_context_t *scan_ctx =
744 container_of(work, tdls_scan_context_t, tdls_scan_work.work);
745
746 if (NULL == scan_ctx)
c_hpothu7f63e882013-10-02 19:13:35 +0530747 {
748 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
749 FL("scan_ctx is NULL"));
Sameer Thalappilbee426e2013-10-30 10:30:30 -0700750 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530751 }
Sameer Thalappilbee426e2013-10-30 10:30:30 -0700752
753 if (unlikely(TDLS_CTX_MAGIC != scan_ctx->magic))
754 return;
755
756 scan_ctx->attempt++;
757
758 wlan_hdd_cfg80211_scan(scan_ctx->wiphy,
759#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
760 scan_ctx->dev,
761#endif
762 scan_ctx->scan_request);
763}
764
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530765void wlan_hdd_tdls_btCoex_cb(void *data, int indType)
766{
767 hdd_adapter_t *pAdapter;
768 hdd_context_t *pHddCtx;
769 u16 connectedTdlsPeers;
770 tdlsCtx_t *pHddTdlsCtx;
771 hddTdlsPeer_t *currPeer;
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530772
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530773 ENTER();
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530774 if ((NULL == data) || (indType < 0))
775 {
776 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
777 FL("Invalid arguments"));
778 return;
779 }
780
781 pHddCtx = (hdd_context_t *)data;
782 if (0 != (wlan_hdd_validate_context(pHddCtx)))
783 {
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530784 return;
785 }
786
787 /* if tdls is not enabled, then continue btCoex */
788 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
789 {
790 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
791 FL("tdls is not enabled"));
792 return;
793 }
794
795 /* get pAdapter context, do we need WLAN_HDD_P2P_CLIENT */
796 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
797 if (NULL == pAdapter)
798 {
799 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
800 FL("pAdapter is not valid"));
801 return;
802 }
803
804 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
805 if (NULL == pHddTdlsCtx)
806 {
807 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
808 FL("pHddTdlsCtx is not valid"));
809 return;
810 }
811
812 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
813 "%s: BtCoex notification type %d", __func__, indType);
814 /* BtCoex notification type enabled, Disable TDLS */
815 if (indType == SIR_COEX_IND_TYPE_TDLS_DISABLE)
816 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530817 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530818 FL("BtCoex notification, Disable TDLS"));
819
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530820 /* tdls is in progress */
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +0530821 currPeer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, TRUE);
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530822 if (NULL != currPeer)
823 {
824 wlan_hdd_tdls_set_peer_link_status (currPeer,
825 eTDLS_LINK_IDLE,
826 eTDLS_LINK_UNSPECIFIED);
827 }
828
829 /* while tdls is up */
830 if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode ||
831 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == pHddCtx->tdls_mode)
832 {
833 connectedTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
834 /* disable implicit trigger logic & tdls operatoin */
835 wlan_hdd_tdls_set_mode(pHddCtx, eTDLS_SUPPORT_DISABLED, FALSE);
836 pHddCtx->is_tdls_btc_enabled = FALSE;
837
838 /* teardown the peers on the btcoex */
839 if (connectedTdlsPeers)
840 {
841 tANI_U8 staIdx;
842 hddTdlsPeer_t *curr_peer;
843
844 for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
845 {
846 if (pHddCtx->tdlsConnInfo[staIdx].staId)
847 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530848 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
849 ("%s: indicate TDLS teardown (staId %d)"),
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530850 __func__,pHddCtx->tdlsConnInfo[staIdx].staId);
851
852 #ifdef CONFIG_TDLS_IMPLICIT
853 curr_peer = wlan_hdd_tdls_find_all_peer(pHddCtx,
854 pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes);
855 if(curr_peer) {
856 wlan_hdd_tdls_indicate_teardown(
857 curr_peer->pHddTdlsCtx->pAdapter, curr_peer,
858 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
859 }
860 #endif
861 }
862 }
863 }
864 }
865 }
866 /* BtCoex notification type enabled, Enable TDLS */
867 else if (indType == SIR_COEX_IND_TYPE_TDLS_ENABLE)
868 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530869 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530870 FL("BtCoex notification, Enable TDLS"));
871 /* if tdls was enabled before btCoex, re-enable tdls mode */
872 if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode_last ||
873 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == pHddCtx->tdls_mode_last)
874 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530875 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530876 ("%s: revert tdls mode %d"), __func__,
877 pHddCtx->tdls_mode_last);
878 pHddCtx->is_tdls_btc_enabled = TRUE;
879 wlan_hdd_tdls_set_mode(pHddCtx, pHddCtx->tdls_mode_last, FALSE);
880 }
881 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530882 EXIT();
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530883 return;
884}
885
Agarwal Ashish4b87f922014-06-18 03:03:21 +0530886/* initialize TDLS global context */
887void wlan_hdd_tdls_init(hdd_context_t *pHddCtx )
888{
889 v_U8_t staIdx;
Chandrasekaran, Manishekar0de84dc2015-03-10 15:12:34 +0530890 eHalStatus status;
Sameer Thalappilbee426e2013-10-30 10:30:30 -0700891
Agarwal Ashish4b87f922014-06-18 03:03:21 +0530892 pHddCtx->connected_peer_count = 0;
893
894 pHddCtx->tdls_scan_ctxt.magic = 0;
895 pHddCtx->tdls_scan_ctxt.attempt = 0;
896 pHddCtx->tdls_scan_ctxt.reject = 0;
897 pHddCtx->tdls_scan_ctxt.scan_request = NULL;
898
899 for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
900 {
901 pHddCtx->tdlsConnInfo[staIdx].staId = 0;
902 pHddCtx->tdlsConnInfo[staIdx].sessionId = 255;
903 vos_mem_zero(&pHddCtx->tdlsConnInfo[staIdx].peerMac,
904 sizeof(v_MACADDR_t)) ;
905 }
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530906 pHddCtx->is_tdls_btc_enabled = TRUE;
Chandrasekaran, Manishekar0de84dc2015-03-10 15:12:34 +0530907 status = sme_RegisterBtCoexTDLSCallback(pHddCtx->hHal,
908 wlan_hdd_tdls_btCoex_cb);
909 if (status != eHAL_STATUS_SUCCESS) {
910 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to register BT Coex TDLS callback"));
911 }
Agarwal Ashish4b87f922014-06-18 03:03:21 +0530912
913 if (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger)
914 {
915 pHddCtx->tdls_mode = eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY;
Ratheesh S P36dbc932015-08-07 14:28:57 +0530916 hddLog(VOS_TRACE_LEVEL_INFO, "%s TDLS Implicit trigger not enabled!", __func__);
Agarwal Ashish4b87f922014-06-18 03:03:21 +0530917 }
918 else
919 {
920 pHddCtx->tdls_mode = eTDLS_SUPPORT_ENABLED;
921 }
922}
923
924int wlan_hdd_sta_tdls_init(hdd_adapter_t *pAdapter)
Chilam Ng01120412013-02-19 18:32:21 -0800925{
Chilam Ng01120412013-02-19 18:32:21 -0800926 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Hoonki Lee27511902013-03-14 18:19:06 -0700927 tdlsCtx_t *pHddTdlsCtx;
Chilam Ng01120412013-02-19 18:32:21 -0800928 int i;
Sunil Dutt66485cb2013-12-19 19:05:03 +0530929 if (NULL == pHddCtx)
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +0530930 {
931 hddLog(VOS_TRACE_LEVEL_ERROR, "%s pHddCtx is NULL", __func__);
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530932 return -EINVAL;
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +0530933 }
Sunil Dutt66485cb2013-12-19 19:05:03 +0530934
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +0530935 if (test_bit(TDLS_INIT_DONE, &pAdapter->event_flags))
936 {
937 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530938 "%s: TDLS INIT DONE set to 1, no point in re-init", __func__);
939 return -EALREADY;
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +0530940 }
Sunil Dutt66485cb2013-12-19 19:05:03 +0530941
Hoonki Lee27511902013-03-14 18:19:06 -0700942 if ((FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport) ||
943 (FALSE == sme_IsFeatureSupportedByFW(TDLS)))
944 {
945 pHddCtx->tdls_mode = eTDLS_SUPPORT_NOT_ENABLED;
946 pAdapter->sessionCtx.station.pHddTdlsCtx = NULL;
Ratheesh S P36dbc932015-08-07 14:28:57 +0530947 hddLog(VOS_TRACE_LEVEL_INFO, "%s TDLS not enabled (%d) or FW doesn't support (%d)!",
Hoonki Lee27511902013-03-14 18:19:06 -0700948 __func__, pHddCtx->cfg_ini->fEnableTDLSSupport,
949 sme_IsFeatureSupportedByFW(TDLS));
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530950 return -EINVAL;
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800951 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530952 /* TDLS is supported only in STA / P2P Client modes,
953 * hence the check for TDLS support in a specific Device mode.
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530954 */
955 if (0 == WLAN_HDD_IS_TDLS_SUPPORTED_ADAPTER(pAdapter))
956 {
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +0530957 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 +0530958 return -EINVAL;
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530959 }
960 /* Check for the valid pHddTdlsCtx. If valid do not further
961 * allocate the memory, rather continue with the initialization.
962 * If tdls_initialization would get reinvoked without tdls_exit
963 * getting invoked (SSR) there is no point to further proceed
964 * with the memory allocations.
965 */
966 if (NULL == pAdapter->sessionCtx.station.pHddTdlsCtx)
967 {
968 pHddTdlsCtx = vos_mem_malloc(sizeof(tdlsCtx_t));
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800969
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530970 if (NULL == pHddTdlsCtx) {
971 hddLog(VOS_TRACE_LEVEL_ERROR, "%s malloc failed!", __func__);
972 pAdapter->sessionCtx.station.pHddTdlsCtx = NULL;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530973 return -ENOMEM;
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530974 }
975 /* initialize TDLS pAdater context */
976 vos_mem_zero(pHddTdlsCtx, sizeof(tdlsCtx_t));
977#ifdef TDLS_USE_SEPARATE_DISCOVERY_TIMER
978 vos_timer_init(&pHddTdlsCtx->peerDiscoverTimer,
979 VOS_TIMER_TYPE_SW,
980 wlan_hdd_tdls_discover_peer_cb,
981 pHddTdlsCtx);
982#endif
Hoonki Lee27511902013-03-14 18:19:06 -0700983
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530984 vos_timer_init(&pHddTdlsCtx->peerUpdateTimer,
985 VOS_TIMER_TYPE_SW,
986 wlan_hdd_tdls_update_peer_cb,
987 pHddTdlsCtx);
988 vos_timer_init(&pHddTdlsCtx->peerDiscoveryTimeoutTimer,
989 VOS_TIMER_TYPE_SW,
990 wlan_hdd_tdls_discovery_timeout_peer_cb,
991 pHddTdlsCtx);
992
993 pAdapter->sessionCtx.station.pHddTdlsCtx = pHddTdlsCtx;
Hoonki Lee27511902013-03-14 18:19:06 -0700994 }
995
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530996 pHddTdlsCtx = pAdapter->sessionCtx.station.pHddTdlsCtx;
Hoonki Lee27511902013-03-14 18:19:06 -0700997
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700998 sme_SetTdlsPowerSaveProhibited(WLAN_HDD_GET_HAL_CTX(pAdapter), 0);
Hoonki Lee27511902013-03-14 18:19:06 -0700999
Hoonki Lee27511902013-03-14 18:19:06 -07001000 pHddTdlsCtx->pAdapter = pAdapter;
1001
1002 for (i = 0; i < 256; i++)
1003 {
1004 INIT_LIST_HEAD(&pHddTdlsCtx->peer_list[i]);
1005 }
1006
Hoonki Leed37cbb32013-04-20 00:31:14 -07001007 pHddTdlsCtx->curr_candidate = NULL;
1008 pHddTdlsCtx->magic = 0;
1009
Hoonki Lee27511902013-03-14 18:19:06 -07001010 /* remember configuration even if it is not used right now. it could be used later */
1011 pHddTdlsCtx->threshold_config.tx_period_t = pHddCtx->cfg_ini->fTDLSTxStatsPeriod;
1012 pHddTdlsCtx->threshold_config.tx_packet_n = pHddCtx->cfg_ini->fTDLSTxPacketThreshold;
1013 pHddTdlsCtx->threshold_config.discovery_period_t = pHddCtx->cfg_ini->fTDLSDiscoveryPeriod;
1014 pHddTdlsCtx->threshold_config.discovery_tries_n = pHddCtx->cfg_ini->fTDLSMaxDiscoveryAttempt;
1015 pHddTdlsCtx->threshold_config.idle_timeout_t = pHddCtx->cfg_ini->fTDLSIdleTimeout;
1016 pHddTdlsCtx->threshold_config.idle_packet_n = pHddCtx->cfg_ini->fTDLSIdlePacketThreshold;
1017 pHddTdlsCtx->threshold_config.rssi_hysteresis = pHddCtx->cfg_ini->fTDLSRSSIHysteresis;
1018 pHddTdlsCtx->threshold_config.rssi_trigger_threshold = pHddCtx->cfg_ini->fTDLSRSSITriggerThreshold;
1019 pHddTdlsCtx->threshold_config.rssi_teardown_threshold = pHddCtx->cfg_ini->fTDLSRSSITeardownThreshold;
Chilam NG571c65a2013-01-19 12:27:36 +05301020
Anand N Sunkaddc63c792015-06-03 14:33:24 +05301021 vos_init_delayed_work(&pHddCtx->tdls_scan_ctxt.tdls_scan_work,
1022 wlan_hdd_tdls_schedule_scan);
1023 set_bit(TDLS_INIT_DONE, &pAdapter->event_flags);
Hoonki Lee27511902013-03-14 18:19:06 -07001024
1025 return 0;
Chilam NG571c65a2013-01-19 12:27:36 +05301026}
1027
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +05301028void wlan_hdd_tdls_exit(hdd_adapter_t *pAdapter, tANI_BOOLEAN mutexLock)
Chilam NG571c65a2013-01-19 12:27:36 +05301029{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001030 tdlsCtx_t *pHddTdlsCtx;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07001031 hdd_context_t *pHddCtx;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001032
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05301033 if (!pAdapter) {
1034 hddLog(VOS_TRACE_LEVEL_ERROR, FL("HDD adpater is NULL"));
1035 return;
1036 }
1037
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301038 /*
1039 * NOTE: The Callers of this function should ensure to acquire the
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301040 * tdls_lock to avoid any concurrent access to the Adapter and logp
1041 * protection has to be ensured.
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301042 */
1043
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301044 pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +05301045
1046 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301047 {
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +05301048 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1049 "%s: HDD context is Null", __func__);
1050 return ;
1051 }
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301052 if (!test_bit(TDLS_INIT_DONE, &pAdapter->event_flags))
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +05301053 {
Ratheesh S P36dbc932015-08-07 14:28:57 +05301054 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301055 "%s: TDLS INIT DONE set to 0, no point in exit", __func__);
1056 return;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301057 }
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301058 clear_bit(TDLS_INIT_DONE, &pAdapter->event_flags);
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301059
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001060 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001061 if (NULL == pHddTdlsCtx)
1062 {
Ratheesh S P36dbc932015-08-07 14:28:57 +05301063 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
c_hpothu7f63e882013-10-02 19:13:35 +05301064 FL("pHddTdlsCtx is NULL"));
Hoonki Leebfee0342013-01-21 16:43:45 -08001065 return;
1066 }
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301067
Anand N Sunkad860e5ea2015-03-30 14:41:51 +05301068 vos_flush_delayed_work(&pHddCtx->tdls_scan_ctxt.tdls_scan_work);
Hoonki Leebfee0342013-01-21 16:43:45 -08001069
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001070 /* must stop timer here before freeing peer list, because peerIdleTimer is
1071 part of peer list structure. */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001072 wlan_hdd_tdls_timers_destroy(pHddTdlsCtx);
1073 wlan_hdd_tdls_free_list(pHddTdlsCtx);
Chilam Nga75d8b62013-01-29 01:35:59 -08001074
Hoonki Lee93e67ff2013-03-19 15:49:25 -07001075 wlan_hdd_tdls_free_scan_request(&pHddCtx->tdls_scan_ctxt);
Sushant Kaushik15c4c522014-08-14 12:24:49 +05301076 pHddTdlsCtx->magic = 0;
1077 pHddTdlsCtx->pAdapter = NULL;
Chilam Nga75d8b62013-01-29 01:35:59 -08001078 vos_mem_free(pHddTdlsCtx);
Pradeep Reddy POTTETI59c90d62014-03-24 19:45:47 +05301079 pAdapter->sessionCtx.station.pHddTdlsCtx = NULL;
Chilam Nga75d8b62013-01-29 01:35:59 -08001080 pHddTdlsCtx = NULL;
Chilam NG571c65a2013-01-19 12:27:36 +05301081}
1082
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301083/* stop all monitoring timers per Adapter */
1084static void wlan_hdd_tdls_monitor_timers_stop(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001085{
Hoonki Leed37cbb32013-04-20 00:31:14 -07001086#ifdef TDLS_USE_SEPARATE_DISCOVERY_TIMER
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001087 vos_timer_stop(&pHddTdlsCtx->peerDiscoverTimer);
Hoonki Leed37cbb32013-04-20 00:31:14 -07001088#endif
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001089 vos_timer_stop(&pHddTdlsCtx->peerUpdateTimer);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001090 vos_timer_stop(&pHddTdlsCtx->peerDiscoveryTimeoutTimer);
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301091}
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001092
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301093/* stop all per peer timers */
1094static void wlan_hdd_tdls_peer_timers_stop(tdlsCtx_t *pHddTdlsCtx)
1095{
1096 int i;
1097 struct list_head *head;
1098 struct list_head *pos;
1099 hddTdlsPeer_t *curr_peer;
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001100 for (i = 0; i < 256; i++)
1101 {
1102 head = &pHddTdlsCtx->peer_list[i];
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001103 list_for_each (pos, head) {
1104 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301105 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Chilam Ng01120412013-02-19 18:32:21 -08001106 "%s: " MAC_ADDRESS_STR " -> stop idle timer",
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001107 __func__,
Chilam Ng01120412013-02-19 18:32:21 -08001108 MAC_ADDR_ARRAY(curr_peer->peerMac));
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001109 vos_timer_stop ( &curr_peer->peerIdleTimer );
Hoonki Lee14621352013-04-16 17:51:19 -07001110 vos_timer_stop( &curr_peer->initiatorWaitTimeoutTimer );
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001111 }
1112 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001113}
1114
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301115/* stop all the tdls timers running */
1116static void wlan_hdd_tdls_timers_stop(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001117{
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301118 wlan_hdd_tdls_monitor_timers_stop(pHddTdlsCtx);
1119 wlan_hdd_tdls_peer_timers_stop(pHddTdlsCtx);
1120}
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001121
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301122static void wlan_hdd_tdls_monitor_timers_destroy(tdlsCtx_t *pHddTdlsCtx)
1123{
Hoonki Leed37cbb32013-04-20 00:31:14 -07001124#ifdef TDLS_USE_SEPARATE_DISCOVERY_TIMER
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001125 vos_timer_stop(&pHddTdlsCtx->peerDiscoverTimer);
1126 vos_timer_destroy(&pHddTdlsCtx->peerDiscoverTimer);
Hoonki Leed37cbb32013-04-20 00:31:14 -07001127#endif
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001128 vos_timer_stop(&pHddTdlsCtx->peerUpdateTimer);
1129 vos_timer_destroy(&pHddTdlsCtx->peerUpdateTimer);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001130 vos_timer_stop(&pHddTdlsCtx->peerDiscoveryTimeoutTimer);
1131 vos_timer_destroy(&pHddTdlsCtx->peerDiscoveryTimeoutTimer);
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301132}
1133/*Free all the timers related to the TDLS peer */
1134static void wlan_hdd_tdls_peer_timers_destroy(tdlsCtx_t *pHddTdlsCtx)
1135{
1136 int i;
1137 struct list_head *head;
1138 struct list_head *pos;
1139 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001140 for (i = 0; i < 256; i++)
1141 {
1142 head = &pHddTdlsCtx->peer_list[i];
1143
1144 list_for_each (pos, head) {
1145 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
1146
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301147 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Chilam Ng01120412013-02-19 18:32:21 -08001148 "%s: " MAC_ADDRESS_STR " -> destroy idle timer",
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001149 __func__,
Chilam Ng01120412013-02-19 18:32:21 -08001150 MAC_ADDR_ARRAY(curr_peer->peerMac));
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001151 vos_timer_stop ( &curr_peer->peerIdleTimer );
1152 vos_timer_destroy ( &curr_peer->peerIdleTimer );
Hoonki Lee14621352013-04-16 17:51:19 -07001153 vos_timer_stop(&curr_peer->initiatorWaitTimeoutTimer);
1154 vos_timer_destroy(&curr_peer->initiatorWaitTimeoutTimer);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001155 }
1156 }
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301157
1158}
1159
1160/* destroy all the tdls timers running */
1161static void wlan_hdd_tdls_timers_destroy(tdlsCtx_t *pHddTdlsCtx)
1162{
1163 wlan_hdd_tdls_monitor_timers_destroy(pHddTdlsCtx);
1164 wlan_hdd_tdls_peer_timers_destroy(pHddTdlsCtx);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001165}
1166
Hoonki Lee387663d2013-02-05 18:08:43 -08001167/* if mac address exist, return pointer
1168 if mac address doesn't exist, create a list and add, return pointer
1169 return NULL if fails to get new mac address
1170*/
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +05301171hddTdlsPeer_t *wlan_hdd_tdls_get_peer(hdd_adapter_t *pAdapter,
1172#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1173 const u8 *mac
1174#else
1175 u8 *mac
1176#endif
1177 )
Chilam NG571c65a2013-01-19 12:27:36 +05301178{
Hoonki Lee387663d2013-02-05 18:08:43 -08001179 struct list_head *head;
1180 hddTdlsPeer_t *peer;
1181 u8 key;
Gopichand Nakkala4ddf0192013-03-27 13:41:20 -07001182 tdlsCtx_t *pHddTdlsCtx;
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05301183 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301184
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05301185
1186 if (!pAdapter) {
1187 hddLog(VOS_TRACE_LEVEL_ERROR, FL("HDD adpater is NULL"));
1188 return NULL;
1189 }
1190
1191 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1192 if (0 != (wlan_hdd_validate_context(pHddCtx)))
c_hpothu7f63e882013-10-02 19:13:35 +05301193 {
c_hpothu7f63e882013-10-02 19:13:35 +05301194 return 0;
1195 }
Hoonki Leebfee0342013-01-21 16:43:45 -08001196
Hoonki Lee387663d2013-02-05 18:08:43 -08001197 /* if already there, just update */
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301198 peer = wlan_hdd_tdls_find_peer(pAdapter, mac, FALSE);
Hoonki Lee387663d2013-02-05 18:08:43 -08001199 if (peer != NULL)
1200 {
1201 return peer;
Chilam NG571c65a2013-01-19 12:27:36 +05301202 }
1203
Hoonki Lee387663d2013-02-05 18:08:43 -08001204 /* not found, allocate and add the list */
1205 peer = vos_mem_malloc(sizeof(hddTdlsPeer_t));
1206 if (NULL == peer) {
1207 hddLog(VOS_TRACE_LEVEL_ERROR, "%s peer malloc failed!", __func__);
1208 return NULL;
1209 }
Chilam NG571c65a2013-01-19 12:27:36 +05301210
Gopichand Nakkala4ddf0192013-03-27 13:41:20 -07001211 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
1212
1213 if (NULL == pHddTdlsCtx)
1214 {
1215 vos_mem_free(peer);
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05301216 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
1217 FL("pHddTdlsCtx is NULL"));
Gopichand Nakkala4ddf0192013-03-27 13:41:20 -07001218 return NULL;
1219 }
1220
1221 key = wlan_hdd_tdls_hash_key(mac);
1222 head = &pHddTdlsCtx->peer_list[key];
Chilam NG571c65a2013-01-19 12:27:36 +05301223
Hoonki Lee387663d2013-02-05 18:08:43 -08001224 vos_mem_zero(peer, sizeof(hddTdlsPeer_t));
1225 vos_mem_copy(peer->peerMac, mac, sizeof(peer->peerMac));
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001226 peer->pHddTdlsCtx = pHddTdlsCtx;
Hoonki Lee387663d2013-02-05 18:08:43 -08001227
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001228 vos_timer_init(&peer->peerIdleTimer,
1229 VOS_TIMER_TYPE_SW,
1230 wlan_hdd_tdls_idle_cb,
1231 peer);
1232
Hoonki Lee14621352013-04-16 17:51:19 -07001233 vos_timer_init(&peer->initiatorWaitTimeoutTimer,
1234 VOS_TIMER_TYPE_SW,
1235 wlan_hdd_tdls_initiator_wait_cb,
1236 peer);
1237
Hoonki Lee387663d2013-02-05 18:08:43 -08001238 list_add_tail(&peer->node, head);
Hoonki Lee387663d2013-02-05 18:08:43 -08001239
1240 return peer;
1241}
1242
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001243int wlan_hdd_tdls_set_cap(hdd_adapter_t *pAdapter,
Anand N Sunkad9bfc2622015-07-30 15:18:54 +05301244#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1245 const u8* mac,
1246#else
Hoonki Lee27511902013-03-14 18:19:06 -07001247 u8* mac,
Anand N Sunkad9bfc2622015-07-30 15:18:54 +05301248#endif
Hoonki Lee27511902013-03-14 18:19:06 -07001249 tTDLSCapType cap)
1250{
1251 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301252 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Lee27511902013-03-14 18:19:06 -07001253
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301254 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1255 return -EINVAL;
1256
1257 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001258 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee27511902013-03-14 18:19:06 -07001259 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301260 {
1261 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1262 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301263 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001264 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301265 }
Hoonki Lee27511902013-03-14 18:19:06 -07001266
1267 curr_peer->tdls_support = cap;
1268
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301269 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001270 return 0;
Hoonki Lee27511902013-03-14 18:19:06 -07001271}
1272
Atul Mittal115287b2014-07-08 13:26:33 +05301273void wlan_hdd_tdls_set_peer_link_status(hddTdlsPeer_t *curr_peer,
1274 tTDLSLinkStatus status,
1275 tTDLSLinkReason reason)
Hoonki Lee387663d2013-02-05 18:08:43 -08001276{
Atul Mittal115287b2014-07-08 13:26:33 +05301277 /*EXT TDLS*/
1278 tANI_S32 state = 0;
1279 tANI_S32 res = 0;
1280 /*EXT TDLS*/
Hoonki Lee387663d2013-02-05 18:08:43 -08001281 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301282 {
1283 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1284 "%s: curr_peer is NULL", __func__);
Hoonki Lee387663d2013-02-05 18:08:43 -08001285 return;
c_hpothu7f63e882013-10-02 19:13:35 +05301286 }
Hoonki Lee387663d2013-02-05 18:08:43 -08001287
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001288 hddLog(VOS_TRACE_LEVEL_WARN, "tdls set peer " MAC_ADDRESS_STR " link status to %u",
Chilam Ng01120412013-02-19 18:32:21 -08001289 MAC_ADDR_ARRAY(curr_peer->peerMac), status);
Chilam NG571c65a2013-01-19 12:27:36 +05301290
1291 curr_peer->link_status = status;
1292
Atul Mittal115287b2014-07-08 13:26:33 +05301293 /*EXT TDLS*/
1294 if (curr_peer->isForcedPeer && curr_peer->state_change_notification)
1295 {
1296 /*save the reason for any further query*/
1297 curr_peer->reason = reason;
1298 wlan_hdd_tdls_get_wifi_hal_state(curr_peer, &state, &res);
1299
1300 (curr_peer->state_change_notification)(
1301 curr_peer->peerMac,
1302 state,
1303 res,
1304 curr_peer->pHddTdlsCtx->pAdapter);
1305
1306 }
1307 /*EXT TDLS*/
1308
Chilam NG571c65a2013-01-19 12:27:36 +05301309}
1310
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001311void wlan_hdd_tdls_set_link_status(hdd_adapter_t *pAdapter,
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +05301312#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1313 const u8 *mac,
1314#else
1315 u8 *mac,
1316#endif
Atul Mittal115287b2014-07-08 13:26:33 +05301317 tTDLSLinkStatus linkStatus,
1318 tTDLSLinkReason reason)
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001319{
Atul Mittal115287b2014-07-08 13:26:33 +05301320
1321 /*EXT TDLS*/
1322 tANI_S32 state = 0;
1323 tANI_S32 res = 0;
1324 /*EXT TDLS*/
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001325 hddTdlsPeer_t *curr_peer;
1326
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301327 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001328 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301329 {
1330 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1331 "%s: curr_peer is NULL", __func__);
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001332 return;
c_hpothu7f63e882013-10-02 19:13:35 +05301333 }
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001334
1335 curr_peer->link_status= linkStatus;
1336
Atul Mittal115287b2014-07-08 13:26:33 +05301337 /*EXT TDLS*/
1338
1339 if (curr_peer->isForcedPeer && curr_peer->state_change_notification)
1340 {
1341 /*save the reason for any further query*/
1342 curr_peer->reason = reason;
1343 wlan_hdd_tdls_get_wifi_hal_state(curr_peer, &state, &res);
1344
1345 (*curr_peer->state_change_notification)(mac,
1346 state,
1347 res,
1348 curr_peer->pHddTdlsCtx->pAdapter);
1349
1350 }
1351 /*EXT TDLS*/
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001352 return;
1353}
1354
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001355int wlan_hdd_tdls_recv_discovery_resp(hdd_adapter_t *pAdapter, u8 *mac)
Chilam NG571c65a2013-01-19 12:27:36 +05301356{
1357 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001358 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301359 hdd_context_t *pHddCtx;
1360
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301361 ENTER();
1362
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301363 if ( NULL == pHddTdlsCtx )
c_hpothu7f63e882013-10-02 19:13:35 +05301364 {
1365 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05301366 FL("pHddTdlsCtx is NULL device mode = %d"), pAdapter->device_mode);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301367 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301368 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301369
1370 pHddCtx = WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter);
1371
c_hpothu7f63e882013-10-02 19:13:35 +05301372 if(0 != (wlan_hdd_validate_context(pHddCtx)))
1373 {
c_hpothu7f63e882013-10-02 19:13:35 +05301374 return 0;
1375 }
Chilam NG571c65a2013-01-19 12:27:36 +05301376
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301377 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001378 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001379
1380 if (NULL == curr_peer)
c_hpothu7f63e882013-10-02 19:13:35 +05301381 {
1382 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1383 FL("curr_peer is NULL"));
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301384 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001385 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301386 }
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301387 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001388
1389 if (pHddTdlsCtx->discovery_sent_cnt)
1390 pHddTdlsCtx->discovery_sent_cnt--;
1391
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301392 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301393
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001394 wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301395
1396 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001397 if (0 == pHddTdlsCtx->discovery_sent_cnt)
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07001398 {
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001399 vos_timer_stop(&pHddTdlsCtx->peerDiscoveryTimeoutTimer);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07001400 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001401
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301402 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001403 "Discovery(%u) Response from " MAC_ADDRESS_STR " link_status %d",
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001404 pHddTdlsCtx->discovery_sent_cnt, MAC_ADDR_ARRAY(curr_peer->peerMac),
1405 curr_peer->link_status);
1406
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001407 if (eTDLS_LINK_DISCOVERING == curr_peer->link_status)
Gopichand Nakkala901e8922013-03-04 23:45:58 -08001408 {
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001409 /* Since we are here, it means Throughput threshold is alredy met. Make sure RSSI
1410 threshold is also met before setting up TDLS link*/
1411 if ((tANI_S32) curr_peer->rssi > (tANI_S32) pHddTdlsCtx->threshold_config.rssi_trigger_threshold)
1412 {
Atul Mittal115287b2014-07-08 13:26:33 +05301413 wlan_hdd_tdls_set_peer_link_status(curr_peer,
1414 eTDLS_LINK_DISCOVERED,
1415 eTDLS_LINK_SUCCESS);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301416 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001417 "Rssi Threshold met: "MAC_ADDRESS_STR" rssi = %d threshold= %d" ,
1418 MAC_ADDR_ARRAY(curr_peer->peerMac), curr_peer->rssi,
1419 pHddTdlsCtx->threshold_config.rssi_trigger_threshold);
1420 cfg80211_tdls_oper_request(pAdapter->dev, curr_peer->peerMac, NL80211_TDLS_SETUP, FALSE, GFP_KERNEL);
1421 }
1422 else
1423 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301424 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001425 "Rssi Threshold not met: "MAC_ADDRESS_STR" rssi = %d threshold = %d ",
1426 MAC_ADDR_ARRAY(curr_peer->peerMac), curr_peer->rssi,
1427 pHddTdlsCtx->threshold_config.rssi_trigger_threshold);
Sunil Duttb0d39242014-09-10 23:54:51 +05301428
1429 /* if RSSI threshold is not met then allow further discovery
1430 * attempts by decrementing count for the last attempt
1431 */
1432 if (curr_peer->discovery_attempt)
1433 curr_peer->discovery_attempt--;
1434
Atul Mittal115287b2014-07-08 13:26:33 +05301435 wlan_hdd_tdls_set_peer_link_status(curr_peer,
1436 eTDLS_LINK_IDLE,
1437 eTDLS_LINK_UNSPECIFIED);
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001438 }
Gopichand Nakkala901e8922013-03-04 23:45:58 -08001439 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07001440 else
1441 {
1442 wlan_hdd_tdls_check_bmps(pAdapter);
1443 }
Chilam NG571c65a2013-01-19 12:27:36 +05301444
Gopichand Nakkala901e8922013-03-04 23:45:58 -08001445 curr_peer->tdls_support = eTDLS_CAP_SUPPORTED;
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301446 EXIT();
Hoonki Lee387663d2013-02-05 18:08:43 -08001447 return 0;
Chilam NG571c65a2013-01-19 12:27:36 +05301448}
1449
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301450int wlan_hdd_tdls_set_peer_caps(hdd_adapter_t *pAdapter,
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +05301451#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1452 const u8 *mac,
1453#else
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301454 u8 *mac,
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +05301455#endif
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301456 tCsrStaParams *StaParams,
1457 tANI_BOOLEAN isBufSta,
1458 tANI_BOOLEAN isOffChannelSupported)
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301459{
1460 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301461 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301462
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301463 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1464 return -EINVAL;
1465
1466 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301467 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
1468 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301469 {
1470 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1471 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301472 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301473 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301474 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301475
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301476 curr_peer->uapsdQueues = StaParams->uapsd_queues;
1477 curr_peer->maxSp = StaParams->max_sp;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301478 curr_peer->isBufSta = isBufSta;
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301479 curr_peer->isOffChannelSupported = isOffChannelSupported;
1480
1481 vos_mem_copy(curr_peer->supported_channels,
1482 StaParams->supported_channels,
1483 StaParams->supported_channels_len);
1484
1485 curr_peer->supported_channels_len =
1486 StaParams->supported_channels_len;
1487
1488 vos_mem_copy(curr_peer->supported_oper_classes,
1489 StaParams->supported_oper_classes,
1490 StaParams->supported_oper_classes_len);
1491
1492 curr_peer->supported_oper_classes_len =
1493 StaParams->supported_oper_classes_len;
Agarwal Ashish16020c42014-12-29 22:01:11 +05301494 curr_peer->qos = StaParams->capability & CAPABILITIES_QOS_OFFSET;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301495
1496 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301497 return 0;
1498}
1499
Anand N Sunkad9bfc2622015-07-30 15:18:54 +05301500int wlan_hdd_tdls_get_link_establish_params(hdd_adapter_t *pAdapter,
1501#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1502 const u8 *mac,
1503#else
1504 u8 *mac,
1505#endif
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301506 tCsrTdlsLinkEstablishParams* tdlsLinkEstablishParams)
1507{
1508 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301509 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301510
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301511 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1512 return -EINVAL;
1513
1514 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301515 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
1516 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301517 {
1518 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1519 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301520 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301521 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301522 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301523
1524 tdlsLinkEstablishParams->isResponder = curr_peer->is_responder;
1525 tdlsLinkEstablishParams->uapsdQueues = curr_peer->uapsdQueues;
1526 tdlsLinkEstablishParams->maxSp = curr_peer->maxSp;
1527 tdlsLinkEstablishParams->isBufSta = curr_peer->isBufSta;
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301528 tdlsLinkEstablishParams->isOffChannelSupported =
1529 curr_peer->isOffChannelSupported;
1530
1531 vos_mem_copy(tdlsLinkEstablishParams->supportedChannels,
1532 curr_peer->supported_channels,
1533 curr_peer->supported_channels_len);
1534
1535 tdlsLinkEstablishParams->supportedChannelsLen =
1536 curr_peer->supported_channels_len;
1537
1538 vos_mem_copy(tdlsLinkEstablishParams->supportedOperClasses,
1539 curr_peer->supported_oper_classes,
1540 curr_peer->supported_oper_classes_len);
1541
1542 tdlsLinkEstablishParams->supportedOperClassesLen =
1543 curr_peer->supported_oper_classes_len;
Agarwal Ashish16020c42014-12-29 22:01:11 +05301544 tdlsLinkEstablishParams->qos = curr_peer->qos;
1545
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301546 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301547 return 0;
1548}
1549
Anand N Sunkad9bfc2622015-07-30 15:18:54 +05301550int wlan_hdd_tdls_set_rssi(hdd_adapter_t *pAdapter,
1551#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1552 const u8 *mac,
1553#else
1554 u8 *mac,
1555#endif
1556 tANI_S8 rxRssi)
Chilam NG571c65a2013-01-19 12:27:36 +05301557{
1558 hddTdlsPeer_t *curr_peer;
Chilam NG571c65a2013-01-19 12:27:36 +05301559
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301560 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Hoonki Lee387663d2013-02-05 18:08:43 -08001561 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301562 {
1563 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1564 "%s: curr_peer is NULL", __func__);
Hoonki Lee387663d2013-02-05 18:08:43 -08001565 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301566 }
Chilam NG571c65a2013-01-19 12:27:36 +05301567
1568 curr_peer->rssi = rxRssi;
1569
Hoonki Lee387663d2013-02-05 18:08:43 -08001570 return 0;
Chilam NG571c65a2013-01-19 12:27:36 +05301571}
1572
Anand N Sunkad9bfc2622015-07-30 15:18:54 +05301573int wlan_hdd_tdls_set_responder(hdd_adapter_t *pAdapter,
1574#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1575 const u8 *mac,
1576#else
1577 u8 *mac,
1578#endif
1579 tANI_U8 responder)
Hoonki Leea34dd892013-02-05 22:56:02 -08001580{
1581 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301582 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Leea34dd892013-02-05 22:56:02 -08001583
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301584 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1585 return -EINVAL;
1586
1587 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001588 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001589 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301590 {
1591 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1592 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301593 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leea34dd892013-02-05 22:56:02 -08001594 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301595 }
Hoonki Leea34dd892013-02-05 22:56:02 -08001596
1597 curr_peer->is_responder = responder;
1598
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301599 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leea34dd892013-02-05 22:56:02 -08001600 return 0;
1601}
1602
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001603int wlan_hdd_tdls_get_responder(hdd_adapter_t *pAdapter, u8 *mac)
Hoonki Leea34dd892013-02-05 22:56:02 -08001604{
1605 hddTdlsPeer_t *curr_peer;
1606
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301607 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001608 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301609 {
1610 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1611 "%s: curr_peer is NULL", __func__);
Hoonki Leea34dd892013-02-05 22:56:02 -08001612 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301613 }
Hoonki Leea34dd892013-02-05 22:56:02 -08001614
1615 return (curr_peer->is_responder);
1616}
1617
Anand N Sunkad9bfc2622015-07-30 15:18:54 +05301618int wlan_hdd_tdls_set_signature(hdd_adapter_t *pAdapter,
1619#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1620 const u8 *mac,
1621#else
1622 u8 *mac,
1623#endif
1624 tANI_U8 uSignature)
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001625{
1626 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301627 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001628
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301629 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1630 return -EINVAL;
1631
1632 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001633 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001634 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301635 {
1636 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1637 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301638 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001639 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301640 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001641
1642 curr_peer->signature = uSignature;
1643
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301644 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001645 return 0;
1646}
1647
Hoonki Leea34dd892013-02-05 22:56:02 -08001648
Hoonki Lee387663d2013-02-05 18:08:43 -08001649void wlan_hdd_tdls_extract_da(struct sk_buff *skb, u8 *mac)
Chilam NG571c65a2013-01-19 12:27:36 +05301650{
Chilam NG571c65a2013-01-19 12:27:36 +05301651 memcpy(mac, skb->data, 6);
Chilam NG571c65a2013-01-19 12:27:36 +05301652}
1653
Hoonki Lee387663d2013-02-05 18:08:43 -08001654void wlan_hdd_tdls_extract_sa(struct sk_buff *skb, u8 *mac)
Chilam Ng1279e232013-01-25 15:06:52 -08001655{
Chilam Ng1279e232013-01-25 15:06:52 -08001656 memcpy(mac, skb->data+6, 6);
Chilam Ng1279e232013-01-25 15:06:52 -08001657}
1658
Anand N Sunkad9bfc2622015-07-30 15:18:54 +05301659int wlan_hdd_tdls_increment_pkt_count(hdd_adapter_t *pAdapter,
1660#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1661 const u8 *mac,
1662#else
1663 u8 *mac,
1664#endif
1665 u8 tx)
Chilam NG571c65a2013-01-19 12:27:36 +05301666{
Hoonki Lee387663d2013-02-05 18:08:43 -08001667 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001668 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Chilam NG571c65a2013-01-19 12:27:36 +05301669
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301670 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1671 return -EINVAL;
1672
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001673 if (eTDLS_SUPPORT_ENABLED != pHddCtx->tdls_mode)
1674 return -1;
Hoonki Leebfee0342013-01-21 16:43:45 -08001675
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301676 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001677 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee387663d2013-02-05 18:08:43 -08001678 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301679 {
c_hpothue21931b2014-09-08 14:02:14 +05301680 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
1681 FL("curr_peer is NULL"));
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301682 mutex_unlock(&pHddCtx->tdls_lock);
Chilam NG571c65a2013-01-19 12:27:36 +05301683 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301684 }
Chilam NG571c65a2013-01-19 12:27:36 +05301685
Chilam Ng1279e232013-01-25 15:06:52 -08001686 if (tx)
1687 curr_peer->tx_pkt++;
1688 else
1689 curr_peer->rx_pkt++;
Chilam NG571c65a2013-01-19 12:27:36 +05301690
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301691 mutex_unlock(&pHddCtx->tdls_lock);
Chilam NG571c65a2013-01-19 12:27:36 +05301692 return 0;
1693}
1694
Hoonki Lee27511902013-03-14 18:19:06 -07001695static int wlan_hdd_tdls_check_config(tdls_config_params_t *config)
1696{
1697 if (config->tdls > 2)
1698 {
1699 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 1st argument %d. <0...2>", __func__, config->tdls);
1700 return -1;
1701 }
1702 if (config->tx_period_t < CFG_TDLS_TX_STATS_PERIOD_MIN ||
1703 config->tx_period_t > CFG_TDLS_TX_STATS_PERIOD_MAX)
1704 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001705 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 2nd argument %d. <%d...%ld>", __func__, config->tx_period_t,
Hoonki Lee27511902013-03-14 18:19:06 -07001706 CFG_TDLS_TX_STATS_PERIOD_MIN, CFG_TDLS_TX_STATS_PERIOD_MAX);
1707 return -1;
1708 }
1709 if (config->tx_packet_n < CFG_TDLS_TX_PACKET_THRESHOLD_MIN ||
1710 config->tx_packet_n > CFG_TDLS_TX_PACKET_THRESHOLD_MAX)
1711 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001712 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 3rd argument %d. <%d...%ld>", __func__, config->tx_packet_n,
Hoonki Lee27511902013-03-14 18:19:06 -07001713 CFG_TDLS_TX_PACKET_THRESHOLD_MIN, CFG_TDLS_TX_PACKET_THRESHOLD_MAX);
1714 return -1;
1715 }
1716 if (config->discovery_period_t < CFG_TDLS_DISCOVERY_PERIOD_MIN ||
1717 config->discovery_period_t > CFG_TDLS_DISCOVERY_PERIOD_MAX)
1718 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001719 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 4th argument %d. <%d...%ld>", __func__, config->discovery_period_t,
Hoonki Lee27511902013-03-14 18:19:06 -07001720 CFG_TDLS_DISCOVERY_PERIOD_MIN, CFG_TDLS_DISCOVERY_PERIOD_MAX);
1721 return -1;
1722 }
1723 if (config->discovery_tries_n < CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MIN ||
1724 config->discovery_tries_n > CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MAX)
1725 {
1726 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 5th argument %d. <%d...%d>", __func__, config->discovery_tries_n,
1727 CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MIN, CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MAX);
1728 return -1;
1729 }
1730 if (config->idle_timeout_t < CFG_TDLS_IDLE_TIMEOUT_MIN ||
1731 config->idle_timeout_t > CFG_TDLS_IDLE_TIMEOUT_MAX)
1732 {
1733 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 6th argument %d. <%d...%d>", __func__, config->idle_timeout_t,
1734 CFG_TDLS_IDLE_TIMEOUT_MIN, CFG_TDLS_IDLE_TIMEOUT_MAX);
1735 return -1;
1736 }
1737 if (config->idle_packet_n < CFG_TDLS_IDLE_PACKET_THRESHOLD_MIN ||
1738 config->idle_packet_n > CFG_TDLS_IDLE_PACKET_THRESHOLD_MAX)
1739 {
1740 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 7th argument %d. <%d...%d>", __func__, config->idle_packet_n,
1741 CFG_TDLS_IDLE_PACKET_THRESHOLD_MIN, CFG_TDLS_IDLE_PACKET_THRESHOLD_MAX);
1742 return -1;
1743 }
1744 if (config->rssi_hysteresis < CFG_TDLS_RSSI_HYSTERESIS_MIN ||
1745 config->rssi_hysteresis > CFG_TDLS_RSSI_HYSTERESIS_MAX)
1746 {
1747 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 8th argument %d. <%d...%d>", __func__, config->rssi_hysteresis,
1748 CFG_TDLS_RSSI_HYSTERESIS_MIN, CFG_TDLS_RSSI_HYSTERESIS_MAX);
1749 return -1;
1750 }
1751 if (config->rssi_trigger_threshold < CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MIN ||
1752 config->rssi_trigger_threshold > CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MAX)
1753 {
1754 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 9th argument %d. <%d...%d>", __func__, config->rssi_trigger_threshold,
1755 CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MIN, CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MAX);
1756 return -1;
1757 }
1758 if (config->rssi_teardown_threshold < CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MIN ||
1759 config->rssi_teardown_threshold > CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MAX)
1760 {
1761 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 10th argument %d. <%d...%d>", __func__, config->rssi_teardown_threshold,
1762 CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MIN, CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MAX);
1763 return -1;
1764 }
1765 return 0;
1766}
1767
Chilam Ng01120412013-02-19 18:32:21 -08001768int wlan_hdd_tdls_set_params(struct net_device *dev, tdls_config_params_t *config)
Chilam NG571c65a2013-01-19 12:27:36 +05301769{
Chilam Ng01120412013-02-19 18:32:21 -08001770 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
1771 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001772 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Hoonki Lee27511902013-03-14 18:19:06 -07001773 eTDLSSupportMode req_tdls_mode;
Hoonki Leebfee0342013-01-21 16:43:45 -08001774
Hoonki Lee27511902013-03-14 18:19:06 -07001775 if (NULL == pHddTdlsCtx)
1776 {
c_hpothu7f63e882013-10-02 19:13:35 +05301777 hddLog(VOS_TRACE_LEVEL_ERROR, FL("TDLS not enabled!"));
Hoonki Lee27511902013-03-14 18:19:06 -07001778 return -1;
Chilam Ng01120412013-02-19 18:32:21 -08001779 }
Chilam NG571c65a2013-01-19 12:27:36 +05301780
Hoonki Lee27511902013-03-14 18:19:06 -07001781 if (wlan_hdd_tdls_check_config(config) != 0)
1782 {
1783 return -1;
1784 }
1785
1786 /* config->tdls is mapped to 0->1, 1->2, 2->3 */
1787 req_tdls_mode = config->tdls + 1;
1788 if (pHddCtx->tdls_mode == req_tdls_mode)
1789 {
1790 hddLog(VOS_TRACE_LEVEL_ERROR, "%s already in mode %d", __func__, config->tdls);
1791 return -1;
1792 }
1793
1794 /* copy the configuration only when given tdls mode is implicit trigger enable */
1795 if (eTDLS_SUPPORT_ENABLED == req_tdls_mode)
1796 {
Chilam Ng01120412013-02-19 18:32:21 -08001797 memcpy(&pHddTdlsCtx->threshold_config, config, sizeof(tdls_config_params_t));
1798 }
Chilam NG571c65a2013-01-19 12:27:36 +05301799
Chilam Ng01120412013-02-19 18:32:21 -08001800 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1801 "iw set tdls params: %d %d %d %d %d %d %d %d %d %d",
1802 config->tdls,
1803 config->tx_period_t,
1804 config->tx_packet_n,
1805 config->discovery_period_t,
1806 config->discovery_tries_n,
1807 config->idle_timeout_t,
1808 config->idle_packet_n,
1809 config->rssi_hysteresis,
1810 config->rssi_trigger_threshold,
1811 config->rssi_teardown_threshold);
Chilam NG571c65a2013-01-19 12:27:36 +05301812
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07001813 wlan_hdd_tdls_set_mode(pHddCtx, req_tdls_mode, TRUE);
Chilam Ng01120412013-02-19 18:32:21 -08001814
Chilam NG571c65a2013-01-19 12:27:36 +05301815 return 0;
1816}
1817
Anand N Sunkad9bfc2622015-07-30 15:18:54 +05301818int wlan_hdd_tdls_set_sta_id(hdd_adapter_t *pAdapter,
1819#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1820 const u8 *mac,
1821#else
1822 u8 *mac,
1823#endif
1824 u8 staId)
Kiran V1ccee932012-12-12 14:49:46 -08001825{
Hoonki Lee387663d2013-02-05 18:08:43 -08001826 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301827 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kiran V1ccee932012-12-12 14:49:46 -08001828
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301829 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1830 return -EINVAL;
1831
1832 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001833 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee387663d2013-02-05 18:08:43 -08001834 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301835 {
1836 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1837 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301838 mutex_unlock(&pHddCtx->tdls_lock);
Chilam NG571c65a2013-01-19 12:27:36 +05301839 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301840 }
Chilam NG571c65a2013-01-19 12:27:36 +05301841
Hoonki Lee387663d2013-02-05 18:08:43 -08001842 curr_peer->staId = staId;
Chilam NG571c65a2013-01-19 12:27:36 +05301843
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301844 mutex_unlock(&pHddCtx->tdls_lock);
Chilam NG571c65a2013-01-19 12:27:36 +05301845 return 0;
Kiran V1ccee932012-12-12 14:49:46 -08001846}
1847
Anand N Sunkad9bfc2622015-07-30 15:18:54 +05301848int wlan_hdd_tdls_set_force_peer(hdd_adapter_t *pAdapter,
1849#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1850 const u8 *mac,
1851#else
1852 u8 *mac,
1853#endif
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301854 tANI_BOOLEAN forcePeer)
Sunil Dutt41de4e22013-11-14 18:09:02 +05301855{
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301856 hddTdlsPeer_t *curr_peer;
Sunil Dutt41de4e22013-11-14 18:09:02 +05301857 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1858
1859 if ((NULL == pHddCtx)) return -1;
1860
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301861 mutex_lock(&pHddCtx->tdls_lock);
1862
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301863 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, FALSE);
1864 if (curr_peer == NULL)
Sunil Dutt41de4e22013-11-14 18:09:02 +05301865 goto error;
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301866 curr_peer->isForcedPeer = forcePeer;
Naresh Jayaramca7bc3a2014-02-04 23:03:04 +05301867
1868 mutex_unlock(&pHddCtx->tdls_lock);
1869 return 0;
Sunil Dutt41de4e22013-11-14 18:09:02 +05301870error:
1871 mutex_unlock(&pHddCtx->tdls_lock);
1872 return -1;
1873}
1874
Hoonki Lee387663d2013-02-05 18:08:43 -08001875/* if peerMac is found, then it returns pointer to hddTdlsPeer_t
1876 otherwise, it returns NULL
1877*/
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +05301878hddTdlsPeer_t *wlan_hdd_tdls_find_peer(hdd_adapter_t *pAdapter,
1879#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1880 const u8 *mac,
1881#else
1882 u8 *mac,
1883#endif
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301884 tANI_BOOLEAN mutexLock)
Kiran V1ccee932012-12-12 14:49:46 -08001885{
Hoonki Lee387663d2013-02-05 18:08:43 -08001886 u8 key;
1887 struct list_head *pos;
1888 struct list_head *head;
1889 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001890 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301891 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Lee387663d2013-02-05 18:08:43 -08001892
c_hpothu7f63e882013-10-02 19:13:35 +05301893 if(0 != (wlan_hdd_validate_context(pHddCtx)))
1894 {
c_hpothu7f63e882013-10-02 19:13:35 +05301895 return 0;
1896 }
Hoonki Lee387663d2013-02-05 18:08:43 -08001897
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301898 if ( mutexLock )
Hoonki Lee387663d2013-02-05 18:08:43 -08001899 {
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301900 mutex_lock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001901 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001902 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08001903 if (NULL == pHddTdlsCtx)
1904 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301905 if ( mutexLock )
1906 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08001907 return NULL;
1908 }
1909
1910 key = wlan_hdd_tdls_hash_key(mac);
1911
1912 head = &pHddTdlsCtx->peer_list[key];
Hoonki Lee387663d2013-02-05 18:08:43 -08001913
1914 list_for_each(pos, head) {
1915 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
1916 if (!memcmp(mac, curr_peer->peerMac, 6)) {
1917 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
1918 "findTdlsPeer: found staId %d", curr_peer->staId);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301919 if ( mutexLock )
1920 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001921 return curr_peer;
1922 }
1923 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301924 if ( mutexLock )
1925 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301926
Hoonki Lee387663d2013-02-05 18:08:43 -08001927 return NULL;
1928}
1929
Anand N Sunkad9bfc2622015-07-30 15:18:54 +05301930hddTdlsPeer_t *wlan_hdd_tdls_find_all_peer(hdd_context_t *pHddCtx,
1931#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1932 const u8 *mac
1933#else
1934 u8 *mac
1935#endif
1936)
Hoonki Leea6d49be2013-04-05 09:43:25 -07001937{
1938 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
1939 hdd_adapter_t *pAdapter = NULL;
1940 tdlsCtx_t *pHddTdlsCtx = NULL;
1941 hddTdlsPeer_t *curr_peer= NULL;
1942 VOS_STATUS status = 0;
1943
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301944 mutex_lock(&pHddCtx->tdls_lock);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001945 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
1946 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
1947 {
1948 pAdapter = pAdapterNode->pAdapter;
1949
1950 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
1951 if (NULL != pHddTdlsCtx)
1952 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301953 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, FALSE);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001954 if (curr_peer)
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301955 {
1956 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001957 return curr_peer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301958 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07001959 }
1960 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
1961 pAdapterNode = pNext;
1962 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301963 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001964 return curr_peer;
1965}
1966
1967
Anand N Sunkad9bfc2622015-07-30 15:18:54 +05301968int wlan_hdd_tdls_reset_peer(hdd_adapter_t *pAdapter,
1969#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1970 const u8 *mac
1971#else
1972 u8 *mac
1973#endif
1974)
Hoonki Lee387663d2013-02-05 18:08:43 -08001975{
Chilam Ng01120412013-02-19 18:32:21 -08001976 hdd_context_t *pHddCtx;
Chilam NG571c65a2013-01-19 12:27:36 +05301977 hddTdlsPeer_t *curr_peer;
Kiran V1ccee932012-12-12 14:49:46 -08001978
Chilam Ng01120412013-02-19 18:32:21 -08001979 pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
1980
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301981 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1982 return -EINVAL;
1983
1984 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001985 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee387663d2013-02-05 18:08:43 -08001986 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301987 {
1988 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1989 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301990 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001991 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301992 }
Chilam NG571c65a2013-01-19 12:27:36 +05301993
Atul Mittal115287b2014-07-08 13:26:33 +05301994 wlan_hdd_tdls_set_peer_link_status(curr_peer,
1995 eTDLS_LINK_IDLE,
1996 eTDLS_LINK_UNSPECIFIED);
Hoonki Leecdd8e962013-01-20 00:45:46 -08001997 curr_peer->staId = 0;
Hoonki Lee387663d2013-02-05 18:08:43 -08001998
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05301999 /* Throughput Monitor shall disable the split scan when
2000 * TDLS scan coexistance is disabled.At this point of time
2001 * since TDLS scan coexistance is not meeting the criteria
2002 * to be operational, explicitly make it false to enable
2003 * throughput monitor takes the control of split scan.
2004 */
2005 if (pHddCtx->isTdlsScanCoexistence == TRUE)
2006 {
2007 pHddCtx->isTdlsScanCoexistence = FALSE;
2008 }
2009
Chilam Ng01120412013-02-19 18:32:21 -08002010 if(eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode) {
Chilam Nga75d8b62013-01-29 01:35:59 -08002011 vos_timer_stop( &curr_peer->peerIdleTimer );
Chilam Nga75d8b62013-01-29 01:35:59 -08002012 }
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05302013
2014 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08002015 return 0;
Hoonki Leecdd8e962013-01-20 00:45:46 -08002016}
2017
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07002018/* Caller has to take the lock before calling this function */
Hoonki Lee27511902013-03-14 18:19:06 -07002019static void wlan_tdd_tdls_reset_tx_rx(tdlsCtx_t *pHddTdlsCtx)
2020{
2021 int i;
2022 struct list_head *head;
2023 hddTdlsPeer_t *tmp;
2024 struct list_head *pos, *q;
2025
Hoonki Lee27511902013-03-14 18:19:06 -07002026 for (i = 0; i < 256; i++) {
2027 head = &pHddTdlsCtx->peer_list[i];
2028 list_for_each_safe (pos, q, head) {
2029 tmp = list_entry(pos, hddTdlsPeer_t, node);
2030 tmp->tx_pkt = 0;
2031 tmp->rx_pkt = 0;
2032 }
2033 }
Hoonki Lee27511902013-03-14 18:19:06 -07002034
2035 return ;
2036}
2037
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07002038/* Caller has to take the lock before calling this function */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002039static tANI_S32 wlan_hdd_tdls_peer_reset_discovery_processed(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002040{
2041 int i;
2042 struct list_head *head;
2043 hddTdlsPeer_t *tmp;
2044 struct list_head *pos, *q;
2045
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002046 pHddTdlsCtx->discovery_peer_cnt = 0;
2047
2048 for (i = 0; i < 256; i++) {
2049 head = &pHddTdlsCtx->peer_list[i];
2050 list_for_each_safe (pos, q, head) {
2051 tmp = list_entry(pos, hddTdlsPeer_t, node);
2052 tmp->discovery_processed = 0;
2053 }
2054 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002055
2056 return 0;
2057}
2058
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002059static tANI_S32 wlan_hdd_get_tdls_discovery_peer_cnt(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002060{
2061 int i;
2062 struct list_head *head;
2063 struct list_head *pos, *q;
2064 int discovery_peer_cnt=0;
2065 hddTdlsPeer_t *tmp;
2066
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002067 /*
2068 * This function expects the callers to acquire the Mutex.
2069 */
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002070
2071 for (i = 0; i < 256; i++) {
2072 head = &pHddTdlsCtx->peer_list[i];
2073 list_for_each_safe (pos, q, head) {
2074 tmp = list_entry(pos, hddTdlsPeer_t, node);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302075 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Chilam Ng01120412013-02-19 18:32:21 -08002076 "%s, %d, " MAC_ADDRESS_STR, __func__, i,
2077 MAC_ADDR_ARRAY(tmp->peerMac));
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002078 discovery_peer_cnt++;
2079 }
2080 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002081 return discovery_peer_cnt;
2082}
2083
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002084tANI_U16 wlan_hdd_tdlsConnectedPeers(hdd_adapter_t *pAdapter)
Lee Hoonkic1262f22013-01-24 21:59:00 -08002085{
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302086 hdd_context_t *pHddCtx = NULL;
2087
2088 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
2089 {
2090 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2091 FL("invalid pAdapter: %p"), pAdapter);
2092 return 0;
2093 }
2094 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002095
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302096 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302097 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2098 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002099 return 0;
c_hpothu7f63e882013-10-02 19:13:35 +05302100 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302101 EXIT();
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002102 return pHddCtx->connected_peer_count;
Lee Hoonkic1262f22013-01-24 21:59:00 -08002103}
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002104
Pradeep Reddy POTTETIe309c152015-02-06 13:21:07 +05302105hddTdlsPeer_t *wlan_hdd_tdls_get_connected_peer(hdd_adapter_t *pAdapter)
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302106{
2107 int i;
2108 struct list_head *head;
2109 struct list_head *pos;
2110 hddTdlsPeer_t *curr_peer = NULL;
2111 tdlsCtx_t *pHddTdlsCtx;
2112 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2113
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302114 ENTER();
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302115 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2116 {
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302117 return NULL;
2118 }
2119
2120 mutex_lock(&pHddCtx->tdls_lock);
2121 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2122 if (NULL == pHddTdlsCtx) {
2123 mutex_unlock(&pHddCtx->tdls_lock);
2124 return NULL;
2125 }
2126 for (i = 0; i < 256; i++) {
2127 head = &pHddTdlsCtx->peer_list[i];
2128
2129 list_for_each(pos, head) {
2130 curr_peer= list_entry (pos, hddTdlsPeer_t, node);
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05302131 if (curr_peer && (curr_peer->link_status == eTDLS_LINK_CONNECTED))
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302132 {
2133 mutex_unlock(&pHddCtx->tdls_lock);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302134 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05302135 "%s: " MAC_ADDRESS_STR " eTDLS_LINK_CONNECTED",
2136 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302137 return curr_peer;
2138 }
2139 }
2140 }
2141 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302142
2143 EXIT();
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302144 return NULL;
2145}
2146
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002147int wlan_hdd_tdls_get_all_peers(hdd_adapter_t *pAdapter, char *buf, int buflen)
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002148{
2149 int i;
2150 int len, init_len;
Hoonki Lee387663d2013-02-05 18:08:43 -08002151 struct list_head *head;
2152 struct list_head *pos;
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002153 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002154 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302155 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2156
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302157 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302158 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2159 {
c_hpothu7f63e882013-10-02 19:13:35 +05302160 return 0;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302161 }
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002162
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002163 init_len = buflen;
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002164 len = scnprintf(buf, buflen, "\n%-18s%-3s%-4s%-3s%-5s\n",
2165 "MAC", "Id", "cap", "up", "RSSI");
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002166 buf += len;
2167 buflen -= len;
2168 /* 1234567890123456789012345678901234567 */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002169 len = scnprintf(buf, buflen, "---------------------------------\n");
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002170 buf += len;
2171 buflen -= len;
2172
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302173 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002174 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002175 if (NULL == pHddTdlsCtx) {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302176 mutex_unlock(&pHddCtx->tdls_lock);
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002177 len = scnprintf(buf, buflen, "TDLS not enabled\n");
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002178 return len;
2179 }
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002180 for (i = 0; i < 256; i++) {
Hoonki Lee387663d2013-02-05 18:08:43 -08002181 head = &pHddTdlsCtx->peer_list[i];
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002182
Hoonki Lee387663d2013-02-05 18:08:43 -08002183 list_for_each(pos, head) {
2184 curr_peer= list_entry (pos, hddTdlsPeer_t, node);
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002185
Hoonki Lee387663d2013-02-05 18:08:43 -08002186 if (buflen < 32+1)
2187 break;
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002188 len = scnprintf(buf, buflen,
Chilam Ng01120412013-02-19 18:32:21 -08002189 MAC_ADDRESS_STR"%3d%4s%3s%5d\n",
2190 MAC_ADDR_ARRAY(curr_peer->peerMac),
Hoonki Lee387663d2013-02-05 18:08:43 -08002191 curr_peer->staId,
2192 (curr_peer->tdls_support == eTDLS_CAP_SUPPORTED) ? "Y":"N",
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002193 TDLS_IS_CONNECTED(curr_peer) ? "Y":"N",
Hoonki Lee387663d2013-02-05 18:08:43 -08002194 curr_peer->rssi);
2195 buf += len;
2196 buflen -= len;
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002197 }
2198 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302199 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302200
2201 EXIT();
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002202 return init_len-buflen;
2203}
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002204
2205void wlan_hdd_tdls_connection_callback(hdd_adapter_t *pAdapter)
2206{
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302207 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302208 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala9d76a9b2013-02-28 15:38:37 -08002209
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302210 if ((NULL == pHddCtx))
c_hpothu7f63e882013-10-02 19:13:35 +05302211 {
Agarwal Ashishbf98caf2014-03-25 13:29:11 +05302212 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
2213 FL("pHddCtx or pHddTdlsCtx points to NULL"));
c_hpothu7f63e882013-10-02 19:13:35 +05302214 return;
2215 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302216
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302217 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07002218
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302219 if (0 != wlan_hdd_sta_tdls_init(pAdapter))
2220 {
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302221 mutex_unlock(&pHddCtx->tdls_lock);
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302222 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wlan_hdd_sta_tdls_init failed",__func__);
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302223 return;
2224 }
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302225
2226 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2227 if ((NULL == pHddTdlsCtx))
2228 {
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302229 mutex_unlock(&pHddCtx->tdls_lock);
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302230 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
2231 FL("pHddCtx or pHddTdlsCtx points to NULL device mode = %d"), pAdapter->device_mode);
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302232 return;
2233 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302234 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002235 "%s, update %d discover %d", __func__,
2236 pHddTdlsCtx->threshold_config.tx_period_t,
2237 pHddTdlsCtx->threshold_config.discovery_period_t);
2238
Gopichand Nakkala9d76a9b2013-02-28 15:38:37 -08002239 if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode)
2240 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002241 wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002242 pHddTdlsCtx->discovery_sent_cnt = 0;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002243 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002244
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002245 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2246 &pHddTdlsCtx->peerUpdateTimer,
2247 pHddTdlsCtx->threshold_config.tx_period_t);
Gopichand Nakkala9d76a9b2013-02-28 15:38:37 -08002248 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302249 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002250
2251}
2252
2253void wlan_hdd_tdls_disconnection_callback(hdd_adapter_t *pAdapter)
2254{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002255 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302256 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2257
Deepthi Gowribfd17132014-11-14 17:59:04 +05302258 if (NULL == pHddCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302259 {
2260 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Deepthi Gowribfd17132014-11-14 17:59:04 +05302261 FL(" pHddCtx points to NULL"));
c_hpothu7f63e882013-10-02 19:13:35 +05302262 return;
2263 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002264
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302265 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"%s", __func__);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002266
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002267 if (NULL == pHddTdlsCtx)
2268 {
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302269 mutex_unlock(&pHddCtx->tdls_lock);
Ratheesh S P36dbc932015-08-07 14:28:57 +05302270 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
c_hpothu7f63e882013-10-02 19:13:35 +05302271 FL("pHddTdlsCtx is NULL"));
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002272 return;
2273 }
Masti, Narayanraddide96b992015-01-08 13:00:58 +05302274
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +05302275 mutex_lock(&pHddCtx->tdls_lock);
Masti, Narayanraddide96b992015-01-08 13:00:58 +05302276
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002277 pHddTdlsCtx->discovery_sent_cnt = 0;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002278 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002279
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +05302280 wlan_hdd_tdls_exit(pAdapter, TRUE);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002281
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302282 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002283}
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002284
2285void wlan_hdd_tdls_mgmt_completion_callback(hdd_adapter_t *pAdapter, tANI_U32 statusCode)
2286{
2287 pAdapter->mgmtTxCompletionStatus = statusCode;
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302288 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2289 "%s: Mgmt TX Completion %d",__func__, statusCode);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002290 complete(&pAdapter->tdls_mgmt_comp);
2291}
2292
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002293void wlan_hdd_tdls_increment_peer_count(hdd_adapter_t *pAdapter)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002294{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002295 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002296
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302297 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302298 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2299 {
c_hpothu7f63e882013-10-02 19:13:35 +05302300 return;
2301 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002302
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302303 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302304
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002305 pHddCtx->connected_peer_count++;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002306 wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002307
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302308 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: %d",
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002309 __func__, pHddCtx->connected_peer_count);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302310
2311 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302312
2313 EXIT();
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002314}
2315
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002316void wlan_hdd_tdls_decrement_peer_count(hdd_adapter_t *pAdapter)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002317{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002318 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002319
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302320 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302321 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2322 {
c_hpothu7f63e882013-10-02 19:13:35 +05302323 return;
2324 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002325
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302326 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302327
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002328 if (pHddCtx->connected_peer_count)
2329 pHddCtx->connected_peer_count--;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002330 wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002331
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302332 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: %d",
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002333 __func__, pHddCtx->connected_peer_count);
2334
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302335 mutex_unlock(&pHddCtx->tdls_lock);
2336
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302337 EXIT();
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002338}
2339
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002340void wlan_hdd_tdls_check_bmps(hdd_adapter_t *pAdapter)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002341{
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302342
2343 tdlsCtx_t *pHddTdlsCtx = NULL;
2344 hdd_context_t *pHddCtx = NULL;
Hoonki Lee14621352013-04-16 17:51:19 -07002345 hddTdlsPeer_t *curr_peer;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002346
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302347 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
2348 {
2349 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2350 FL("invalid pAdapter: %p"), pAdapter);
2351 return;
2352 }
2353
2354 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2355 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2356
c_hpothu7f63e882013-10-02 19:13:35 +05302357 if ((NULL == pHddCtx) || (NULL == pHddTdlsCtx))
2358 {
Sushant Kaushik125ae692014-11-25 17:38:48 +05302359 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
c_hpothu7f63e882013-10-02 19:13:35 +05302360 FL(" pHddCtx or pHddTdlsCtx points to NULL"));
2361 return;
2362 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002363
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302364 curr_peer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, TRUE);
Hoonki Lee14621352013-04-16 17:51:19 -07002365 if (NULL != curr_peer)
2366 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302367 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee14621352013-04-16 17:51:19 -07002368 "%s: tdls in progress. Dont check for BMPS " MAC_ADDRESS_STR,
2369 __func__, MAC_ADDR_ARRAY (curr_peer->peerMac));
2370 return;
2371 }
2372
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002373 if ((TDLS_CTX_MAGIC != pHddCtx->tdls_scan_ctxt.magic) &&
2374 (0 == pHddCtx->connected_peer_count) &&
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002375 (0 == pHddTdlsCtx->discovery_sent_cnt))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002376 {
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002377 if (FALSE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
2378 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302379 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002380 "%s: No TDLS peer connected/discovery sent. Enable BMPS",
2381 __func__);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002382 hdd_enable_bmps_imps(pHddCtx);
2383 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002384 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002385 else
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002386 {
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002387 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
2388 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302389 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002390 "%s: TDLS peer connected. Disable BMPS", __func__);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002391 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
2392 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002393 }
2394 return;
2395}
2396
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002397u8 wlan_hdd_tdls_is_peer_progress(hdd_adapter_t *pAdapter, u8 *mac)
2398{
2399 hddTdlsPeer_t *curr_peer;
2400
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302401 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002402 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05302403 {
2404 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2405 "%s: curr_peer is NULL", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002406 return 0;
c_hpothu7f63e882013-10-02 19:13:35 +05302407 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002408
2409 return (eTDLS_LINK_CONNECTING == curr_peer->link_status);
2410}
2411
Hoonki Leefb8df672013-04-10 18:20:34 -07002412/* return pointer to hddTdlsPeer_t if TDLS is ongoing. Otherwise return NULL.
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002413 * mac - if NULL check for all the peer list, otherwise, skip this mac when skip_self is TRUE
2414 * skip_self - if TRUE, skip this mac. otherwise, check all the peer list. if
2415 mac is NULL, this argument is ignored, and check for all the peer list.
2416 */
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +05302417static hddTdlsPeer_t *wlan_hdd_tdls_find_progress_peer(hdd_adapter_t *pAdapter,
2418#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
2419 const u8 *mac,
2420#else
2421 u8 *mac,
2422#endif
2423 u8 skip_self)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002424{
2425 int i;
2426 struct list_head *head;
2427 hddTdlsPeer_t *curr_peer;
2428 struct list_head *pos;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302429 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302430
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302431 if (NULL == pHddTdlsCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302432 {
Ratheesh S P36dbc932015-08-07 14:28:57 +05302433 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
c_hpothu7f63e882013-10-02 19:13:35 +05302434 FL("pHddTdlsCtx is NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302435 return NULL;
c_hpothu7f63e882013-10-02 19:13:35 +05302436 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302437
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002438 for (i = 0; i < 256; i++) {
2439 head = &pHddTdlsCtx->peer_list[i];
2440 list_for_each(pos, head) {
2441 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
2442 if (skip_self && mac && !memcmp(mac, curr_peer->peerMac, 6)) {
2443 continue;
2444 }
2445 else
2446 {
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08002447 if (eTDLS_LINK_CONNECTING == curr_peer->link_status)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002448 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302449 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002450 "%s:" MAC_ADDRESS_STR " eTDLS_LINK_CONNECTING",
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002451 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
Hoonki Leefb8df672013-04-10 18:20:34 -07002452 return curr_peer;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002453 }
2454 }
2455 }
2456 }
Hoonki Leefb8df672013-04-10 18:20:34 -07002457 return NULL;
2458}
2459
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +05302460hddTdlsPeer_t *wlan_hdd_tdls_is_progress(hdd_context_t *pHddCtx,
2461#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
2462 const u8 *mac,
2463#else
2464 u8 *mac,
2465#endif
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302466 u8 skip_self, tANI_BOOLEAN mutexLock)
Hoonki Leefb8df672013-04-10 18:20:34 -07002467{
2468 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2469 hdd_adapter_t *pAdapter = NULL;
2470 tdlsCtx_t *pHddTdlsCtx = NULL;
2471 hddTdlsPeer_t *curr_peer= NULL;
2472 VOS_STATUS status = 0;
2473
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302474 if (mutexLock)
2475 {
2476 mutex_lock(&pHddCtx->tdls_lock);
2477 }
Hoonki Leefb8df672013-04-10 18:20:34 -07002478 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2479 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2480 {
2481 pAdapter = pAdapterNode->pAdapter;
2482
2483 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2484 if (NULL != pHddTdlsCtx)
2485 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302486 curr_peer = wlan_hdd_tdls_find_progress_peer(pAdapter, mac, skip_self);
Hoonki Leefb8df672013-04-10 18:20:34 -07002487 if (curr_peer)
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302488 {
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302489 if (mutexLock)
2490 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leefb8df672013-04-10 18:20:34 -07002491 return curr_peer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302492 }
Hoonki Leefb8df672013-04-10 18:20:34 -07002493 }
2494 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2495 pAdapterNode = pNext;
2496 }
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302497 if (mutexLock)
2498 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leefb8df672013-04-10 18:20:34 -07002499 return NULL;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002500}
Hoonki Lee27511902013-03-14 18:19:06 -07002501
2502static void wlan_hdd_tdls_implicit_disable(tdlsCtx_t *pHddTdlsCtx)
2503{
Hoonki Lee27511902013-03-14 18:19:06 -07002504 wlan_hdd_tdls_timers_stop(pHddTdlsCtx);
Hoonki Lee27511902013-03-14 18:19:06 -07002505}
2506
2507static void wlan_hdd_tdls_implicit_enable(tdlsCtx_t *pHddTdlsCtx)
2508{
2509 wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002510 pHddTdlsCtx->discovery_sent_cnt = 0;
Hoonki Lee27511902013-03-14 18:19:06 -07002511 wlan_tdd_tdls_reset_tx_rx(pHddTdlsCtx);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002512 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002513
Hoonki Lee27511902013-03-14 18:19:06 -07002514
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002515 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2516 &pHddTdlsCtx->peerUpdateTimer,
2517 pHddTdlsCtx->threshold_config.tx_period_t);
Hoonki Lee27511902013-03-14 18:19:06 -07002518}
2519
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002520void wlan_hdd_tdls_set_mode(hdd_context_t *pHddCtx,
2521 eTDLSSupportMode tdls_mode,
2522 v_BOOL_t bUpdateLast)
Hoonki Lee27511902013-03-14 18:19:06 -07002523{
2524 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2525 VOS_STATUS status;
2526 hdd_adapter_t *pAdapter;
2527 tdlsCtx_t *pHddTdlsCtx;
2528
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302529 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2530 "%s mode %d", __func__, (int)tdls_mode);
c_hpothu7f63e882013-10-02 19:13:35 +05302531
2532 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2533 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302534 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302535 }
Hoonki Lee27511902013-03-14 18:19:06 -07002536
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302537 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07002538
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002539 if (pHddCtx->tdls_mode == tdls_mode)
2540 {
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302541 mutex_unlock(&pHddCtx->tdls_lock);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302542 hddLog(VOS_TRACE_LEVEL_INFO, "%s already in mode %d", __func__,
2543 (int)tdls_mode);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002544 return;
2545 }
2546
Hoonki Lee27511902013-03-14 18:19:06 -07002547 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2548
2549 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2550 {
2551 pAdapter = pAdapterNode->pAdapter;
Hoonki Leea6d49be2013-04-05 09:43:25 -07002552 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2553 if (NULL != pHddTdlsCtx)
Hoonki Lee27511902013-03-14 18:19:06 -07002554 {
Hoonki Leea6d49be2013-04-05 09:43:25 -07002555 if(eTDLS_SUPPORT_ENABLED == tdls_mode)
2556 wlan_hdd_tdls_implicit_enable(pHddTdlsCtx);
2557 else if((eTDLS_SUPPORT_DISABLED == tdls_mode) ||
2558 (eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == tdls_mode))
2559 wlan_hdd_tdls_implicit_disable(pHddTdlsCtx);
Hoonki Lee27511902013-03-14 18:19:06 -07002560 }
2561 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2562 pAdapterNode = pNext;
2563 }
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002564 if(bUpdateLast)
2565 {
2566 pHddCtx->tdls_mode_last = tdls_mode;
2567 }
2568 else
2569 {
2570 pHddCtx->tdls_mode_last = pHddCtx->tdls_mode;
2571 }
Hoonki Lee27511902013-03-14 18:19:06 -07002572 pHddCtx->tdls_mode = tdls_mode;
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002573
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302574 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302575
Hoonki Lee27511902013-03-14 18:19:06 -07002576}
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002577
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302578static
2579void wlan_hdd_tdls_implicit_send_discovery_request(tdlsCtx_t * pHddTdlsCtx)
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002580{
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302581 hdd_context_t *pHddCtx = NULL;
2582 hddTdlsPeer_t *curr_peer = NULL, *temp_peer = NULL;
Hoonki Leed37cbb32013-04-20 00:31:14 -07002583
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302584 ENTER();
Hoonki Leed37cbb32013-04-20 00:31:14 -07002585 if (NULL == pHddTdlsCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302586 {
Ratheesh S P36dbc932015-08-07 14:28:57 +05302587 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
c_hpothu7f63e882013-10-02 19:13:35 +05302588 FL("pHddTdlsCtx is NULL"));
Hoonki Leed37cbb32013-04-20 00:31:14 -07002589 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302590 }
Hoonki Leed37cbb32013-04-20 00:31:14 -07002591
Hoonki Leed37cbb32013-04-20 00:31:14 -07002592 pHddCtx = WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter);
Hoonki Leefb8df672013-04-10 18:20:34 -07002593
c_hpothu7f63e882013-10-02 19:13:35 +05302594 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2595 {
Hoonki Leefb8df672013-04-10 18:20:34 -07002596 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302597 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002598
Hoonki Leed37cbb32013-04-20 00:31:14 -07002599 curr_peer = pHddTdlsCtx->curr_candidate;
Hoonki Leed37cbb32013-04-20 00:31:14 -07002600 if (NULL == curr_peer)
c_hpothu7f63e882013-10-02 19:13:35 +05302601 {
2602 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2603 FL("curr_peer is NULL"));
2604
Hoonki Leed37cbb32013-04-20 00:31:14 -07002605 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302606 }
Hoonki Leed37cbb32013-04-20 00:31:14 -07002607
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002608 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter)))
2609 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302610 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2611 "%s: Disable BMPS", __func__);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002612 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
2613 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002614
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302615 /* This function is called in mutex_lock */
2616 temp_peer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, FALSE);
Hoonki Leefb8df672013-04-10 18:20:34 -07002617 if (NULL != temp_peer)
2618 {
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302619 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2620 "%s: " MAC_ADDRESS_STR " ongoing. pre_setup ignored",
2621 __func__, MAC_ADDR_ARRAY(temp_peer->peerMac));
Hoonki Leed37cbb32013-04-20 00:31:14 -07002622 goto done;
Hoonki Leefb8df672013-04-10 18:20:34 -07002623 }
2624
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002625 if (eTDLS_CAP_UNKNOWN != curr_peer->tdls_support)
Atul Mittal115287b2014-07-08 13:26:33 +05302626 wlan_hdd_tdls_set_peer_link_status(curr_peer,
2627 eTDLS_LINK_DISCOVERING,
2628 eTDLS_LINK_SUCCESS);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002629
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302630 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2631 "%s: Implicit TDLS, Send Discovery request event", __func__);
Hoonki Leed37cbb32013-04-20 00:31:14 -07002632
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302633 cfg80211_tdls_oper_request(pHddTdlsCtx->pAdapter->dev,
2634 curr_peer->peerMac,
2635 NL80211_TDLS_DISCOVERY_REQ,
2636 FALSE,
2637 GFP_KERNEL);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002638 pHddTdlsCtx->discovery_sent_cnt++;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302639
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002640 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302641
Pradeep Reddy POTTETI219ced32014-11-14 16:33:57 +05302642 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2643 &pHddTdlsCtx->peerDiscoveryTimeoutTimer,
2644 pHddTdlsCtx->threshold_config.tx_period_t - TDLS_DISCOVERY_TIMEOUT_BEFORE_UPDATE);
2645
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302646 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2647 "%s: discovery count %u timeout %u msec",
2648 __func__, pHddTdlsCtx->discovery_sent_cnt,
2649 pHddTdlsCtx->threshold_config.tx_period_t - TDLS_DISCOVERY_TIMEOUT_BEFORE_UPDATE);
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002650
Hoonki Leed37cbb32013-04-20 00:31:14 -07002651done:
2652 pHddTdlsCtx->curr_candidate = NULL;
2653 pHddTdlsCtx->magic = 0;
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302654 EXIT();
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002655 return;
2656}
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002657
2658tANI_U32 wlan_hdd_tdls_discovery_sent_cnt(hdd_context_t *pHddCtx)
2659{
2660 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2661 hdd_adapter_t *pAdapter = NULL;
2662 tdlsCtx_t *pHddTdlsCtx = NULL;
2663 VOS_STATUS status = 0;
2664 tANI_U32 count = 0;
2665
2666 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2667 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2668 {
2669 pAdapter = pAdapterNode->pAdapter;
2670
Hoonki Leea6d49be2013-04-05 09:43:25 -07002671 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2672 if (NULL != pHddTdlsCtx)
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002673 {
Hoonki Leea6d49be2013-04-05 09:43:25 -07002674 count = count + pHddTdlsCtx->discovery_sent_cnt;
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002675 }
2676 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2677 pAdapterNode = pNext;
2678 }
2679 return count;
2680}
2681
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002682void wlan_hdd_tdls_check_power_save_prohibited(hdd_adapter_t *pAdapter)
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002683{
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302684 tdlsCtx_t *pHddTdlsCtx = NULL;
2685 hdd_context_t *pHddCtx = NULL;
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05302686
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302687
2688 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
2689 {
2690 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2691 FL("invalid pAdapter: %p"), pAdapter);
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05302692 return;
2693 }
2694
2695 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2696 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002697
2698 if ((NULL == pHddTdlsCtx) || (NULL == pHddCtx))
c_hpothu7f63e882013-10-02 19:13:35 +05302699 {
2700 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2701 FL(" pHddCtx or pHddTdlsCtx points to NULL"));
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002702 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302703 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002704
2705 if ((0 == pHddCtx->connected_peer_count) &&
2706 (0 == wlan_hdd_tdls_discovery_sent_cnt(pHddCtx)))
2707 {
2708 sme_SetTdlsPowerSaveProhibited(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter), 0);
2709 return;
2710 }
2711 sme_SetTdlsPowerSaveProhibited(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter), 1);
2712 return;
2713}
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002714
2715void wlan_hdd_tdls_free_scan_request (tdls_scan_context_t *tdls_scan_ctx)
2716{
2717 if (NULL == tdls_scan_ctx)
c_hpothu7f63e882013-10-02 19:13:35 +05302718 {
2719 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2720 FL("tdls_scan_ctx is NULL"));
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002721 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302722 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002723
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002724 tdls_scan_ctx->attempt = 0;
Hoonki Leefb8df672013-04-10 18:20:34 -07002725 tdls_scan_ctx->reject = 0;
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002726 tdls_scan_ctx->magic = 0;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002727 tdls_scan_ctx->scan_request = NULL;
2728 return;
2729}
2730
2731int wlan_hdd_tdls_copy_scan_context(hdd_context_t *pHddCtx,
2732 struct wiphy *wiphy,
2733#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2734 struct net_device *dev,
2735#endif
2736 struct cfg80211_scan_request *request)
2737{
2738 tdls_scan_context_t *scan_ctx;
2739
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302740 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302741 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2742 {
c_hpothu7f63e882013-10-02 19:13:35 +05302743 return 0;
2744 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002745
2746 scan_ctx = &pHddCtx->tdls_scan_ctxt;
2747
2748 scan_ctx->wiphy = wiphy;
2749#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2750 scan_ctx->dev = dev;
2751#endif
2752
2753 scan_ctx->scan_request = request;
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302754
2755 EXIT();
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002756 return 0;
2757}
2758
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002759static void wlan_hdd_tdls_scan_init_work(hdd_context_t *pHddCtx,
2760 struct wiphy *wiphy,
2761#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2762 struct net_device *dev,
2763#endif
2764 struct cfg80211_scan_request *request,
2765 unsigned long delay)
2766{
2767 if (TDLS_CTX_MAGIC != pHddCtx->tdls_scan_ctxt.magic)
2768 {
2769#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2770 wlan_hdd_tdls_copy_scan_context(pHddCtx, wiphy, dev, request);
2771#else
2772 wlan_hdd_tdls_copy_scan_context(pHddCtx, wiphy, request);
2773#endif
2774 pHddCtx->tdls_scan_ctxt.attempt = 0;
2775 pHddCtx->tdls_scan_ctxt.magic = TDLS_CTX_MAGIC;
2776 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002777 schedule_delayed_work(&pHddCtx->tdls_scan_ctxt.tdls_scan_work, delay);
2778}
2779
2780/* return negative = caller should stop and return error code immediately
2781 return 0 = caller should stop and return success immediately
2782 return 1 = caller can continue to scan
2783 */
2784int wlan_hdd_tdls_scan_callback (hdd_adapter_t *pAdapter,
2785 struct wiphy *wiphy,
2786#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2787 struct net_device *dev,
2788#endif
2789 struct cfg80211_scan_request *request)
2790{
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002791 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2792 u16 connectedTdlsPeers;
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302793 hddTdlsPeer_t *curr_peer, *connected_peer;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002794 unsigned long delay;
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302795 hdd_config_t *cfg_param = pHddCtx->cfg_ini;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002796
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302797 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302798 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2799 {
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002800 return 0;
c_hpothu7f63e882013-10-02 19:13:35 +05302801 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002802
2803 /* if tdls is not enabled, then continue scan */
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +05302804 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
2805 (pHddCtx->is_tdls_btc_enabled == FALSE))
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002806 return 1;
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302807 curr_peer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, TRUE);
Hoonki Leefb8df672013-04-10 18:20:34 -07002808 if (NULL != curr_peer)
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002809 {
Hoonki Leefb8df672013-04-10 18:20:34 -07002810 if (pHddCtx->tdls_scan_ctxt.reject++ >= TDLS_MAX_SCAN_REJECT)
2811 {
2812 pHddCtx->tdls_scan_ctxt.reject = 0;
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302813 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Leefb8df672013-04-10 18:20:34 -07002814 "%s: " MAC_ADDRESS_STR ". scan rejected %d. force it to idle",
2815 __func__, MAC_ADDR_ARRAY (curr_peer->peerMac), pHddCtx->tdls_scan_ctxt.reject);
2816
Atul Mittal115287b2014-07-08 13:26:33 +05302817 wlan_hdd_tdls_set_peer_link_status (curr_peer,
2818 eTDLS_LINK_IDLE,
2819 eTDLS_LINK_UNSPECIFIED);
Hoonki Leefb8df672013-04-10 18:20:34 -07002820 return 1;
2821 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302822 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Leefb8df672013-04-10 18:20:34 -07002823 "%s: tdls in progress. scan rejected %d",
2824 __func__, pHddCtx->tdls_scan_ctxt.reject);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002825 return -EBUSY;
2826 }
2827
2828 /* tdls teardown is ongoing */
2829 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
2830 {
2831 connectedTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
2832 if (connectedTdlsPeers && (pHddCtx->tdls_scan_ctxt.attempt < TDLS_MAX_SCAN_SCHEDULE))
2833 {
2834 delay = (unsigned long)(TDLS_DELAY_SCAN_PER_CONNECTION*connectedTdlsPeers);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302835 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002836 "%s: tdls disabled, but still connected_peers %d attempt %d. schedule scan %lu msec",
2837 __func__, connectedTdlsPeers, pHddCtx->tdls_scan_ctxt.attempt, delay);
2838
2839 wlan_hdd_tdls_scan_init_work (pHddCtx, wiphy,
2840#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2841 dev,
2842#endif
2843 request,
2844 msecs_to_jiffies(delay));
2845 /* scan should not continue */
2846 return 0;
2847 }
2848 /* no connected peer or max retry reached, scan continue */
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302849 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002850 "%s: tdls disabled. connected_peers %d attempt %d. scan allowed",
2851 __func__, connectedTdlsPeers, pHddCtx->tdls_scan_ctxt.attempt);
2852 return 1;
2853 }
Agarwal Ashishef54a182014-12-16 15:07:31 +05302854
2855 /* if fEnableTDLSScan flag is 1 ; driverwill allow scan even if
2856 * peer station is not buffer STA capable
2857 *
2858 * RX: If there is any RX activity, device will lose RX packets,
2859 * as peer will not be aware that device is off channel.
2860 * TX: TX is stopped whenever device initiate scan.
2861 */
2862 if (pHddCtx->cfg_ini->fEnableTDLSScan == 1)
2863 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302864 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Agarwal Ashishef54a182014-12-16 15:07:31 +05302865 FL("Allow SCAN in all TDLS cases"));
2866 return 1;
2867 }
2868
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002869 /* while tdls is up, first time scan */
2870 else if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode ||
2871 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == pHddCtx->tdls_mode)
2872 {
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002873 connectedTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302874
2875 /* check the TDLS link and Scan coexistance Capability */
2876 if ( (TRUE == pHddCtx->cfg_ini->fEnableTDLSScanCoexSupport) &&
2877 (TRUE == sme_IsFeatureSupportedByFW(TDLS_SCAN_COEXISTENCE)) &&
2878 (connectedTdlsPeers == 1) )
2879 {
2880 /* get connected peer information */
Pradeep Reddy POTTETIe309c152015-02-06 13:21:07 +05302881 connected_peer = wlan_hdd_tdls_get_connected_peer(pAdapter);
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302882 if (NULL == connected_peer) {
2883 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2884 "%s: Invalid connected_peer, Continue Scanning", __func__);
2885 /* scan should continue */
2886 return 1;
2887 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302888 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302889 ("%s: TDLS Scan Co-exist supported connectedTdlsPeers =%d buffersta =%d"),
2890 __func__,connectedTdlsPeers,connected_peer->isBufSta);
2891
2892 if (connected_peer->isBufSta)
2893 {
2894 pHddCtx->isTdlsScanCoexistence = TRUE;
2895 if ((cfg_param->dynSplitscan) && (!pHddCtx->issplitscan_enabled))
2896 {
2897 pHddCtx->issplitscan_enabled = TRUE;
2898 sme_enable_disable_split_scan(
2899 WLAN_HDD_GET_HAL_CTX(pAdapter),
2900 cfg_param->nNumStaChanCombinedConc,
2901 cfg_param->nNumP2PChanCombinedConc);
2902 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302903 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302904 ("%s:%d TDLS Scan Co-exist supported splitscan_enabled =%d "),
2905 __func__, __LINE__, pHddCtx->issplitscan_enabled);
2906 return 1;
2907 }
2908
2909 }
2910 else
2911 {
2912 /* Throughput Monitor shall disable the split scan when
2913 * TDLS scan coexistance is disabled.At this point of time
2914 * since TDLS scan coexistance is not meeting the criteria
2915 * to be operational, explicitly make it false to enable
2916 * throughput monitor takes the control of split scan.
2917 */
2918 pHddCtx->isTdlsScanCoexistence = FALSE;
2919 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302920 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302921 ("%s: TDLS Scan Co-exist not supported connectedTdlsPeers =%d"
2922 " TDLSScanCoexSupport param =%d TDLS_SCAN_COEXISTENCE =%d"),
2923 __func__, connectedTdlsPeers,
2924 pHddCtx->cfg_ini->fEnableTDLSScanCoexSupport,
2925 sme_IsFeatureSupportedByFW(TDLS_SCAN_COEXISTENCE));
2926
Atul Mittal5803b342014-09-04 15:31:19 +05302927 /* disable implicit trigger logic & tdls operatoin */
2928 wlan_hdd_tdls_set_mode(pHddCtx, eTDLS_SUPPORT_DISABLED, FALSE);
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302929 /* fall back to the implementation of teardown the peers on the scan
2930 * when the number of connected peers are more than one. TDLS Scan
2931 * coexistance feature is exercised only when a single peer is
2932 * connected and the DUT shall not advertize the Buffer Sta capability,
2933 * so that the peer shall not go to the TDLS power save
2934 */
2935
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002936 if (connectedTdlsPeers)
2937 {
2938 tANI_U8 staIdx;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002939 hddTdlsPeer_t *curr_peer;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002940
2941 for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
2942 {
2943 if (pHddCtx->tdlsConnInfo[staIdx].staId)
2944 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302945 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2946 ("%s: indicate TDLS teardown (staId %d)"), __func__, pHddCtx->tdlsConnInfo[staIdx].staId) ;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002947
2948#ifdef CONFIG_TDLS_IMPLICIT
Hoonki Leea6d49be2013-04-05 09:43:25 -07002949 curr_peer = wlan_hdd_tdls_find_all_peer(pHddCtx, pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes);
2950 if(curr_peer)
2951 wlan_hdd_tdls_indicate_teardown(curr_peer->pHddTdlsCtx->pAdapter, curr_peer, eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002952#endif
2953 }
2954 }
2955 /* schedule scan */
2956 delay = (unsigned long)(TDLS_DELAY_SCAN_PER_CONNECTION*connectedTdlsPeers);
2957
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302958 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002959 "%s: tdls enabled (mode %d), connected_peers %d. schedule scan %lu msec",
2960 __func__, pHddCtx->tdls_mode, wlan_hdd_tdlsConnectedPeers(pAdapter),
2961 delay);
2962
2963 wlan_hdd_tdls_scan_init_work (pHddCtx, wiphy,
2964#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2965 dev,
2966#endif
2967 request,
2968 msecs_to_jiffies(delay));
2969 /* scan should not continue */
2970 return 0;
2971 }
2972 /* no connected peer, scan continue */
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302973 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002974 "%s: tdls_mode %d, and no tdls connection. scan allowed",
2975 __func__, pHddCtx->tdls_mode);
2976 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302977 EXIT();
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002978 return 1;
2979}
2980
2981void wlan_hdd_tdls_scan_done_callback(hdd_adapter_t *pAdapter)
2982{
2983 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002984
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302985 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302986 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2987 {
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002988 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302989 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002990
Pradeep Reddy POTTETIc7822df2015-02-19 20:15:41 +05302991 /* if tdls is not enabled or BtCoex is on then don't revert tdls mode */
2992 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
Chandrasekaran, Manishekar0de84dc2015-03-10 15:12:34 +05302993 (pHddCtx->is_tdls_btc_enabled == FALSE)) {
2994 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to revert: Mode=%d, BTC enabled=%d"),
2995 pHddCtx->tdls_mode, pHddCtx->is_tdls_btc_enabled);
Pradeep Reddy POTTETIc7822df2015-02-19 20:15:41 +05302996 return;
Chandrasekaran, Manishekar0de84dc2015-03-10 15:12:34 +05302997 }
Sunil Dutt41de4e22013-11-14 18:09:02 +05302998
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002999 /* free allocated memory at scan time */
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07003000 wlan_hdd_tdls_free_scan_request (&pHddCtx->tdls_scan_ctxt);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07003001
3002 /* if tdls was enabled before scan, re-enable tdls mode */
3003 if(eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode_last ||
3004 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == pHddCtx->tdls_mode_last)
3005 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05303006 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07003007 ("%s: revert tdls mode %d"), __func__, pHddCtx->tdls_mode_last);
3008
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07003009 wlan_hdd_tdls_set_mode(pHddCtx, pHddCtx->tdls_mode_last, FALSE);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07003010 }
3011 wlan_hdd_tdls_check_bmps(pAdapter);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05303012
3013 EXIT();
Hoonki Lee93e67ff2013-03-19 15:49:25 -07003014}
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07003015
3016void wlan_hdd_tdls_timer_restart(hdd_adapter_t *pAdapter,
3017 vos_timer_t *timer,
3018 v_U32_t expirationTime)
3019{
3020 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3021
3022 if (NULL == pHddStaCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05303023 {
3024 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3025 FL("pHddStaCtx is NULL"));
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07003026 return;
c_hpothu7f63e882013-10-02 19:13:35 +05303027 }
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07003028
3029 /* Check whether driver load unload is in progress */
3030 if(vos_is_load_unload_in_progress( VOS_MODULE_ID_VOSS, NULL))
3031 {
3032 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
3033 "%s: Driver load/unload is in progress.", __func__);
3034 return;
3035 }
3036
3037 if (hdd_connIsConnected(pHddStaCtx))
3038 {
3039 vos_timer_stop(timer);
3040 vos_timer_start(timer, expirationTime);
3041 }
3042}
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003043void wlan_hdd_tdls_indicate_teardown(hdd_adapter_t *pAdapter,
3044 hddTdlsPeer_t *curr_peer,
3045 tANI_U16 reason)
3046{
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05303047 hdd_context_t *pHddCtx;
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05303048
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05303049 if ((NULL == pAdapter || WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic) ||
3050 (NULL == curr_peer))
c_hpothu7f63e882013-10-02 19:13:35 +05303051 {
3052 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3053 FL("parameters passed are invalid"));
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003054 return;
c_hpothu7f63e882013-10-02 19:13:35 +05303055 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003056
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05303057 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3058
Masti, Narayanraddi9d275662015-08-26 13:15:12 +05303059 if ((eTDLS_LINK_CONNECTED != curr_peer->link_status) &&
3060 (eTDLS_LINK_CONNECTING != curr_peer->link_status))
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003061 return;
3062
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05303063 /* Throughput Monitor shall disable the split scan when
3064 * TDLS scan coexistance is disabled.At this point of time
3065 * since TDLS scan coexistance is not meeting the criteria
3066 * to be operational, explicitly make it false to enable
3067 * throughput monitor takes the control of split scan.
3068 */
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05303069 if (pHddCtx && (pHddCtx->isTdlsScanCoexistence == TRUE))
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05303070 {
3071 pHddCtx->isTdlsScanCoexistence = FALSE;
3072 }
3073
Atul Mittal115287b2014-07-08 13:26:33 +05303074 wlan_hdd_tdls_set_peer_link_status(curr_peer,
3075 eTDLS_LINK_TEARING,
Atul Mittal271a7652014-09-12 13:18:22 +05303076 eTDLS_LINK_UNSPECIFIED);
Agarwal Ashisha7ef41d2015-06-25 18:00:26 +05303077 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3078 FL("Setting NL80211_TDLS_TEARDOWN, reason %d"), reason);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003079 cfg80211_tdls_oper_request(pAdapter->dev,
3080 curr_peer->peerMac,
3081 NL80211_TDLS_TEARDOWN,
3082 reason,
3083 GFP_KERNEL);
3084}
Atul Mittal115287b2014-07-08 13:26:33 +05303085
3086
3087/*EXT TDLS*/
3088int wlan_hdd_set_callback(hddTdlsPeer_t *curr_peer,
3089 cfg80211_exttdls_callback callback)
3090{
3091
3092 hdd_context_t *pHddCtx;
3093 hdd_adapter_t *pAdapter;
3094
3095 if (!curr_peer) return -1;
3096
3097 pAdapter = curr_peer->pHddTdlsCtx->pAdapter;
3098 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3099 if ((NULL == pHddCtx)) return -1;
3100
3101 mutex_lock(&pHddCtx->tdls_lock);
3102
3103 curr_peer->state_change_notification = callback;
3104
3105 mutex_unlock(&pHddCtx->tdls_lock);
3106 return 0;
3107
3108
3109}
3110
3111void wlan_hdd_tdls_get_wifi_hal_state(hddTdlsPeer_t *curr_peer,
3112 tANI_S32 *state,
3113 tANI_S32 *reason)
3114{
3115 *reason = curr_peer->reason;
3116
3117 switch(curr_peer->link_status)
3118 {
3119 case eTDLS_LINK_IDLE:
Atul Mittal115287b2014-07-08 13:26:33 +05303120 case eTDLS_LINK_DISCOVERED:
3121 *state = WIFI_TDLS_ENABLED;
3122 break;
Atul Mittalad630e42014-10-07 19:19:14 +05303123 case eTDLS_LINK_DISCOVERING:
Atul Mittal115287b2014-07-08 13:26:33 +05303124 case eTDLS_LINK_CONNECTING:
3125 *state = WIFI_TDLS_TRYING;
3126 break;
3127 case eTDLS_LINK_CONNECTED:
Pradeep Reddy POTTETIf3148e82015-04-16 12:10:33 +05303128 if (TRUE == curr_peer->isOffChannelEstablished)
Pradeep Reddy POTTETI16d83332015-03-26 18:28:13 +05303129 {
3130 *state = WIFI_TDLS_ESTABLISHED_OFF_CHANNEL;
3131 }
3132 else
3133 {
3134 *state = WIFI_TDLS_ESTABLISHED;
3135 }
Atul Mittal115287b2014-07-08 13:26:33 +05303136 break;
3137 case eTDLS_LINK_TEARING:
3138 *state = WIFI_TDLS_DROPPED;
3139 break;
3140 }
3141
3142}
3143
3144int wlan_hdd_tdls_get_status(hdd_adapter_t *pAdapter,
Anand N Sunkad9bfc2622015-07-30 15:18:54 +05303145#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
3146 const tANI_U8* mac,
3147#else
Atul Mittal115287b2014-07-08 13:26:33 +05303148 tANI_U8* mac,
Anand N Sunkad9bfc2622015-07-30 15:18:54 +05303149#endif
Atul Mittal115287b2014-07-08 13:26:33 +05303150 tANI_S32 *state,
3151 tANI_S32 *reason)
3152{
3153
3154 hddTdlsPeer_t *curr_peer;
Atul Mittala75fced2014-10-06 13:59:07 +05303155 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Atul Mittal115287b2014-07-08 13:26:33 +05303156 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
3157 if (curr_peer == NULL)
3158 {
Atul Mittala75fced2014-10-06 13:59:07 +05303159 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Atul Mittal115287b2014-07-08 13:26:33 +05303160 FL("curr_peer is NULL"));
Atul Mittal115287b2014-07-08 13:26:33 +05303161
Atul Mittala75fced2014-10-06 13:59:07 +05303162 *state = WIFI_TDLS_DISABLED;
3163 *reason = eTDLS_LINK_UNSPECIFIED;
3164 }
3165 else
3166 {
3167 if (pHddCtx->cfg_ini->fTDLSExternalControl &&
3168 (FALSE == curr_peer->isForcedPeer))
3169 {
3170 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3171 FL("curr_peer is not Forced"));
3172 *state = WIFI_TDLS_DISABLED;
3173 *reason = eTDLS_LINK_UNSPECIFIED;
3174 }
3175 else
3176 {
3177 wlan_hdd_tdls_get_wifi_hal_state(curr_peer, state, reason);
3178 }
3179 }
Atul Mittal115287b2014-07-08 13:26:33 +05303180 return (0);
3181}
3182
Agarwal Ashishef54a182014-12-16 15:07:31 +05303183int hdd_set_tdls_scan_type(hdd_adapter_t *pAdapter,
3184 tANI_U8 *ptr)
3185{
3186 int tdls_scan_type;
Hema Aparna Medicharla26b98042015-01-21 15:02:01 +05303187 hdd_context_t *pHddCtx;
Agarwal Ashishef54a182014-12-16 15:07:31 +05303188 if (NULL == pAdapter)
3189 {
3190 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3191 "%s: pAdapter is NULL", __func__);
3192 return -EINVAL;
3193 }
Hema Aparna Medicharla26b98042015-01-21 15:02:01 +05303194 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Agarwal Ashishef54a182014-12-16 15:07:31 +05303195 tdls_scan_type = ptr[9] - '0';
3196
3197 if (tdls_scan_type <= 2)
3198 {
3199 pHddCtx->cfg_ini->fEnableTDLSScan = tdls_scan_type;
3200 return 0;
3201 }
3202 else
3203 {
3204 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3205 " Wrong value is given for tdls_scan_type "
3206 " Making fEnableTDLSScan as 0 ");
3207 pHddCtx->cfg_ini->fEnableTDLSScan = 0;
3208 return -EINVAL;
3209 }
3210}
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +05303211int wlan_hdd_validate_tdls_context(hdd_context_t *pHddCtx,
3212 tdlsCtx_t *pHddTdlsCtx)
3213{
3214 VOS_STATUS status;
3215 int found = 0;
3216 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
3217 hdd_adapter_t *pAdapter;
Agarwal Ashishef54a182014-12-16 15:07:31 +05303218
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +05303219 if (NULL == pHddTdlsCtx)
3220 {
3221 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3222 FL("TDLS context is NULL"));
3223 return -EINVAL;
3224 }
3225 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
3226 while (NULL != pAdapterNode && VOS_STATUS_SUCCESS == status)
3227 {
3228 pAdapter = pAdapterNode->pAdapter;
3229 if (NULL != pAdapter)
3230 {
3231 if (pHddTdlsCtx == pAdapter->sessionCtx.station.pHddTdlsCtx &&
3232 (NULL != pHddTdlsCtx->pAdapter) &&
3233 (WLAN_HDD_ADAPTER_MAGIC == pHddTdlsCtx->pAdapter->magic))
3234 {
3235 found = 1;
3236 break;
3237 }
3238 }
3239 status = hdd_get_next_adapter (pHddCtx, pAdapterNode, &pNext);
3240 pAdapterNode = pNext;
3241 }
3242 if (found == 1)
3243 {
3244 return 0;
3245 }
3246 else
3247 {
3248 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3249 FL("TDLS context doesnot belongs to valid adapter"));
3250 return -EINVAL;
3251 }
3252}
Ganesh Kondabattinif3ba0972015-08-07 15:58:04 +05303253
3254
3255void wlan_hdd_tdls_update_rx_pkt_cnt_n_rssi(hdd_adapter_t *pAdapter,
3256 u8 *mac, v_S7_t rssiAvg)
3257{
3258 hddTdlsPeer_t *curr_peer;
3259 hdd_context_t *pHddCtx = NULL;
3260 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3261 mutex_lock(&pHddCtx->tdls_lock);
3262 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, FALSE);
3263 if ((NULL != curr_peer) &&
3264 (eTDLS_LINK_CONNECTED == curr_peer->link_status))
3265 {
3266 curr_peer->rx_pkt++;
3267 curr_peer->rssi = rssiAvg;
3268 }
3269 mutex_unlock(&pHddCtx->tdls_lock);
3270 VOS_TRACE( VOS_MODULE_ID_HDD_DATA, VOS_TRACE_LEVEL_INFO,
3271 "mac : " MAC_ADDRESS_STR "rssi is %d",
3272 MAC_ADDR_ARRAY(mac), rssiAvg);
3273}
Atul Mittal115287b2014-07-08 13:26:33 +05303274
Masti, Narayanraddi575ccc72015-08-17 18:04:57 +05303275/**
3276 * wlan_hdd_tdls_reenable() - Re-Enable TDLS
3277 * @hddctx: pointer to hdd context
3278 *
3279 * Function re-enable's TDLS which might be disabled during concurrency
3280 *
3281 * Return: None
3282 */
3283void wlan_hdd_tdls_reenable(hdd_context_t *pHddCtx)
3284{
3285
3286 if ((TRUE != pHddCtx->cfg_ini->fEnableTDLSSupport) ||
3287 (TRUE != sme_IsFeatureSupportedByFW(TDLS))) {
3288 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3289 FL("tdls support not enabled"));
3290 return;
3291 }
3292
3293 /* if tdls is not enabled or BtCoex is on then don't revert tdls mode */
3294 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
3295 (pHddCtx->is_tdls_btc_enabled == FALSE)) {
3296 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3297 FL("btc disable tdls so no need to enable: Mode=%d, BTC enabled=%d"),
3298 pHddCtx->tdls_mode, pHddCtx->is_tdls_btc_enabled);
3299 return;
3300 }
3301
3302 if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode_last ||
3303 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY ==
3304 pHddCtx->tdls_mode_last) {
3305 /* Enable TDLS support Once P2P session ends since
3306 * upond detection of concurrency TDLS might be disabled
3307 */
3308 hddLog(LOG1, FL("TDLS mode set to %d"), pHddCtx->tdls_mode_last);
3309 wlan_hdd_tdls_set_mode(pHddCtx, pHddCtx->tdls_mode_last,
3310 FALSE);
3311 }
3312}
3313/*EXT TDLS*/