Commit | Line | Data |
---|---|---|
d4317252 AN |
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 | ||
67 | void 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 | ||
89 | int 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 | ||
307e4723 AN |
116 | static void iwl_mvm_tdls_config(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
117 | { | |
118 | struct iwl_rx_packet *pkt; | |
119 | struct iwl_tdls_config_res *resp; | |
120 | struct iwl_tdls_config_cmd tdls_cfg_cmd = {}; | |
121 | struct iwl_host_cmd cmd = { | |
122 | .id = TDLS_CONFIG_CMD, | |
123 | .flags = CMD_WANT_SKB, | |
124 | .data = { &tdls_cfg_cmd, }, | |
125 | .len = { sizeof(struct iwl_tdls_config_cmd), }, | |
126 | }; | |
127 | struct ieee80211_sta *sta; | |
128 | int ret, i, cnt; | |
129 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
130 | ||
131 | lockdep_assert_held(&mvm->mutex); | |
132 | ||
133 | tdls_cfg_cmd.id_and_color = | |
134 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)); | |
135 | tdls_cfg_cmd.tx_to_ap_tid = IWL_MVM_TDLS_FW_TID; | |
136 | tdls_cfg_cmd.tx_to_ap_ssn = cpu_to_le16(0); /* not used for now */ | |
137 | ||
138 | /* for now the Tx cmd is empty and unused */ | |
139 | ||
140 | /* populate TDLS peer data */ | |
141 | cnt = 0; | |
142 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { | |
143 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], | |
144 | lockdep_is_held(&mvm->mutex)); | |
145 | if (IS_ERR_OR_NULL(sta) || !sta->tdls) | |
146 | continue; | |
147 | ||
148 | tdls_cfg_cmd.sta_info[cnt].sta_id = i; | |
149 | tdls_cfg_cmd.sta_info[cnt].tx_to_peer_tid = | |
150 | IWL_MVM_TDLS_FW_TID; | |
151 | tdls_cfg_cmd.sta_info[cnt].tx_to_peer_ssn = cpu_to_le16(0); | |
152 | tdls_cfg_cmd.sta_info[cnt].is_initiator = | |
153 | cpu_to_le32(sta->tdls_initiator ? 1 : 0); | |
154 | ||
155 | cnt++; | |
156 | } | |
157 | ||
158 | tdls_cfg_cmd.tdls_peer_count = cnt; | |
159 | IWL_DEBUG_TDLS(mvm, "send TDLS config to FW for %d peers\n", cnt); | |
160 | ||
161 | ret = iwl_mvm_send_cmd(mvm, &cmd); | |
162 | if (WARN_ON_ONCE(ret)) | |
163 | return; | |
164 | ||
165 | pkt = cmd.resp_pkt; | |
166 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { | |
167 | IWL_ERR(mvm, "Bad return from TDLS_CONFIG_COMMAND (0x%08X)\n", | |
168 | pkt->hdr.flags); | |
169 | goto exit; | |
170 | } | |
171 | ||
172 | if (WARN_ON_ONCE(iwl_rx_packet_payload_len(pkt) != sizeof(*resp))) | |
173 | goto exit; | |
174 | ||
175 | /* we don't really care about the response at this point */ | |
176 | ||
177 | exit: | |
178 | iwl_free_resp(&cmd); | |
179 | } | |
180 | ||
d4317252 AN |
181 | void iwl_mvm_recalc_tdls_state(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
182 | bool sta_added) | |
183 | { | |
184 | int tdls_sta_cnt = iwl_mvm_tdls_sta_count(mvm, vif); | |
185 | ||
307e4723 AN |
186 | /* when the first peer joins, send a power update first */ |
187 | if (tdls_sta_cnt == 1 && sta_added) | |
188 | iwl_mvm_power_update_mac(mvm); | |
189 | ||
190 | /* configure the FW with TDLS peer info */ | |
191 | iwl_mvm_tdls_config(mvm, vif); | |
192 | ||
193 | /* when the last peer leaves, send a power update last */ | |
194 | if (tdls_sta_cnt == 0 && !sta_added) | |
d4317252 AN |
195 | iwl_mvm_power_update_mac(mvm); |
196 | } | |
197 | ||
198 | void iwl_mvm_mac_mgd_protect_tdls_discover(struct ieee80211_hw *hw, | |
199 | struct ieee80211_vif *vif) | |
200 | { | |
201 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
202 | u32 duration = 2 * vif->bss_conf.dtim_period * vif->bss_conf.beacon_int; | |
203 | ||
204 | /* | |
205 | * iwl_mvm_protect_session() reads directly from the device | |
206 | * (the system time), so make sure it is available. | |
207 | */ | |
208 | if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_TDLS)) | |
209 | return; | |
210 | ||
211 | mutex_lock(&mvm->mutex); | |
212 | /* Protect the session to hear the TDLS setup response on the channel */ | |
213 | iwl_mvm_protect_session(mvm, vif, duration, duration, 100, true); | |
214 | mutex_unlock(&mvm->mutex); | |
215 | ||
216 | iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_TDLS); | |
217 | } |