Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 1 | /* |
Gopichand Nakkala | 0c1331e | 2013-01-07 22:49:07 -0800 | [diff] [blame] | 2 | * 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 V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 21 | |
| 22 | /**======================================================================== |
| 23 | |
| 24 | \file wlan_hdd_tdls.c |
| 25 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 26 | \brief WLAN Host Device Driver implementation for TDLS |
Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 27 | |
Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 28 | ========================================================================*/ |
| 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 NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 35 | #include <linux/list.h> |
Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 36 | #include <linux/etherdevice.h> |
| 37 | #include <net/ieee80211_radiotap.h> |
| 38 | #include "wlan_hdd_tdls.h" |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 39 | #include "wlan_hdd_cfg80211.h" |
Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 40 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 41 | |
| 42 | typedef struct { |
| 43 | struct list_head node; |
Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 44 | tSirMacAddr peerMac; |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 45 | 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 V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 52 | |
Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 53 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 54 | typedef 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 | |
| 65 | tdlsCtx_t *pHddTdlsCtx; |
| 66 | |
Hoonki Lee | cdd8e96 | 2013-01-20 00:45:46 -0800 | [diff] [blame] | 67 | void wlan_hdd_freeTdlsPeer(void); |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 68 | |
| 69 | static v_VOID_t wlan_hdd_discover_peer_cb( v_PVOID_t userData ) |
Hoonki Lee | f63df0d | 2013-01-16 19:29:14 -0800 | [diff] [blame] | 70 | { |
| 71 | int i; |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 72 | hddTdlsPeer_t *curr_peer; |
Hoonki Lee | bfee034 | 2013-01-21 16:43:45 -0800 | [diff] [blame^] | 73 | 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 Lee | f63df0d | 2013-01-16 19:29:14 -0800 | [diff] [blame] | 80 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 81 | 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 Lee | f63df0d | 2013-01-16 19:29:14 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 113 | 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 Lee | f63df0d | 2013-01-16 19:29:14 -0800 | [diff] [blame] | 120 | } |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 121 | |
| 122 | static v_VOID_t wlan_hdd_update_peer_cb( v_PVOID_t userData ) |
| 123 | { |
| 124 | int i; |
| 125 | hddTdlsPeer_t *curr_peer; |
| 126 | |
Hoonki Lee | bfee034 | 2013-01-21 16:43:45 -0800 | [diff] [blame^] | 127 | if (NULL == pHddTdlsCtx) return; |
| 128 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 129 | 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 Lee | cdd8e96 | 2013-01-20 00:45:46 -0800 | [diff] [blame] | 154 | goto next_peer; |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 155 | } |
| 156 | |
Hoonki Lee | cdd8e96 | 2013-01-20 00:45:46 -0800 | [diff] [blame] | 157 | if ((tANI_S32)curr_peer->rssi > |
| 158 | (tANI_S32)(pHddTdlsCtx->threshold_config.rssi_hysteresis + |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 159 | 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 Lee | cdd8e96 | 2013-01-20 00:45:46 -0800 | [diff] [blame] | 172 | if (curr_peer->tx_pkt < |
| 173 | pHddTdlsCtx->threshold_config.tx_packet_n) { |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 174 | cfg80211_tdls_oper_request(pHddTdlsCtx->dev, |
| 175 | curr_peer->peerMac, |
| 176 | NL80211_TDLS_TEARDOWN, FALSE, |
| 177 | GFP_KERNEL); |
Hoonki Lee | cdd8e96 | 2013-01-20 00:45:46 -0800 | [diff] [blame] | 178 | |
| 179 | goto next_peer; |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 180 | } |
Hoonki Lee | cdd8e96 | 2013-01-20 00:45:46 -0800 | [diff] [blame] | 181 | |
| 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 NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
Hoonki Lee | cdd8e96 | 2013-01-20 00:45:46 -0800 | [diff] [blame] | 196 | next_peer: |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 197 | 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 | |
| 207 | int wlan_hdd_tdls_init(struct net_device *dev) |
| 208 | { |
| 209 | VOS_STATUS status; |
Hoonki Lee | bf870f3 | 2013-01-19 15:53:30 +0530 | [diff] [blame] | 210 | hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 211 | hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter ); |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 212 | |
Hoonki Lee | bf870f3 | 2013-01-19 15:53:30 +0530 | [diff] [blame] | 213 | 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 NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 220 | 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 Lee | bf870f3 | 2013-01-19 15:53:30 +0530 | [diff] [blame] | 229 | 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 NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 240 | |
| 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 | |
| 260 | void wlan_hdd_tdls_exit() |
| 261 | { |
Hoonki Lee | bfee034 | 2013-01-21 16:43:45 -0800 | [diff] [blame^] | 262 | 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 Lee | cdd8e96 | 2013-01-20 00:45:46 -0800 | [diff] [blame] | 282 | |
| 283 | wlan_hdd_freeTdlsPeer(); |
| 284 | if(pHddTdlsCtx) |
| 285 | vos_mem_free(pHddTdlsCtx); |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | int 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 Lee | bfee034 | 2013-01-21 16:43:45 -0800 | [diff] [blame^] | 294 | if (NULL == pHddTdlsCtx) return -1; |
| 295 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 296 | 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 | |
| 314 | found_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 | |
| 324 | int wlan_hdd_tdls_set_cap(u8 *mac, int cap) |
| 325 | { |
| 326 | hddTdlsPeer_t *curr_peer; |
| 327 | int i; |
| 328 | u8 key = 0; |
| 329 | |
Hoonki Lee | bfee034 | 2013-01-21 16:43:45 -0800 | [diff] [blame^] | 330 | if (NULL == pHddTdlsCtx) return -1; |
| 331 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 332 | 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 | |
| 368 | found_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 | |
| 378 | int 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 Lee | bfee034 | 2013-01-21 16:43:45 -0800 | [diff] [blame^] | 384 | if (NULL == pHddTdlsCtx) return -1; |
| 385 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 386 | 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 | |
| 422 | found_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 | |
| 432 | u8 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 | |
| 444 | int wlan_hdd_tdls_add_peer_to_list(u8 key, u8 *mac) |
| 445 | { |
| 446 | hddTdlsPeer_t *new_peer, *curr_peer; |
| 447 | |
Hoonki Lee | bfee034 | 2013-01-21 16:43:45 -0800 | [diff] [blame^] | 448 | if (NULL == pHddTdlsCtx) return -1; |
| 449 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 450 | 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 | |
| 495 | known_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 | |
| 506 | int wlan_hdd_tdls_set_params(tdls_config_params_t *config) |
| 507 | { |
Hoonki Lee | bfee034 | 2013-01-21 16:43:45 -0800 | [diff] [blame^] | 508 | if (NULL == pHddTdlsCtx) return -1; |
| 509 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 510 | 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 V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 533 | int wlan_hdd_saveTdlsPeer(tCsrRoamInfo *pRoamInfo) |
| 534 | { |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 535 | hddTdlsPeer_t *new_peer, *curr_peer; |
Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 536 | int i; |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 537 | u8 key = 0; |
Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 538 | |
Hoonki Lee | bfee034 | 2013-01-21 16:43:45 -0800 | [diff] [blame^] | 539 | if (NULL == pHddTdlsCtx) return -1; |
| 540 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 541 | for (i = 0; i < 6; i++) |
| 542 | key ^= pRoamInfo->peerMac[i]; |
Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 543 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 544 | curr_peer = pHddTdlsCtx->peer_list[key]; |
Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 545 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 546 | 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 V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 562 | "saveTdlsPeer: saved staId %d", pRoamInfo->staId); |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 563 | return 0; |
Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 564 | } |
| 565 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 566 | 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 | |
| 582 | known_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 V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | int wlan_hdd_findTdlsPeer(tSirMacAddr peerMac) |
| 593 | { |
| 594 | int i; |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 595 | hddTdlsPeer_t *curr_peer; |
Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 596 | |
Hoonki Lee | bfee034 | 2013-01-21 16:43:45 -0800 | [diff] [blame^] | 597 | if (NULL == pHddTdlsCtx) return -1; |
| 598 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 599 | 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 V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 612 | } |
| 613 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 614 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 615 | "findTdlsPeer: staId NOT found"); |
Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 616 | |
Kiran V | 1ccee93 | 2012-12-12 14:49:46 -0800 | [diff] [blame] | 617 | return -1; |
| 618 | } |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 619 | |
| 620 | void wlan_hdd_removeTdlsPeer(tCsrRoamInfo *pRoamInfo) |
| 621 | { |
| 622 | int i; |
| 623 | hddTdlsPeer_t *curr_peer; |
| 624 | |
Hoonki Lee | bfee034 | 2013-01-21 16:43:45 -0800 | [diff] [blame^] | 625 | if (NULL == pHddTdlsCtx) return; |
| 626 | |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 627 | 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 | |
| 642 | found_peer: |
Hoonki Lee | cdd8e96 | 2013-01-20 00:45:46 -0800 | [diff] [blame] | 643 | curr_peer->link_status = eTDLS_LINK_NOT_CONNECTED; |
| 644 | curr_peer->staId = 0; |
| 645 | curr_peer->rssi = -120; |
| 646 | } |
| 647 | |
| 648 | void wlan_hdd_freeTdlsPeer(void) |
| 649 | { |
| 650 | int i; |
| 651 | hddTdlsPeer_t *curr_peer; |
| 652 | hddTdlsPeer_t *temp_peer; |
| 653 | |
Hoonki Lee | bfee034 | 2013-01-21 16:43:45 -0800 | [diff] [blame^] | 654 | if (NULL == pHddTdlsCtx) return; |
| 655 | |
Hoonki Lee | cdd8e96 | 2013-01-20 00:45:46 -0800 | [diff] [blame] | 656 | for (i = 0; i < 256; i++) { |
| 657 | |
| 658 | curr_peer = pHddTdlsCtx->peer_list[i]; |
| 659 | |
| 660 | if (NULL != curr_peer) { |
Hoonki Lee | bfee034 | 2013-01-21 16:43:45 -0800 | [diff] [blame^] | 661 | while (&curr_peer->node != curr_peer->node.next) { |
Hoonki Lee | cdd8e96 | 2013-01-20 00:45:46 -0800 | [diff] [blame] | 662 | temp_peer = curr_peer; |
| 663 | curr_peer = (hddTdlsPeer_t *)curr_peer->node.next; |
| 664 | vos_mem_free(temp_peer); |
Hoonki Lee | bfee034 | 2013-01-21 16:43:45 -0800 | [diff] [blame^] | 665 | } |
| 666 | vos_mem_free(curr_peer); |
Hoonki Lee | cdd8e96 | 2013-01-20 00:45:46 -0800 | [diff] [blame] | 667 | } |
| 668 | } |
Chilam NG | 571c65a | 2013-01-19 12:27:36 +0530 | [diff] [blame] | 669 | } |