blob: 6daeafe7bc6a7a9c361b8499c2ad16ec3c590224 [file] [log] [blame]
Kiran V1ccee932012-12-12 14:49:46 -08001/*
Gopichand Nakkala0c1331e2013-01-07 22:49:07 -08002 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
3 *
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.
20 */
Kiran V1ccee932012-12-12 14:49:46 -080021
22/**========================================================================
23
24 \file wlan_hdd_tdls.c
25
Chilam NG571c65a2013-01-19 12:27:36 +053026 \brief WLAN Host Device Driver implementation for TDLS
Kiran V1ccee932012-12-12 14:49:46 -080027
Kiran V1ccee932012-12-12 14:49:46 -080028 ========================================================================*/
29
30#include <wlan_hdd_includes.h>
31#include <wlan_hdd_hostapd.h>
32#include <net/cfg80211.h>
33#include <linux/netdevice.h>
34#include <linux/skbuff.h>
Chilam NG571c65a2013-01-19 12:27:36 +053035#include <linux/list.h>
Kiran V1ccee932012-12-12 14:49:46 -080036#include <linux/etherdevice.h>
37#include <net/ieee80211_radiotap.h>
38#include "wlan_hdd_tdls.h"
Chilam NG571c65a2013-01-19 12:27:36 +053039#include "wlan_hdd_cfg80211.h"
Kiran V1ccee932012-12-12 14:49:46 -080040
Chilam NG571c65a2013-01-19 12:27:36 +053041
42typedef struct {
43 struct list_head node;
Kiran V1ccee932012-12-12 14:49:46 -080044 tSirMacAddr peerMac;
Chilam NG571c65a2013-01-19 12:27:36 +053045 tANI_U16 staId ;
46 tANI_S8 rssi;
47 tANI_S8 tdls_support;
48 tANI_S8 link_status;
49 tANI_U16 discovery_attempt;
50 tANI_U16 tx_pkt;
51} hddTdlsPeer_t;
Kiran V1ccee932012-12-12 14:49:46 -080052
Kiran V1ccee932012-12-12 14:49:46 -080053
Chilam NG571c65a2013-01-19 12:27:36 +053054typedef struct {
55 hddTdlsPeer_t* peer_list[256];
56 struct net_device *dev;
57 spinlock_t lock;
58 vos_timer_t peerDiscoverTimer;
59 vos_timer_t peerUpdateTimer;
60 vos_timer_t peerIdleTimer;
61 tdls_config_params_t threshold_config;
62 tANI_S8 ap_rssi;
63} tdlsCtx_t;
64
65tdlsCtx_t *pHddTdlsCtx;
66
Hoonki Leecdd8e962013-01-20 00:45:46 -080067void wlan_hdd_freeTdlsPeer(void);
Chilam NG571c65a2013-01-19 12:27:36 +053068
69static v_VOID_t wlan_hdd_discover_peer_cb( v_PVOID_t userData )
Hoonki Leef63df0d2013-01-16 19:29:14 -080070{
71 int i;
Chilam NG571c65a2013-01-19 12:27:36 +053072 hddTdlsPeer_t *curr_peer;
Hoonki Leebfee0342013-01-21 16:43:45 -080073 hdd_adapter_t *pAdapter;
74 hdd_context_t *pHddCtx;
75
76 if (NULL == pHddTdlsCtx) return;
77
78 pAdapter = WLAN_HDD_GET_PRIV_PTR(pHddTdlsCtx->dev);
79 pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Hoonki Leef63df0d2013-01-16 19:29:14 -080080
Chilam NG571c65a2013-01-19 12:27:36 +053081 for (i = 0; i < 256; i++) {
82 curr_peer = pHddTdlsCtx->peer_list[i];
83 if (NULL == curr_peer) continue;
84
85 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
86 "hdd discovery cb - %d: %x %x %x %x %x %x\n", i,
87 curr_peer->peerMac[0],
88 curr_peer->peerMac[1],
89 curr_peer->peerMac[2],
90 curr_peer->peerMac[3],
91 curr_peer->peerMac[4],
92 curr_peer->peerMac[5]);
93
94 do {
95 if ((eTDLS_CAP_UNKNOWN == curr_peer->tdls_support) &&
96 (eTDLS_LINK_NOT_CONNECTED == curr_peer->link_status) &&
97 (curr_peer->discovery_attempt <
98 pHddTdlsCtx->threshold_config.discovery_tries_n)) {
99 wlan_hdd_cfg80211_send_tdls_discover_req(pHddCtx->wiphy,
100 pHddTdlsCtx->dev, curr_peer->peerMac);
101// cfg80211_tdls_oper_request(pHddTdlsCtx->dev, curr_peer->peerMac,
102// NL80211_TDLS_DISCOVERY_REQ, FALSE, GFP_KERNEL);
103
104// if (++curr_peer->discovery_attempt >= pHddTdlsCtx->threshold_config.discovery_tries_n) {
105// curr_peer->tdls_support = eTDLS_CAP_NOT_SUPPORTED;
106// }
107 }
108
109 curr_peer = (hddTdlsPeer_t *)curr_peer->node.next;
110 } while (&curr_peer->node != curr_peer->node.next);
Hoonki Leef63df0d2013-01-16 19:29:14 -0800111 }
112
Chilam NG571c65a2013-01-19 12:27:36 +0530113 vos_timer_start( &pHddTdlsCtx->peerDiscoverTimer,
114 pHddTdlsCtx->threshold_config.discovery_period_t );
115
116 wlan_hdd_get_rssi(pAdapter, &pHddTdlsCtx->ap_rssi);
117
118 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "beacon rssi: %d",
119 pHddTdlsCtx->ap_rssi);
Hoonki Leef63df0d2013-01-16 19:29:14 -0800120}
Chilam NG571c65a2013-01-19 12:27:36 +0530121
122static v_VOID_t wlan_hdd_update_peer_cb( v_PVOID_t userData )
123{
124 int i;
125 hddTdlsPeer_t *curr_peer;
126
Hoonki Leebfee0342013-01-21 16:43:45 -0800127 if (NULL == pHddTdlsCtx) return;
128
Chilam NG571c65a2013-01-19 12:27:36 +0530129 for (i = 0; i < 256; i++) {
130 curr_peer = pHddTdlsCtx->peer_list[i];
131 if (NULL == curr_peer) continue;
132
133 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
134 "hdd update cb - %d: %x %x %x %x %x %x -> %d\n", i,
135 curr_peer->peerMac[0],
136 curr_peer->peerMac[1],
137 curr_peer->peerMac[2],
138 curr_peer->peerMac[3],
139 curr_peer->peerMac[4],
140 curr_peer->peerMac[5],
141 curr_peer->tx_pkt);
142
143 do {
144 if (eTDLS_CAP_SUPPORTED == curr_peer->tdls_support) {
145 if (eTDLS_LINK_CONNECTED != curr_peer->link_status) {
146 if (curr_peer->tx_pkt >=
147 pHddTdlsCtx->threshold_config.tx_packet_n) {
148#ifdef CONFIG_TDLS_IMPLICIT
149 cfg80211_tdls_oper_request(pHddTdlsCtx->dev,
150 curr_peer->peerMac,
151 NL80211_TDLS_SETUP, FALSE,
152 GFP_KERNEL);
153#endif
Hoonki Leecdd8e962013-01-20 00:45:46 -0800154 goto next_peer;
Chilam NG571c65a2013-01-19 12:27:36 +0530155 }
156
Hoonki Leecdd8e962013-01-20 00:45:46 -0800157 if ((tANI_S32)curr_peer->rssi >
158 (tANI_S32)(pHddTdlsCtx->threshold_config.rssi_hysteresis +
Chilam NG571c65a2013-01-19 12:27:36 +0530159 pHddTdlsCtx->ap_rssi)) {
160
161 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
162 "RSSI triggering");
163
164#ifdef CONFIG_TDLS_IMPLICIT
165 cfg80211_tdls_oper_request(pHddTdlsCtx->dev,
166 curr_peer->peerMac,
167 NL80211_TDLS_SETUP, FALSE,
168 GFP_KERNEL);
169#endif
170 }
171 } else {
Hoonki Leecdd8e962013-01-20 00:45:46 -0800172 if (curr_peer->tx_pkt <
173 pHddTdlsCtx->threshold_config.tx_packet_n) {
Chilam NG571c65a2013-01-19 12:27:36 +0530174 cfg80211_tdls_oper_request(pHddTdlsCtx->dev,
175 curr_peer->peerMac,
176 NL80211_TDLS_TEARDOWN, FALSE,
177 GFP_KERNEL);
Hoonki Leecdd8e962013-01-20 00:45:46 -0800178
179 goto next_peer;
Chilam NG571c65a2013-01-19 12:27:36 +0530180 }
Hoonki Leecdd8e962013-01-20 00:45:46 -0800181
182// if (curr_peer->rssi <
183// (pHddTdlsCtx->threshold_config.rssi_hysteresis +
184// pHddTdlsCtx->ap_rssi)) {
185//
186//#ifdef CONFIG_TDLS_IMPLICIT
187// cfg80211_tdls_oper_request(pHddTdlsCtx->dev,
188// curr_peer->peerMac,
189// NL80211_TDLS_TEARDOWN, FALSE,
190// GFP_KERNEL);
191//#endif
192// }
Chilam NG571c65a2013-01-19 12:27:36 +0530193 }
194 }
195
Hoonki Leecdd8e962013-01-20 00:45:46 -0800196next_peer:
Chilam NG571c65a2013-01-19 12:27:36 +0530197 curr_peer->tx_pkt = 0;
198
199 curr_peer = (hddTdlsPeer_t *)curr_peer->node.next;
200 } while (&curr_peer->node != curr_peer->node.next);
201 }
202
203 vos_timer_start( &pHddTdlsCtx->peerUpdateTimer,
204 pHddTdlsCtx->threshold_config.tx_period_t );
205}
206
207int wlan_hdd_tdls_init(struct net_device *dev)
208{
209 VOS_STATUS status;
Hoonki Leebf870f32013-01-19 15:53:30 +0530210 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
211 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Chilam NG571c65a2013-01-19 12:27:36 +0530212
Hoonki Leebf870f32013-01-19 15:53:30 +0530213 if(FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport)
214 {
215 hddLog(VOS_TRACE_LEVEL_ERROR, "%s TDLS not enabled!", __func__);
216 return -1;
217 }
218
219 pHddTdlsCtx = vos_mem_malloc(sizeof(tdlsCtx_t));
Chilam NG571c65a2013-01-19 12:27:36 +0530220 if (NULL == pHddTdlsCtx) {
221 hddLog(VOS_TRACE_LEVEL_ERROR, "%s malloc failed!", __func__);
222 return -1;
223 }
224
225 vos_mem_zero(pHddTdlsCtx, sizeof(tdlsCtx_t));
226
227 pHddTdlsCtx->dev = dev;
228
Hoonki Leebf870f32013-01-19 15:53:30 +0530229 if(FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger)
230 {
231 hddLog(VOS_TRACE_LEVEL_ERROR, "%s TDLS Implicit trigger not enabled!", __func__);
232 return -1;
233 }
234 pHddTdlsCtx->threshold_config.tx_period_t = pHddCtx->cfg_ini->fTDLSTxStatsPeriod;
235 pHddTdlsCtx->threshold_config.tx_packet_n = pHddCtx->cfg_ini->fTDLSTxPacketThreshold;
236 pHddTdlsCtx->threshold_config.discovery_period_t = pHddCtx->cfg_ini->fTDLSDiscoveryPeriod;
237 pHddTdlsCtx->threshold_config.discovery_tries_n = pHddCtx->cfg_ini->fTDLSMaxDiscoveryAttempt;
238 pHddTdlsCtx->threshold_config.rx_timeout_t = pHddCtx->cfg_ini->fTDLSRxIdleTimeout;
239 pHddTdlsCtx->threshold_config.rssi_hysteresis = pHddCtx->cfg_ini->fTDLSRssiHysteresis;
Chilam NG571c65a2013-01-19 12:27:36 +0530240
241 status = vos_timer_init(&pHddTdlsCtx->peerDiscoverTimer,
242 VOS_TIMER_TYPE_SW,
243 wlan_hdd_discover_peer_cb,
244 pHddTdlsCtx);
245
246 status = vos_timer_start( &pHddTdlsCtx->peerDiscoverTimer,
247 pHddTdlsCtx->threshold_config.discovery_period_t );
248
249 status = vos_timer_init(&pHddTdlsCtx->peerUpdateTimer,
250 VOS_TIMER_TYPE_SW,
251 wlan_hdd_update_peer_cb,
252 pHddTdlsCtx);
253
254 status = vos_timer_start( &pHddTdlsCtx->peerUpdateTimer,
255 pHddTdlsCtx->threshold_config.tx_period_t );
256
257 return 0;
258}
259
260void wlan_hdd_tdls_exit()
261{
Hoonki Leebfee0342013-01-21 16:43:45 -0800262 hdd_adapter_t *pAdapter;
263 hdd_context_t *pHddCtx;
264
265 if (NULL == pHddTdlsCtx) return;
266
267 pAdapter = WLAN_HDD_GET_PRIV_PTR(pHddTdlsCtx->dev);
268 pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
269
270 if(FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport)
271 {
272 hddLog(VOS_TRACE_LEVEL_WARN, "%s TDLS not enabled, exiting!", __func__);
273 return;
274 }
275
276 if(FALSE != pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger) {
277 vos_timer_stop(&pHddTdlsCtx->peerDiscoverTimer);
278 vos_timer_destroy(&pHddTdlsCtx->peerDiscoverTimer);
279 vos_timer_stop(&pHddTdlsCtx->peerUpdateTimer);
280 vos_timer_destroy(&pHddTdlsCtx->peerUpdateTimer);
281 }
Hoonki Leecdd8e962013-01-20 00:45:46 -0800282
283 wlan_hdd_freeTdlsPeer();
284 if(pHddTdlsCtx)
285 vos_mem_free(pHddTdlsCtx);
Chilam NG571c65a2013-01-19 12:27:36 +0530286}
287
288int wlan_hdd_tdls_set_link_status(u8 *mac, int status)
289{
290 hddTdlsPeer_t *curr_peer;
291 int i;
292 u8 key = 0;
293
Hoonki Leebfee0342013-01-21 16:43:45 -0800294 if (NULL == pHddTdlsCtx) return -1;
295
Chilam NG571c65a2013-01-19 12:27:36 +0530296 for (i = 0; i < 6; i++)
297 key ^= mac[i];
298
299 curr_peer = pHddTdlsCtx->peer_list[key];
300
301 if (NULL == curr_peer) {
302 hddLog(VOS_TRACE_LEVEL_ERROR, "%s no matching MAC!", __func__);
303 return -1;
304 }
305
306 do {
307 if (!memcmp(mac, curr_peer->peerMac, 6)) goto found_peer;
308 curr_peer = (hddTdlsPeer_t *)curr_peer->node.next;
309 } while (&curr_peer->node != curr_peer->node.next);
310
311 hddLog(VOS_TRACE_LEVEL_ERROR, "%s no matching MAC!", __func__);
312 return -1;
313
314found_peer:
315
316 hddLog(VOS_TRACE_LEVEL_WARN, "tdls set peer %d link status to %d",
317 key, status);
318
319 curr_peer->link_status = status;
320
321 return status;
322}
323
324int wlan_hdd_tdls_set_cap(u8 *mac, int cap)
325{
326 hddTdlsPeer_t *curr_peer;
327 int i;
328 u8 key = 0;
329
Hoonki Leebfee0342013-01-21 16:43:45 -0800330 if (NULL == pHddTdlsCtx) return -1;
331
Chilam NG571c65a2013-01-19 12:27:36 +0530332 for (i = 0; i < 6; i++)
333 key ^= mac[i];
334
335 curr_peer = pHddTdlsCtx->peer_list[key];
336
337 if (NULL == curr_peer) {
338 curr_peer = vos_mem_malloc(sizeof(hddTdlsPeer_t));
339
340 if (NULL == curr_peer) {
341 hddLog(VOS_TRACE_LEVEL_ERROR, "%s peer malloc failed!", __func__);
342 return -1;
343 }
344 vos_mem_zero(curr_peer, sizeof(hddTdlsPeer_t));
345
346 INIT_LIST_HEAD(&curr_peer->node);
347 memcpy(curr_peer->peerMac, mac, 6);
348 curr_peer->tdls_support = cap;
349 pHddTdlsCtx->peer_list[key] = curr_peer;
350
351 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
352 "new peer - key:%d, mac:%x %x %x %x %x %x, 0x%x",
353 key, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
354 curr_peer );
355 return 0;
356 }
357
358 do {
359 if (!memcmp(mac, curr_peer->peerMac, 6)) goto found_peer;
360 curr_peer = (hddTdlsPeer_t *)curr_peer->node.next;
361 } while (&curr_peer->node != curr_peer->node.next);
362
363 hddLog(VOS_TRACE_LEVEL_ERROR, "%s no matching MAC %d: %x %x %x %x %x %x",
364 __func__, key, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
365
366 return -1;
367
368found_peer:
369
370 hddLog(VOS_TRACE_LEVEL_WARN, "tdls set peer %d support cap to %d",
371 key, cap);
372
373 curr_peer->tdls_support = cap;
374
375 return cap;
376}
377
378int wlan_hdd_tdls_set_rssi(u8 *mac, tANI_S8 rxRssi)
379{
380 hddTdlsPeer_t *curr_peer;
381 int i;
382 u8 key = 0;
383
Hoonki Leebfee0342013-01-21 16:43:45 -0800384 if (NULL == pHddTdlsCtx) return -1;
385
Chilam NG571c65a2013-01-19 12:27:36 +0530386 for (i = 0; i < 6; i++)
387 key ^= mac[i];
388
389 curr_peer = pHddTdlsCtx->peer_list[key];
390
391 if (NULL == curr_peer) {
392 curr_peer = vos_mem_malloc(sizeof(hddTdlsPeer_t));
393
394 if (NULL == curr_peer) {
395 hddLog(VOS_TRACE_LEVEL_ERROR, "%s peer malloc failed!", __func__);
396 return -1;
397 }
398 vos_mem_zero(curr_peer, sizeof(hddTdlsPeer_t));
399
400 INIT_LIST_HEAD(&curr_peer->node);
401 memcpy(curr_peer->peerMac, mac, 6);
402 curr_peer->rssi = rxRssi;
403 pHddTdlsCtx->peer_list[key] = curr_peer;
404
405 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
406 "new peer - key:%d, mac:%x %x %x %x %x %x, 0x%x",
407 key, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
408 curr_peer );
409 return 0;
410 }
411
412 do {
413 if (!memcmp(mac, curr_peer->peerMac, 6)) goto found_peer;
414 curr_peer = (hddTdlsPeer_t *)curr_peer->node.next;
415 } while (&curr_peer->node != curr_peer->node.next);
416
417 hddLog(VOS_TRACE_LEVEL_ERROR, "%s no matching MAC %d: %x %x %x %x %x %x",
418 __func__, key, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
419
420 return -1;
421
422found_peer:
423
424 hddLog(VOS_TRACE_LEVEL_WARN, "tdls set peer %d rssi to %d",
425 key, rxRssi);
426
427 curr_peer->rssi = rxRssi;
428
429 return rxRssi;
430}
431
432u8 wlan_hdd_tdls_extract_da(struct sk_buff *skb, u8 *mac)
433{
434 int i;
435 u8 hash = 0;
436
437 memcpy(mac, skb->data, 6);
438 for (i = 0; i < 6; i++)
439 hash ^= mac[i];
440
441 return hash;
442}
443
444int wlan_hdd_tdls_add_peer_to_list(u8 key, u8 *mac)
445{
446 hddTdlsPeer_t *new_peer, *curr_peer;
447
Hoonki Leebfee0342013-01-21 16:43:45 -0800448 if (NULL == pHddTdlsCtx) return -1;
449
Chilam NG571c65a2013-01-19 12:27:36 +0530450 curr_peer = pHddTdlsCtx->peer_list[key];
451
452 if (NULL == curr_peer) {
453 curr_peer = vos_mem_malloc(sizeof(hddTdlsPeer_t));
454
455 if (NULL == curr_peer) {
456 hddLog(VOS_TRACE_LEVEL_ERROR, "%s peer malloc failed!", __func__);
457 return -1;
458 }
459 vos_mem_zero(curr_peer, sizeof(hddTdlsPeer_t));
460 curr_peer->rssi = -120;
461
462 INIT_LIST_HEAD(&curr_peer->node);
463 memcpy(curr_peer->peerMac, mac, 6);
464
465 pHddTdlsCtx->peer_list[key] = curr_peer;
466
467 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
468 "new peer - key:%d, mac:%x %x %x %x %x %x, 0x%x",
469 key, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
470 curr_peer );
471 return 0;
472 }
473
474 do {
475 if (!memcmp(mac, curr_peer->peerMac, 6)) goto known_peer;
476 curr_peer = (hddTdlsPeer_t *)curr_peer->node.next;
477 } while (&curr_peer->node != curr_peer->node.next);
478
479 new_peer = vos_mem_malloc(sizeof(hddTdlsPeer_t));
480 if (NULL == new_peer) {
481 hddLog(VOS_TRACE_LEVEL_ERROR, "%s peer malloc failed!", __func__);
482 return -1;
483 }
484 vos_mem_zero(new_peer, sizeof(hddTdlsPeer_t));
485 curr_peer->rssi = -120;
486 memcpy(new_peer->peerMac, mac, 6);
487
488 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
489 "add peer - key:%d, mac:%x %x %x %x %x %x",
490 key, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );
491
492 list_add(&new_peer->node, &curr_peer->node);
493 curr_peer = new_peer;
494
495known_peer:
496 curr_peer->tx_pkt++;
497
498 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
499 "known peer - key:%d, mac:%x %x %x %x %x %x, tx:%d",
500 key, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
501 curr_peer->tx_pkt );
502
503 return 0;
504}
505
506int wlan_hdd_tdls_set_params(tdls_config_params_t *config)
507{
Hoonki Leebfee0342013-01-21 16:43:45 -0800508 if (NULL == pHddTdlsCtx) return -1;
509
Chilam NG571c65a2013-01-19 12:27:36 +0530510 vos_timer_stop( &pHddTdlsCtx->peerDiscoverTimer);
511
512 vos_timer_stop( &pHddTdlsCtx->peerUpdateTimer);
513
514 memcpy(&pHddTdlsCtx->threshold_config, config, sizeof(tdls_config_params_t));
515
516 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
517 "iw set tdls params: %d %d %d %d %d %d",
518 pHddTdlsCtx->threshold_config.tx_period_t,
519 pHddTdlsCtx->threshold_config.tx_packet_n,
520 pHddTdlsCtx->threshold_config.discovery_period_t,
521 pHddTdlsCtx->threshold_config.discovery_tries_n,
522 pHddTdlsCtx->threshold_config.rx_timeout_t,
523 pHddTdlsCtx->threshold_config.rssi_hysteresis);
524
525 vos_timer_start( &pHddTdlsCtx->peerDiscoverTimer,
526 pHddTdlsCtx->threshold_config.discovery_period_t );
527
528 vos_timer_start( &pHddTdlsCtx->peerUpdateTimer,
529 pHddTdlsCtx->threshold_config.tx_period_t );
530 return 0;
531}
532
Kiran V1ccee932012-12-12 14:49:46 -0800533int wlan_hdd_saveTdlsPeer(tCsrRoamInfo *pRoamInfo)
534{
Chilam NG571c65a2013-01-19 12:27:36 +0530535 hddTdlsPeer_t *new_peer, *curr_peer;
Kiran V1ccee932012-12-12 14:49:46 -0800536 int i;
Chilam NG571c65a2013-01-19 12:27:36 +0530537 u8 key = 0;
Kiran V1ccee932012-12-12 14:49:46 -0800538
Hoonki Leebfee0342013-01-21 16:43:45 -0800539 if (NULL == pHddTdlsCtx) return -1;
540
Chilam NG571c65a2013-01-19 12:27:36 +0530541 for (i = 0; i < 6; i++)
542 key ^= pRoamInfo->peerMac[i];
Kiran V1ccee932012-12-12 14:49:46 -0800543
Chilam NG571c65a2013-01-19 12:27:36 +0530544 curr_peer = pHddTdlsCtx->peer_list[key];
Kiran V1ccee932012-12-12 14:49:46 -0800545
Chilam NG571c65a2013-01-19 12:27:36 +0530546 if (NULL == curr_peer) {
547 curr_peer = vos_mem_malloc(sizeof(hddTdlsPeer_t));
548
549 if (NULL == curr_peer) {
550 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
551 "saveTdlsPeer: NOT saving staId %d", pRoamInfo->staId);
552 return -1;
553 }
554 vos_mem_zero(curr_peer, sizeof(hddTdlsPeer_t));
555
556 INIT_LIST_HEAD(&curr_peer->node);
557 memcpy(curr_peer->peerMac, pRoamInfo->peerMac, 6);
558 curr_peer->staId = pRoamInfo->staId;
559 pHddTdlsCtx->peer_list[key] = curr_peer;
560
561 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Kiran V1ccee932012-12-12 14:49:46 -0800562 "saveTdlsPeer: saved staId %d", pRoamInfo->staId);
Chilam NG571c65a2013-01-19 12:27:36 +0530563 return 0;
Kiran V1ccee932012-12-12 14:49:46 -0800564 }
565
Chilam NG571c65a2013-01-19 12:27:36 +0530566 do {
567 if (!memcmp(pRoamInfo->peerMac, curr_peer->peerMac, 6)) goto known_peer;
568 curr_peer = (hddTdlsPeer_t *)curr_peer->node.next;
569 } while (&curr_peer->node != curr_peer->node.next);
570
571 new_peer = vos_mem_malloc(sizeof(hddTdlsPeer_t));
572 if (NULL == new_peer) {
573 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
574 "saveTdlsPeer: NOT saving staId %d", pRoamInfo->staId);
575 return -1;
576 }
577 vos_mem_zero(new_peer, sizeof(hddTdlsPeer_t));
578
579 list_add(&new_peer->node, &curr_peer->node);
580 curr_peer = new_peer;
581
582known_peer:
583 memcpy(curr_peer->peerMac, pRoamInfo->peerMac, 6);
584 curr_peer->staId = pRoamInfo->staId;
585
586 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
587 "saveTdlsPeer: saved staId %d", pRoamInfo->staId);
588
589 return 0;
Kiran V1ccee932012-12-12 14:49:46 -0800590}
591
592int wlan_hdd_findTdlsPeer(tSirMacAddr peerMac)
593{
594 int i;
Chilam NG571c65a2013-01-19 12:27:36 +0530595 hddTdlsPeer_t *curr_peer;
Kiran V1ccee932012-12-12 14:49:46 -0800596
Hoonki Leebfee0342013-01-21 16:43:45 -0800597 if (NULL == pHddTdlsCtx) return -1;
598
Chilam NG571c65a2013-01-19 12:27:36 +0530599 for (i = 0; i < 256; i++) {
600 curr_peer = pHddTdlsCtx->peer_list[i];
601 if (NULL == curr_peer) continue;
602
603 do {
604 if (!memcmp(peerMac, curr_peer->peerMac, 6)) {
605 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
606 "findTdlsPeer: found staId %d", curr_peer->staId);
607 return curr_peer->staId;
608 }
609
610 curr_peer = (hddTdlsPeer_t *)curr_peer->node.next;
611 } while (&curr_peer->node != curr_peer->node.next);
Kiran V1ccee932012-12-12 14:49:46 -0800612 }
613
Chilam NG571c65a2013-01-19 12:27:36 +0530614 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
615 "findTdlsPeer: staId NOT found");
Kiran V1ccee932012-12-12 14:49:46 -0800616
Kiran V1ccee932012-12-12 14:49:46 -0800617 return -1;
618}
Chilam NG571c65a2013-01-19 12:27:36 +0530619
620void wlan_hdd_removeTdlsPeer(tCsrRoamInfo *pRoamInfo)
621{
622 int i;
623 hddTdlsPeer_t *curr_peer;
624
Hoonki Leebfee0342013-01-21 16:43:45 -0800625 if (NULL == pHddTdlsCtx) return;
626
Chilam NG571c65a2013-01-19 12:27:36 +0530627 for (i = 0; i < 256; i++) {
628
629 curr_peer = pHddTdlsCtx->peer_list[i];
630
631 if (NULL == curr_peer) continue;
632
633 do {
634 if (curr_peer->staId == pRoamInfo->staId) goto found_peer;
635
636 curr_peer = (hddTdlsPeer_t *)curr_peer->node.next;
637 } while (&curr_peer->node != curr_peer->node.next);
638 }
639
640 if (i == 256) return;
641
642found_peer:
Hoonki Leecdd8e962013-01-20 00:45:46 -0800643 curr_peer->link_status = eTDLS_LINK_NOT_CONNECTED;
644 curr_peer->staId = 0;
645 curr_peer->rssi = -120;
646}
647
648void wlan_hdd_freeTdlsPeer(void)
649{
650 int i;
651 hddTdlsPeer_t *curr_peer;
652 hddTdlsPeer_t *temp_peer;
653
Hoonki Leebfee0342013-01-21 16:43:45 -0800654 if (NULL == pHddTdlsCtx) return;
655
Hoonki Leecdd8e962013-01-20 00:45:46 -0800656 for (i = 0; i < 256; i++) {
657
658 curr_peer = pHddTdlsCtx->peer_list[i];
659
660 if (NULL != curr_peer) {
Hoonki Leebfee0342013-01-21 16:43:45 -0800661 while (&curr_peer->node != curr_peer->node.next) {
Hoonki Leecdd8e962013-01-20 00:45:46 -0800662 temp_peer = curr_peer;
663 curr_peer = (hddTdlsPeer_t *)curr_peer->node.next;
664 vos_mem_free(temp_peer);
Hoonki Leebfee0342013-01-21 16:43:45 -0800665 }
666 vos_mem_free(curr_peer);
Hoonki Leecdd8e962013-01-20 00:45:46 -0800667 }
668 }
Chilam NG571c65a2013-01-19 12:27:36 +0530669}