1/****************************************************************************** 2 * 3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * redistributing this file, you may do so under either license. 5 * 6 * GPL LICENSE SUMMARY 7 * 8 * Copyright(c) 2014 Intel Mobile Communications GmbH 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of version 2 of the GNU General Public License as 12 * published by the Free Software Foundation. 13 * 14 * This program is distributed in the hope that it will be useful, but 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, 22 * USA 23 * 24 * The full GNU General Public License is included in this distribution 25 * in the file called COPYING. 26 * 27 * Contact Information: 28 * Intel Linux Wireless <ilw@linux.intel.com> 29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 30 * 31 * BSD LICENSE 32 * 33 * Copyright(c) 2014 Intel Mobile Communications GmbH 34 * All rights reserved. 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions 38 * are met: 39 * 40 * * Redistributions of source code must retain the above copyright 41 * notice, this list of conditions and the following disclaimer. 42 * * Redistributions in binary form must reproduce the above copyright 43 * notice, this list of conditions and the following disclaimer in 44 * the documentation and/or other materials provided with the 45 * distribution. 46 * * Neither the name Intel Corporation nor the names of its 47 * contributors may be used to endorse or promote products derived 48 * from this software without specific prior written permission. 49 * 50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 61 * 62 *****************************************************************************/ 63 64#include "mvm.h" 65#include "time-event.h" 66 67void iwl_mvm_teardown_tdls_peers(struct iwl_mvm *mvm) 68{ 69 struct ieee80211_sta *sta; 70 struct iwl_mvm_sta *mvmsta; 71 int i; 72 73 lockdep_assert_held(&mvm->mutex); 74 75 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { 76 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 77 lockdep_is_held(&mvm->mutex)); 78 if (!sta || IS_ERR(sta) || !sta->tdls) 79 continue; 80 81 mvmsta = iwl_mvm_sta_from_mac80211(sta); 82 ieee80211_tdls_oper_request(mvmsta->vif, sta->addr, 83 NL80211_TDLS_TEARDOWN, 84 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED, 85 GFP_KERNEL); 86 } 87} 88 89int iwl_mvm_tdls_sta_count(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 90{ 91 struct ieee80211_sta *sta; 92 struct iwl_mvm_sta *mvmsta; 93 int count = 0; 94 int i; 95 96 lockdep_assert_held(&mvm->mutex); 97 98 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { 99 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 100 lockdep_is_held(&mvm->mutex)); 101 if (!sta || IS_ERR(sta) || !sta->tdls) 102 continue; 103 104 if (vif) { 105 mvmsta = iwl_mvm_sta_from_mac80211(sta); 106 if (mvmsta->vif != vif) 107 continue; 108 } 109 110 count++; 111 } 112 113 return count; 114} 115 116void iwl_mvm_recalc_tdls_state(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 117 bool sta_added) 118{ 119 int tdls_sta_cnt = iwl_mvm_tdls_sta_count(mvm, vif); 120 121 /* 122 * Disable ps when the first TDLS sta is added and re-enable it 123 * when the last TDLS sta is removed 124 */ 125 if ((tdls_sta_cnt == 1 && sta_added) || 126 (tdls_sta_cnt == 0 && !sta_added)) 127 iwl_mvm_power_update_mac(mvm); 128} 129 130void iwl_mvm_mac_mgd_protect_tdls_discover(struct ieee80211_hw *hw, 131 struct ieee80211_vif *vif) 132{ 133 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 134 u32 duration = 2 * vif->bss_conf.dtim_period * vif->bss_conf.beacon_int; 135 136 /* 137 * iwl_mvm_protect_session() reads directly from the device 138 * (the system time), so make sure it is available. 139 */ 140 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_TDLS)) 141 return; 142 143 mutex_lock(&mvm->mutex); 144 /* Protect the session to hear the TDLS setup response on the channel */ 145 iwl_mvm_protect_session(mvm, vif, duration, duration, 100, true); 146 mutex_unlock(&mvm->mutex); 147 148 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_TDLS); 149} 150