blob: aee701a5649e59ebd03ef300f25e33eadfc280d5 [file] [log] [blame]
Arik Nemtsov95224fe2014-05-01 10:17:28 +03001/*
2 * mac80211 TDLS handling code
3 *
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2014, Intel Corporation
Johannes Bergd98ad832014-09-03 15:24:57 +03006 * Copyright 2014 Intel Mobile Communications GmbH
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03007 * Copyright 2015 Intel Deutschland GmbH
Arik Nemtsov95224fe2014-05-01 10:17:28 +03008 *
9 * This file is GPLv2 as found in COPYING.
10 */
11
12#include <linux/ieee80211.h>
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +030013#include <linux/log2.h>
Arik Nemtsovc887f0d32014-06-11 17:18:25 +030014#include <net/cfg80211.h>
Arik Nemtsovc8ff71e2015-07-08 15:41:45 +030015#include <linux/rtnetlink.h>
Arik Nemtsov95224fe2014-05-01 10:17:28 +030016#include "ieee80211_i.h"
Arik Nemtsovee10f2c2014-06-11 17:18:27 +030017#include "driver-ops.h"
Arik Nemtsov95224fe2014-05-01 10:17:28 +030018
Arik Nemtsov17e6a592014-06-11 17:18:20 +030019/* give usermode some time for retries in setting up the TDLS session */
20#define TDLS_PEER_SETUP_TIMEOUT (15 * HZ)
21
22void ieee80211_tdls_peer_del_work(struct work_struct *wk)
23{
24 struct ieee80211_sub_if_data *sdata;
25 struct ieee80211_local *local;
26
27 sdata = container_of(wk, struct ieee80211_sub_if_data,
Arik Nemtsov81dd2b82014-07-17 17:14:25 +030028 u.mgd.tdls_peer_del_work.work);
Arik Nemtsov17e6a592014-06-11 17:18:20 +030029 local = sdata->local;
30
31 mutex_lock(&local->mtx);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +030032 if (!is_zero_ether_addr(sdata->u.mgd.tdls_peer)) {
33 tdls_dbg(sdata, "TDLS del peer %pM\n", sdata->u.mgd.tdls_peer);
34 sta_info_destroy_addr(sdata, sdata->u.mgd.tdls_peer);
35 eth_zero_addr(sdata->u.mgd.tdls_peer);
Arik Nemtsov17e6a592014-06-11 17:18:20 +030036 }
37 mutex_unlock(&local->mtx);
38}
39
Arik Nemtsovb98fb442015-06-10 20:42:59 +030040static void ieee80211_tdls_add_ext_capab(struct ieee80211_sub_if_data *sdata,
Arik Nemtsov78632a12014-11-09 18:50:14 +020041 struct sk_buff *skb)
Arik Nemtsov95224fe2014-05-01 10:17:28 +030042{
Arik Nemtsovb98fb442015-06-10 20:42:59 +030043 struct ieee80211_local *local = sdata->local;
Arik Nemtsov78632a12014-11-09 18:50:14 +020044 bool chan_switch = local->hw.wiphy->features &
45 NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
Arik Nemtsovb98fb442015-06-10 20:42:59 +030046 bool wider_band = ieee80211_hw_check(&local->hw, TDLS_WIDER_BW);
47 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
48 struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
49 bool vht = sband && sband->vht_cap.vht_supported;
50 u8 *pos = (void *)skb_put(skb, 10);
Arik Nemtsov95224fe2014-05-01 10:17:28 +030051
52 *pos++ = WLAN_EID_EXT_CAPABILITY;
Arik Nemtsovb98fb442015-06-10 20:42:59 +030053 *pos++ = 8; /* len */
Arik Nemtsov95224fe2014-05-01 10:17:28 +030054 *pos++ = 0x0;
55 *pos++ = 0x0;
56 *pos++ = 0x0;
Arik Nemtsov78632a12014-11-09 18:50:14 +020057 *pos++ = chan_switch ? WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH : 0;
Arik Nemtsov95224fe2014-05-01 10:17:28 +030058 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
Arik Nemtsovb98fb442015-06-10 20:42:59 +030059 *pos++ = 0;
60 *pos++ = 0;
61 *pos++ = (vht && wider_band) ? WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED : 0;
Arik Nemtsov95224fe2014-05-01 10:17:28 +030062}
63
Arik Nemtsovf0d29cb2014-11-09 18:50:12 +020064static u8
65ieee80211_tdls_add_subband(struct ieee80211_sub_if_data *sdata,
66 struct sk_buff *skb, u16 start, u16 end,
67 u16 spacing)
68{
69 u8 subband_cnt = 0, ch_cnt = 0;
70 struct ieee80211_channel *ch;
71 struct cfg80211_chan_def chandef;
72 int i, subband_start;
Arik Nemtsov923b3522015-07-08 15:41:44 +030073 struct wiphy *wiphy = sdata->local->hw.wiphy;
Arik Nemtsovf0d29cb2014-11-09 18:50:12 +020074
75 for (i = start; i <= end; i += spacing) {
76 if (!ch_cnt)
77 subband_start = i;
78
79 ch = ieee80211_get_channel(sdata->local->hw.wiphy, i);
80 if (ch) {
81 /* we will be active on the channel */
Arik Nemtsovf0d29cb2014-11-09 18:50:12 +020082 cfg80211_chandef_create(&chandef, ch,
Arik Nemtsov50075892015-01-07 16:45:07 +020083 NL80211_CHAN_NO_HT);
Arik Nemtsov923b3522015-07-08 15:41:44 +030084 if (cfg80211_reg_can_beacon_relax(wiphy, &chandef,
85 sdata->wdev.iftype)) {
Arik Nemtsovf0d29cb2014-11-09 18:50:12 +020086 ch_cnt++;
Arik Nemtsov50075892015-01-07 16:45:07 +020087 /*
88 * check if the next channel is also part of
89 * this allowed range
90 */
Arik Nemtsovf0d29cb2014-11-09 18:50:12 +020091 continue;
92 }
93 }
94
Arik Nemtsov50075892015-01-07 16:45:07 +020095 /*
96 * we've reached the end of a range, with allowed channels
97 * found
98 */
Arik Nemtsovf0d29cb2014-11-09 18:50:12 +020099 if (ch_cnt) {
100 u8 *pos = skb_put(skb, 2);
101 *pos++ = ieee80211_frequency_to_channel(subband_start);
102 *pos++ = ch_cnt;
103
104 subband_cnt++;
105 ch_cnt = 0;
106 }
107 }
108
Arik Nemtsov50075892015-01-07 16:45:07 +0200109 /* all channels in the requested range are allowed - add them here */
110 if (ch_cnt) {
111 u8 *pos = skb_put(skb, 2);
112 *pos++ = ieee80211_frequency_to_channel(subband_start);
113 *pos++ = ch_cnt;
114
115 subband_cnt++;
116 }
117
Arik Nemtsovf0d29cb2014-11-09 18:50:12 +0200118 return subband_cnt;
119}
120
121static void
122ieee80211_tdls_add_supp_channels(struct ieee80211_sub_if_data *sdata,
123 struct sk_buff *skb)
124{
125 /*
126 * Add possible channels for TDLS. These are channels that are allowed
127 * to be active.
128 */
129 u8 subband_cnt;
130 u8 *pos = skb_put(skb, 2);
131
132 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
133
134 /*
135 * 5GHz and 2GHz channels numbers can overlap. Ignore this for now, as
136 * this doesn't happen in real world scenarios.
137 */
138
139 /* 2GHz, with 5MHz spacing */
140 subband_cnt = ieee80211_tdls_add_subband(sdata, skb, 2412, 2472, 5);
141
142 /* 5GHz, with 20MHz spacing */
143 subband_cnt += ieee80211_tdls_add_subband(sdata, skb, 5000, 5825, 20);
144
145 /* length */
146 *pos = 2 * subband_cnt;
147}
148
Arik Nemtsova38700d2015-03-18 08:46:08 +0200149static void ieee80211_tdls_add_oper_classes(struct ieee80211_sub_if_data *sdata,
150 struct sk_buff *skb)
151{
152 u8 *pos;
153 u8 op_class;
154
155 if (!ieee80211_chandef_to_operating_class(&sdata->vif.bss_conf.chandef,
156 &op_class))
157 return;
158
159 pos = skb_put(skb, 4);
160 *pos++ = WLAN_EID_SUPPORTED_REGULATORY_CLASSES;
161 *pos++ = 2; /* len */
162
163 *pos++ = op_class;
164 *pos++ = op_class; /* give current operating class as alternate too */
165}
166
Arik Nemtsov2cedd872014-11-09 18:50:13 +0200167static void ieee80211_tdls_add_bss_coex_ie(struct sk_buff *skb)
168{
169 u8 *pos = (void *)skb_put(skb, 3);
170
171 *pos++ = WLAN_EID_BSS_COEX_2040;
172 *pos++ = 1; /* len */
173
174 *pos++ = WLAN_BSS_COEX_INFORMATION_REQUEST;
175}
176
Arik Nemtsovdd8c0b02014-07-17 17:14:22 +0300177static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata,
178 u16 status_code)
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300179{
Arik Nemtsovdd8c0b02014-07-17 17:14:22 +0300180 /* The capability will be 0 when sending a failure code */
181 if (status_code != 0)
182 return 0;
183
Johannes Bergea1b2b452015-06-02 20:15:49 +0200184 if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_2GHZ) {
185 return WLAN_CAPABILITY_SHORT_SLOT_TIME |
186 WLAN_CAPABILITY_SHORT_PREAMBLE;
187 }
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300188
Johannes Bergea1b2b452015-06-02 20:15:49 +0200189 return 0;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300190}
191
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300192static void ieee80211_tdls_add_link_ie(struct ieee80211_sub_if_data *sdata,
193 struct sk_buff *skb, const u8 *peer,
194 bool initiator)
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300195{
196 struct ieee80211_tdls_lnkie *lnkid;
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300197 const u8 *init_addr, *rsp_addr;
198
199 if (initiator) {
200 init_addr = sdata->vif.addr;
201 rsp_addr = peer;
202 } else {
203 init_addr = peer;
204 rsp_addr = sdata->vif.addr;
205 }
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300206
207 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
208
209 lnkid->ie_type = WLAN_EID_LINK_ID;
210 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
211
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300212 memcpy(lnkid->bssid, sdata->u.mgd.bssid, ETH_ALEN);
213 memcpy(lnkid->init_sta, init_addr, ETH_ALEN);
214 memcpy(lnkid->resp_sta, rsp_addr, ETH_ALEN);
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300215}
216
Arik Nemtsovfb28ec02015-03-01 09:10:02 +0200217static void
218ieee80211_tdls_add_aid(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
219{
220 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
221 u8 *pos = (void *)skb_put(skb, 4);
222
223 *pos++ = WLAN_EID_AID;
224 *pos++ = 2; /* len */
225 put_unaligned_le16(ifmgd->aid, pos);
226}
227
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300228/* translate numbering in the WMM parameter IE to the mac80211 notation */
229static enum ieee80211_ac_numbers ieee80211_ac_from_wmm(int ac)
230{
231 switch (ac) {
232 default:
233 WARN_ON_ONCE(1);
234 case 0:
235 return IEEE80211_AC_BE;
236 case 1:
237 return IEEE80211_AC_BK;
238 case 2:
239 return IEEE80211_AC_VI;
240 case 3:
241 return IEEE80211_AC_VO;
242 }
243}
244
245static u8 ieee80211_wmm_aci_aifsn(int aifsn, bool acm, int aci)
246{
247 u8 ret;
248
249 ret = aifsn & 0x0f;
250 if (acm)
251 ret |= 0x10;
252 ret |= (aci << 5) & 0x60;
253 return ret;
254}
255
256static u8 ieee80211_wmm_ecw(u16 cw_min, u16 cw_max)
257{
258 return ((ilog2(cw_min + 1) << 0x0) & 0x0f) |
259 ((ilog2(cw_max + 1) << 0x4) & 0xf0);
260}
261
262static void ieee80211_tdls_add_wmm_param_ie(struct ieee80211_sub_if_data *sdata,
263 struct sk_buff *skb)
264{
265 struct ieee80211_wmm_param_ie *wmm;
266 struct ieee80211_tx_queue_params *txq;
267 int i;
268
269 wmm = (void *)skb_put(skb, sizeof(*wmm));
270 memset(wmm, 0, sizeof(*wmm));
271
272 wmm->element_id = WLAN_EID_VENDOR_SPECIFIC;
273 wmm->len = sizeof(*wmm) - 2;
274
275 wmm->oui[0] = 0x00; /* Microsoft OUI 00:50:F2 */
276 wmm->oui[1] = 0x50;
277 wmm->oui[2] = 0xf2;
278 wmm->oui_type = 2; /* WME */
279 wmm->oui_subtype = 1; /* WME param */
280 wmm->version = 1; /* WME ver */
281 wmm->qos_info = 0; /* U-APSD not in use */
282
283 /*
284 * Use the EDCA parameters defined for the BSS, or default if the AP
285 * doesn't support it, as mandated by 802.11-2012 section 10.22.4
286 */
287 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
288 txq = &sdata->tx_conf[ieee80211_ac_from_wmm(i)];
289 wmm->ac[i].aci_aifsn = ieee80211_wmm_aci_aifsn(txq->aifs,
290 txq->acm, i);
291 wmm->ac[i].cw = ieee80211_wmm_ecw(txq->cw_min, txq->cw_max);
292 wmm->ac[i].txop_limit = cpu_to_le16(txq->txop);
293 }
294}
295
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300296static void
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +0300297ieee80211_tdls_chandef_vht_upgrade(struct ieee80211_sub_if_data *sdata,
298 struct sta_info *sta)
299{
300 /* IEEE802.11ac-2013 Table E-4 */
301 u16 centers_80mhz[] = { 5210, 5290, 5530, 5610, 5690, 5775 };
302 struct cfg80211_chan_def uc = sta->tdls_chandef;
303 enum nl80211_chan_width max_width = ieee80211_get_sta_bw(&sta->sta);
304 int i;
305
306 /* only support upgrading non-narrow channels up to 80Mhz */
307 if (max_width == NL80211_CHAN_WIDTH_5 ||
308 max_width == NL80211_CHAN_WIDTH_10)
309 return;
310
311 if (max_width > NL80211_CHAN_WIDTH_80)
312 max_width = NL80211_CHAN_WIDTH_80;
313
314 if (uc.width == max_width)
315 return;
316 /*
317 * Channel usage constrains in the IEEE802.11ac-2013 specification only
318 * allow expanding a 20MHz channel to 80MHz in a single way. In
319 * addition, there are no 40MHz allowed channels that are not part of
320 * the allowed 80MHz range in the 5GHz spectrum (the relevant one here).
321 */
322 for (i = 0; i < ARRAY_SIZE(centers_80mhz); i++)
323 if (abs(uc.chan->center_freq - centers_80mhz[i]) <= 30) {
324 uc.center_freq1 = centers_80mhz[i];
325 uc.width = NL80211_CHAN_WIDTH_80;
326 break;
327 }
328
329 if (!uc.center_freq1)
330 return;
331
332 /* proceed to downgrade the chandef until usable or the same */
333 while (uc.width > max_width &&
334 !cfg80211_reg_can_beacon(sdata->local->hw.wiphy,
335 &uc, sdata->wdev.iftype))
336 ieee80211_chandef_downgrade(&uc);
337
338 if (!cfg80211_chandef_identical(&uc, &sta->tdls_chandef)) {
339 tdls_dbg(sdata, "TDLS ch width upgraded %d -> %d\n",
340 sta->tdls_chandef.width, uc.width);
341
342 /*
343 * the station is not yet authorized when BW upgrade is done,
344 * locking is not required
345 */
346 sta->tdls_chandef = uc;
347 }
348}
349
350static void
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300351ieee80211_tdls_add_setup_start_ies(struct ieee80211_sub_if_data *sdata,
352 struct sk_buff *skb, const u8 *peer,
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300353 u8 action_code, bool initiator,
354 const u8 *extra_ies, size_t extra_ies_len)
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300355{
356 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsov40b861a2014-07-17 17:14:23 +0300357 struct ieee80211_local *local = sdata->local;
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300358 struct ieee80211_supported_band *sband;
359 struct ieee80211_sta_ht_cap ht_cap;
Arik Nemtsovfb28ec02015-03-01 09:10:02 +0200360 struct ieee80211_sta_vht_cap vht_cap;
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300361 struct sta_info *sta = NULL;
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300362 size_t offset = 0, noffset;
363 u8 *pos;
364
365 ieee80211_add_srates_ie(sdata, skb, false, band);
366 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovf0d29cb2014-11-09 18:50:12 +0200367 ieee80211_tdls_add_supp_channels(sdata, skb);
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300368
369 /* add any custom IEs that go before Extended Capabilities */
370 if (extra_ies_len) {
371 static const u8 before_ext_cap[] = {
372 WLAN_EID_SUPP_RATES,
373 WLAN_EID_COUNTRY,
374 WLAN_EID_EXT_SUPP_RATES,
375 WLAN_EID_SUPPORTED_CHANNELS,
376 WLAN_EID_RSN,
377 };
378 noffset = ieee80211_ie_split(extra_ies, extra_ies_len,
379 before_ext_cap,
380 ARRAY_SIZE(before_ext_cap),
381 offset);
382 pos = skb_put(skb, noffset - offset);
383 memcpy(pos, extra_ies + offset, noffset - offset);
384 offset = noffset;
385 }
386
Arik Nemtsovb98fb442015-06-10 20:42:59 +0300387 ieee80211_tdls_add_ext_capab(sdata, skb);
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300388
Arik Nemtsov40b861a2014-07-17 17:14:23 +0300389 /* add the QoS element if we support it */
390 if (local->hw.queues >= IEEE80211_NUM_ACS &&
391 action_code != WLAN_PUB_ACTION_TDLS_DISCOVER_RES)
392 ieee80211_add_wmm_info_ie(skb_put(skb, 9), 0); /* no U-APSD */
393
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300394 /* add any custom IEs that go before HT capabilities */
395 if (extra_ies_len) {
396 static const u8 before_ht_cap[] = {
397 WLAN_EID_SUPP_RATES,
398 WLAN_EID_COUNTRY,
399 WLAN_EID_EXT_SUPP_RATES,
400 WLAN_EID_SUPPORTED_CHANNELS,
401 WLAN_EID_RSN,
402 WLAN_EID_EXT_CAPABILITY,
403 WLAN_EID_QOS_CAPA,
404 WLAN_EID_FAST_BSS_TRANSITION,
405 WLAN_EID_TIMEOUT_INTERVAL,
406 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
407 };
408 noffset = ieee80211_ie_split(extra_ies, extra_ies_len,
409 before_ht_cap,
410 ARRAY_SIZE(before_ht_cap),
411 offset);
412 pos = skb_put(skb, noffset - offset);
413 memcpy(pos, extra_ies + offset, noffset - offset);
414 offset = noffset;
415 }
416
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +0300417 mutex_lock(&local->sta_mtx);
Arik Nemtsovae2e9fb2015-03-01 09:10:09 +0200418
419 /* we should have the peer STA if we're already responding */
420 if (action_code == WLAN_TDLS_SETUP_RESPONSE) {
421 sta = sta_info_get(sdata, peer);
422 if (WARN_ON_ONCE(!sta)) {
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +0300423 mutex_unlock(&local->sta_mtx);
Arik Nemtsovae2e9fb2015-03-01 09:10:09 +0200424 return;
425 }
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +0300426
427 sta->tdls_chandef = sdata->vif.bss_conf.chandef;
Arik Nemtsovae2e9fb2015-03-01 09:10:09 +0200428 }
429
Arik Nemtsova38700d2015-03-18 08:46:08 +0200430 ieee80211_tdls_add_oper_classes(sdata, skb);
431
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300432 /*
433 * with TDLS we can switch channels, and HT-caps are not necessarily
434 * the same on all bands. The specification limits the setup to a
435 * single HT-cap, so use the current band for now.
436 */
437 sband = local->hw.wiphy->bands[band];
438 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300439
Arik Nemtsov070e1762015-03-30 11:16:23 +0300440 if ((action_code == WLAN_TDLS_SETUP_REQUEST ||
441 action_code == WLAN_PUB_ACTION_TDLS_DISCOVER_RES) &&
442 ht_cap.ht_supported) {
Johannes Bergc5309ba2015-01-23 11:42:14 +0100443 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300444
Johannes Bergc5309ba2015-01-23 11:42:14 +0100445 /* disable SMPS in TDLS initiator */
446 ht_cap.cap |= WLAN_HT_CAP_SM_PS_DISABLED
447 << IEEE80211_HT_CAP_SM_PS_SHIFT;
448
449 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
450 ieee80211_ie_build_ht_cap(pos, &ht_cap, ht_cap.cap);
451 } else if (action_code == WLAN_TDLS_SETUP_RESPONSE &&
452 ht_cap.ht_supported && sta->sta.ht_cap.ht_supported) {
Johannes Bergc5309ba2015-01-23 11:42:14 +0100453 /* the peer caps are already intersected with our own */
454 memcpy(&ht_cap, &sta->sta.ht_cap, sizeof(ht_cap));
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300455
456 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
457 ieee80211_ie_build_ht_cap(pos, &ht_cap, ht_cap.cap);
458 }
459
Arik Nemtsov2cedd872014-11-09 18:50:13 +0200460 if (ht_cap.ht_supported &&
461 (ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
462 ieee80211_tdls_add_bss_coex_ie(skb);
463
Arik Nemtsovfb28ec02015-03-01 09:10:02 +0200464 ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator);
465
466 /* add any custom IEs that go before VHT capabilities */
467 if (extra_ies_len) {
468 static const u8 before_vht_cap[] = {
469 WLAN_EID_SUPP_RATES,
470 WLAN_EID_COUNTRY,
471 WLAN_EID_EXT_SUPP_RATES,
472 WLAN_EID_SUPPORTED_CHANNELS,
473 WLAN_EID_RSN,
474 WLAN_EID_EXT_CAPABILITY,
475 WLAN_EID_QOS_CAPA,
476 WLAN_EID_FAST_BSS_TRANSITION,
477 WLAN_EID_TIMEOUT_INTERVAL,
478 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
479 WLAN_EID_MULTI_BAND,
480 };
481 noffset = ieee80211_ie_split(extra_ies, extra_ies_len,
482 before_vht_cap,
483 ARRAY_SIZE(before_vht_cap),
484 offset);
485 pos = skb_put(skb, noffset - offset);
486 memcpy(pos, extra_ies + offset, noffset - offset);
487 offset = noffset;
488 }
489
490 /* build the VHT-cap similarly to the HT-cap */
491 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
Arik Nemtsov070e1762015-03-30 11:16:23 +0300492 if ((action_code == WLAN_TDLS_SETUP_REQUEST ||
493 action_code == WLAN_PUB_ACTION_TDLS_DISCOVER_RES) &&
494 vht_cap.vht_supported) {
Arik Nemtsovfb28ec02015-03-01 09:10:02 +0200495 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
496
497 /* the AID is present only when VHT is implemented */
Arik Nemtsov070e1762015-03-30 11:16:23 +0300498 if (action_code == WLAN_TDLS_SETUP_REQUEST)
499 ieee80211_tdls_add_aid(sdata, skb);
Arik Nemtsovfb28ec02015-03-01 09:10:02 +0200500
501 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
502 ieee80211_ie_build_vht_cap(pos, &vht_cap, vht_cap.cap);
503 } else if (action_code == WLAN_TDLS_SETUP_RESPONSE &&
504 vht_cap.vht_supported && sta->sta.vht_cap.vht_supported) {
505 /* the peer caps are already intersected with our own */
506 memcpy(&vht_cap, &sta->sta.vht_cap, sizeof(vht_cap));
507
508 /* the AID is present only when VHT is implemented */
509 ieee80211_tdls_add_aid(sdata, skb);
510
511 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
512 ieee80211_ie_build_vht_cap(pos, &vht_cap, vht_cap.cap);
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +0300513
514 /*
515 * if both peers support WIDER_BW, we can expand the chandef to
516 * a wider compatible one, up to 80MHz
517 */
518 if (test_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW))
519 ieee80211_tdls_chandef_vht_upgrade(sdata, sta);
Arik Nemtsovfb28ec02015-03-01 09:10:02 +0200520 }
521
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +0300522 mutex_unlock(&local->sta_mtx);
Arik Nemtsovfb28ec02015-03-01 09:10:02 +0200523
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300524 /* add any remaining IEs */
525 if (extra_ies_len) {
526 noffset = extra_ies_len;
527 pos = skb_put(skb, noffset - offset);
528 memcpy(pos, extra_ies + offset, noffset - offset);
529 }
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300530
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300531}
532
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300533static void
534ieee80211_tdls_add_setup_cfm_ies(struct ieee80211_sub_if_data *sdata,
535 struct sk_buff *skb, const u8 *peer,
536 bool initiator, const u8 *extra_ies,
537 size_t extra_ies_len)
538{
539 struct ieee80211_local *local = sdata->local;
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300540 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300541 size_t offset = 0, noffset;
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300542 struct sta_info *sta, *ap_sta;
Arik Nemtsovfb28ec02015-03-01 09:10:02 +0200543 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300544 u8 *pos;
545
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +0300546 mutex_lock(&local->sta_mtx);
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300547
548 sta = sta_info_get(sdata, peer);
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300549 ap_sta = sta_info_get(sdata, ifmgd->bssid);
550 if (WARN_ON_ONCE(!sta || !ap_sta)) {
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +0300551 mutex_unlock(&local->sta_mtx);
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300552 return;
553 }
554
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +0300555 sta->tdls_chandef = sdata->vif.bss_conf.chandef;
556
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300557 /* add any custom IEs that go before the QoS IE */
558 if (extra_ies_len) {
559 static const u8 before_qos[] = {
560 WLAN_EID_RSN,
561 };
562 noffset = ieee80211_ie_split(extra_ies, extra_ies_len,
563 before_qos,
564 ARRAY_SIZE(before_qos),
565 offset);
566 pos = skb_put(skb, noffset - offset);
567 memcpy(pos, extra_ies + offset, noffset - offset);
568 offset = noffset;
569 }
570
571 /* add the QoS param IE if both the peer and we support it */
Johannes Berga74a8c82014-07-22 14:50:47 +0200572 if (local->hw.queues >= IEEE80211_NUM_ACS && sta->sta.wme)
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300573 ieee80211_tdls_add_wmm_param_ie(sdata, skb);
574
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300575 /* add any custom IEs that go before HT operation */
576 if (extra_ies_len) {
577 static const u8 before_ht_op[] = {
578 WLAN_EID_RSN,
579 WLAN_EID_QOS_CAPA,
580 WLAN_EID_FAST_BSS_TRANSITION,
581 WLAN_EID_TIMEOUT_INTERVAL,
582 };
583 noffset = ieee80211_ie_split(extra_ies, extra_ies_len,
584 before_ht_op,
585 ARRAY_SIZE(before_ht_op),
586 offset);
587 pos = skb_put(skb, noffset - offset);
588 memcpy(pos, extra_ies + offset, noffset - offset);
589 offset = noffset;
590 }
591
592 /* if HT support is only added in TDLS, we need an HT-operation IE */
593 if (!ap_sta->sta.ht_cap.ht_supported && sta->sta.ht_cap.ht_supported) {
Arik Nemtsov890b7872015-05-07 15:30:41 +0300594 pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_operation));
595 /* send an empty HT operation IE */
596 ieee80211_ie_build_ht_oper(pos, &sta->sta.ht_cap,
597 &sdata->vif.bss_conf.chandef, 0);
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300598 }
599
Arik Nemtsovfb28ec02015-03-01 09:10:02 +0200600 ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator);
601
602 /* only include VHT-operation if not on the 2.4GHz band */
Arik Nemtsov890b7872015-05-07 15:30:41 +0300603 if (band != IEEE80211_BAND_2GHZ && sta->sta.vht_cap.vht_supported) {
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +0300604 /*
605 * if both peers support WIDER_BW, we can expand the chandef to
606 * a wider compatible one, up to 80MHz
607 */
608 if (test_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW))
609 ieee80211_tdls_chandef_vht_upgrade(sdata, sta);
610
Arik Nemtsov890b7872015-05-07 15:30:41 +0300611 pos = skb_put(skb, 2 + sizeof(struct ieee80211_vht_operation));
612 ieee80211_ie_build_vht_oper(pos, &sta->sta.vht_cap,
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +0300613 &sta->tdls_chandef);
Arik Nemtsovfb28ec02015-03-01 09:10:02 +0200614 }
615
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +0300616 mutex_unlock(&local->sta_mtx);
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300617
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300618 /* add any remaining IEs */
619 if (extra_ies_len) {
620 noffset = extra_ies_len;
621 pos = skb_put(skb, noffset - offset);
622 memcpy(pos, extra_ies + offset, noffset - offset);
623 }
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300624}
625
Arik Nemtsova7a6bdd2014-11-09 18:50:19 +0200626static void
627ieee80211_tdls_add_chan_switch_req_ies(struct ieee80211_sub_if_data *sdata,
628 struct sk_buff *skb, const u8 *peer,
629 bool initiator, const u8 *extra_ies,
630 size_t extra_ies_len, u8 oper_class,
631 struct cfg80211_chan_def *chandef)
632{
633 struct ieee80211_tdls_data *tf;
634 size_t offset = 0, noffset;
635 u8 *pos;
636
637 if (WARN_ON_ONCE(!chandef))
638 return;
639
640 tf = (void *)skb->data;
641 tf->u.chan_switch_req.target_channel =
642 ieee80211_frequency_to_channel(chandef->chan->center_freq);
643 tf->u.chan_switch_req.oper_class = oper_class;
644
645 if (extra_ies_len) {
646 static const u8 before_lnkie[] = {
647 WLAN_EID_SECONDARY_CHANNEL_OFFSET,
648 };
649 noffset = ieee80211_ie_split(extra_ies, extra_ies_len,
650 before_lnkie,
651 ARRAY_SIZE(before_lnkie),
652 offset);
653 pos = skb_put(skb, noffset - offset);
654 memcpy(pos, extra_ies + offset, noffset - offset);
655 offset = noffset;
656 }
657
658 ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator);
659
660 /* add any remaining IEs */
661 if (extra_ies_len) {
662 noffset = extra_ies_len;
663 pos = skb_put(skb, noffset - offset);
664 memcpy(pos, extra_ies + offset, noffset - offset);
665 }
666}
667
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +0200668static void
669ieee80211_tdls_add_chan_switch_resp_ies(struct ieee80211_sub_if_data *sdata,
670 struct sk_buff *skb, const u8 *peer,
671 u16 status_code, bool initiator,
672 const u8 *extra_ies,
673 size_t extra_ies_len)
674{
675 if (status_code == 0)
676 ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator);
677
678 if (extra_ies_len)
679 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
680}
681
Arik Nemtsov46792a22014-07-17 17:14:19 +0300682static void ieee80211_tdls_add_ies(struct ieee80211_sub_if_data *sdata,
683 struct sk_buff *skb, const u8 *peer,
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300684 u8 action_code, u16 status_code,
685 bool initiator, const u8 *extra_ies,
Arik Nemtsovc2733902014-11-09 18:50:16 +0200686 size_t extra_ies_len, u8 oper_class,
687 struct cfg80211_chan_def *chandef)
Arik Nemtsov46792a22014-07-17 17:14:19 +0300688{
Arik Nemtsov46792a22014-07-17 17:14:19 +0300689 switch (action_code) {
690 case WLAN_TDLS_SETUP_REQUEST:
691 case WLAN_TDLS_SETUP_RESPONSE:
692 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300693 if (status_code == 0)
694 ieee80211_tdls_add_setup_start_ies(sdata, skb, peer,
695 action_code,
696 initiator,
697 extra_ies,
698 extra_ies_len);
Arik Nemtsov46792a22014-07-17 17:14:19 +0300699 break;
700 case WLAN_TDLS_SETUP_CONFIRM:
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300701 if (status_code == 0)
702 ieee80211_tdls_add_setup_cfm_ies(sdata, skb, peer,
703 initiator, extra_ies,
704 extra_ies_len);
705 break;
Arik Nemtsov46792a22014-07-17 17:14:19 +0300706 case WLAN_TDLS_TEARDOWN:
707 case WLAN_TDLS_DISCOVERY_REQUEST:
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300708 if (extra_ies_len)
709 memcpy(skb_put(skb, extra_ies_len), extra_ies,
710 extra_ies_len);
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300711 if (status_code == 0 || action_code == WLAN_TDLS_TEARDOWN)
712 ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator);
Arik Nemtsov46792a22014-07-17 17:14:19 +0300713 break;
Arik Nemtsova7a6bdd2014-11-09 18:50:19 +0200714 case WLAN_TDLS_CHANNEL_SWITCH_REQUEST:
715 ieee80211_tdls_add_chan_switch_req_ies(sdata, skb, peer,
716 initiator, extra_ies,
717 extra_ies_len,
718 oper_class, chandef);
719 break;
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +0200720 case WLAN_TDLS_CHANNEL_SWITCH_RESPONSE:
721 ieee80211_tdls_add_chan_switch_resp_ies(sdata, skb, peer,
722 status_code,
723 initiator, extra_ies,
724 extra_ies_len);
725 break;
Arik Nemtsov46792a22014-07-17 17:14:19 +0300726 }
727
Arik Nemtsov46792a22014-07-17 17:14:19 +0300728}
729
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300730static int
731ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200732 const u8 *peer, u8 action_code, u8 dialog_token,
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300733 u16 status_code, struct sk_buff *skb)
734{
735 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300736 struct ieee80211_tdls_data *tf;
737
738 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
739
740 memcpy(tf->da, peer, ETH_ALEN);
741 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
742 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
743 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
744
Arik Nemtsov59cd85c2014-09-09 17:11:02 +0300745 /* network header is after the ethernet header */
746 skb_set_network_header(skb, ETH_HLEN);
747
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300748 switch (action_code) {
749 case WLAN_TDLS_SETUP_REQUEST:
750 tf->category = WLAN_CATEGORY_TDLS;
751 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
752
753 skb_put(skb, sizeof(tf->u.setup_req));
754 tf->u.setup_req.dialog_token = dialog_token;
755 tf->u.setup_req.capability =
Arik Nemtsovdd8c0b02014-07-17 17:14:22 +0300756 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata,
757 status_code));
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300758 break;
759 case WLAN_TDLS_SETUP_RESPONSE:
760 tf->category = WLAN_CATEGORY_TDLS;
761 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
762
763 skb_put(skb, sizeof(tf->u.setup_resp));
764 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
765 tf->u.setup_resp.dialog_token = dialog_token;
766 tf->u.setup_resp.capability =
Arik Nemtsovdd8c0b02014-07-17 17:14:22 +0300767 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata,
768 status_code));
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300769 break;
770 case WLAN_TDLS_SETUP_CONFIRM:
771 tf->category = WLAN_CATEGORY_TDLS;
772 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
773
774 skb_put(skb, sizeof(tf->u.setup_cfm));
775 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
776 tf->u.setup_cfm.dialog_token = dialog_token;
777 break;
778 case WLAN_TDLS_TEARDOWN:
779 tf->category = WLAN_CATEGORY_TDLS;
780 tf->action_code = WLAN_TDLS_TEARDOWN;
781
782 skb_put(skb, sizeof(tf->u.teardown));
783 tf->u.teardown.reason_code = cpu_to_le16(status_code);
784 break;
785 case WLAN_TDLS_DISCOVERY_REQUEST:
786 tf->category = WLAN_CATEGORY_TDLS;
787 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
788
789 skb_put(skb, sizeof(tf->u.discover_req));
790 tf->u.discover_req.dialog_token = dialog_token;
791 break;
Arik Nemtsova7a6bdd2014-11-09 18:50:19 +0200792 case WLAN_TDLS_CHANNEL_SWITCH_REQUEST:
793 tf->category = WLAN_CATEGORY_TDLS;
794 tf->action_code = WLAN_TDLS_CHANNEL_SWITCH_REQUEST;
795
796 skb_put(skb, sizeof(tf->u.chan_switch_req));
797 break;
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +0200798 case WLAN_TDLS_CHANNEL_SWITCH_RESPONSE:
799 tf->category = WLAN_CATEGORY_TDLS;
800 tf->action_code = WLAN_TDLS_CHANNEL_SWITCH_RESPONSE;
801
802 skb_put(skb, sizeof(tf->u.chan_switch_resp));
803 tf->u.chan_switch_resp.status_code = cpu_to_le16(status_code);
804 break;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300805 default:
806 return -EINVAL;
807 }
808
809 return 0;
810}
811
812static int
813ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200814 const u8 *peer, u8 action_code, u8 dialog_token,
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300815 u16 status_code, struct sk_buff *skb)
816{
817 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300818 struct ieee80211_mgmt *mgmt;
819
820 mgmt = (void *)skb_put(skb, 24);
821 memset(mgmt, 0, 24);
822 memcpy(mgmt->da, peer, ETH_ALEN);
823 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
824 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
825
826 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
827 IEEE80211_STYPE_ACTION);
828
829 switch (action_code) {
830 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
831 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
832 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
833 mgmt->u.action.u.tdls_discover_resp.action_code =
834 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
835 mgmt->u.action.u.tdls_discover_resp.dialog_token =
836 dialog_token;
837 mgmt->u.action.u.tdls_discover_resp.capability =
Arik Nemtsovdd8c0b02014-07-17 17:14:22 +0300838 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata,
839 status_code));
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300840 break;
841 default:
842 return -EINVAL;
843 }
844
845 return 0;
846}
847
Arik Nemtsovc2733902014-11-09 18:50:16 +0200848static struct sk_buff *
849ieee80211_tdls_build_mgmt_packet_data(struct ieee80211_sub_if_data *sdata,
850 const u8 *peer, u8 action_code,
851 u8 dialog_token, u16 status_code,
852 bool initiator, const u8 *extra_ies,
853 size_t extra_ies_len, u8 oper_class,
854 struct cfg80211_chan_def *chandef)
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300855{
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300856 struct ieee80211_local *local = sdata->local;
Arik Nemtsovc2733902014-11-09 18:50:16 +0200857 struct sk_buff *skb;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300858 int ret;
859
Arik Nemtsovc2733902014-11-09 18:50:16 +0200860 skb = netdev_alloc_skb(sdata->dev,
Liad Kaufman1277b4a2014-11-09 18:50:08 +0200861 local->hw.extra_tx_headroom +
862 max(sizeof(struct ieee80211_mgmt),
863 sizeof(struct ieee80211_tdls_data)) +
864 50 + /* supported rates */
Arik Nemtsovb98fb442015-06-10 20:42:59 +0300865 10 + /* ext capab */
Liad Kaufman1277b4a2014-11-09 18:50:08 +0200866 26 + /* max(WMM-info, WMM-param) */
867 2 + max(sizeof(struct ieee80211_ht_cap),
868 sizeof(struct ieee80211_ht_operation)) +
Arik Nemtsovfb28ec02015-03-01 09:10:02 +0200869 2 + max(sizeof(struct ieee80211_vht_cap),
870 sizeof(struct ieee80211_vht_operation)) +
Arik Nemtsovf0d29cb2014-11-09 18:50:12 +0200871 50 + /* supported channels */
Arik Nemtsov2cedd872014-11-09 18:50:13 +0200872 3 + /* 40/20 BSS coex */
Arik Nemtsovfb28ec02015-03-01 09:10:02 +0200873 4 + /* AID */
Arik Nemtsova38700d2015-03-18 08:46:08 +0200874 4 + /* oper classes */
Liad Kaufman1277b4a2014-11-09 18:50:08 +0200875 extra_ies_len +
876 sizeof(struct ieee80211_tdls_lnkie));
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300877 if (!skb)
Arik Nemtsovc2733902014-11-09 18:50:16 +0200878 return NULL;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300879
880 skb_reserve(skb, local->hw.extra_tx_headroom);
881
882 switch (action_code) {
883 case WLAN_TDLS_SETUP_REQUEST:
884 case WLAN_TDLS_SETUP_RESPONSE:
885 case WLAN_TDLS_SETUP_CONFIRM:
886 case WLAN_TDLS_TEARDOWN:
887 case WLAN_TDLS_DISCOVERY_REQUEST:
Arik Nemtsova7a6bdd2014-11-09 18:50:19 +0200888 case WLAN_TDLS_CHANNEL_SWITCH_REQUEST:
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +0200889 case WLAN_TDLS_CHANNEL_SWITCH_RESPONSE:
Arik Nemtsovc2733902014-11-09 18:50:16 +0200890 ret = ieee80211_prep_tdls_encap_data(local->hw.wiphy,
891 sdata->dev, peer,
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300892 action_code, dialog_token,
893 status_code, skb);
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300894 break;
895 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
Arik Nemtsovc2733902014-11-09 18:50:16 +0200896 ret = ieee80211_prep_tdls_direct(local->hw.wiphy, sdata->dev,
897 peer, action_code,
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300898 dialog_token, status_code,
899 skb);
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300900 break;
901 default:
902 ret = -ENOTSUPP;
903 break;
904 }
905
906 if (ret < 0)
907 goto fail;
908
Arik Nemtsovc2733902014-11-09 18:50:16 +0200909 ieee80211_tdls_add_ies(sdata, skb, peer, action_code, status_code,
910 initiator, extra_ies, extra_ies_len, oper_class,
911 chandef);
912 return skb;
913
914fail:
915 dev_kfree_skb(skb);
916 return NULL;
917}
918
919static int
920ieee80211_tdls_prep_mgmt_packet(struct wiphy *wiphy, struct net_device *dev,
921 const u8 *peer, u8 action_code, u8 dialog_token,
922 u16 status_code, u32 peer_capability,
923 bool initiator, const u8 *extra_ies,
924 size_t extra_ies_len, u8 oper_class,
925 struct cfg80211_chan_def *chandef)
926{
927 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
928 struct sk_buff *skb = NULL;
929 struct sta_info *sta;
930 u32 flags = 0;
931 int ret = 0;
932
Arik Nemtsov626911c2014-07-17 17:14:17 +0300933 rcu_read_lock();
934 sta = sta_info_get(sdata, peer);
935
936 /* infer the initiator if we can, to support old userspace */
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300937 switch (action_code) {
938 case WLAN_TDLS_SETUP_REQUEST:
Arik Nemtsov8b941482014-10-22 12:32:48 +0300939 if (sta) {
Arik Nemtsov626911c2014-07-17 17:14:17 +0300940 set_sta_flag(sta, WLAN_STA_TDLS_INITIATOR);
Arik Nemtsov8b941482014-10-22 12:32:48 +0300941 sta->sta.tdls_initiator = false;
942 }
Arik Nemtsov626911c2014-07-17 17:14:17 +0300943 /* fall-through */
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300944 case WLAN_TDLS_SETUP_CONFIRM:
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300945 case WLAN_TDLS_DISCOVERY_REQUEST:
Arik Nemtsov626911c2014-07-17 17:14:17 +0300946 initiator = true;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300947 break;
948 case WLAN_TDLS_SETUP_RESPONSE:
Arik Nemtsov626911c2014-07-17 17:14:17 +0300949 /*
950 * In some testing scenarios, we send a request and response.
951 * Make the last packet sent take effect for the initiator
952 * value.
953 */
Arik Nemtsov8b941482014-10-22 12:32:48 +0300954 if (sta) {
Arik Nemtsov626911c2014-07-17 17:14:17 +0300955 clear_sta_flag(sta, WLAN_STA_TDLS_INITIATOR);
Arik Nemtsov8b941482014-10-22 12:32:48 +0300956 sta->sta.tdls_initiator = true;
957 }
Arik Nemtsov626911c2014-07-17 17:14:17 +0300958 /* fall-through */
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300959 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
Arik Nemtsov626911c2014-07-17 17:14:17 +0300960 initiator = false;
Arik Nemtsov2fb6b9b2014-06-11 17:18:22 +0300961 break;
962 case WLAN_TDLS_TEARDOWN:
Arik Nemtsova7a6bdd2014-11-09 18:50:19 +0200963 case WLAN_TDLS_CHANNEL_SWITCH_REQUEST:
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +0200964 case WLAN_TDLS_CHANNEL_SWITCH_RESPONSE:
Arik Nemtsov2fb6b9b2014-06-11 17:18:22 +0300965 /* any value is ok */
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300966 break;
967 default:
968 ret = -ENOTSUPP;
Arik Nemtsov626911c2014-07-17 17:14:17 +0300969 break;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300970 }
971
Arik Nemtsov46792a22014-07-17 17:14:19 +0300972 if (sta && test_sta_flag(sta, WLAN_STA_TDLS_INITIATOR))
973 initiator = true;
Arik Nemtsov2fb6b9b2014-06-11 17:18:22 +0300974
Arik Nemtsov626911c2014-07-17 17:14:17 +0300975 rcu_read_unlock();
976 if (ret < 0)
977 goto fail;
978
Arik Nemtsovc2733902014-11-09 18:50:16 +0200979 skb = ieee80211_tdls_build_mgmt_packet_data(sdata, peer, action_code,
980 dialog_token, status_code,
981 initiator, extra_ies,
982 extra_ies_len, oper_class,
983 chandef);
984 if (!skb) {
985 ret = -EINVAL;
986 goto fail;
987 }
988
989 if (action_code == WLAN_PUB_ACTION_TDLS_DISCOVER_RES) {
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300990 ieee80211_tx_skb(sdata, skb);
991 return 0;
992 }
993
994 /*
995 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
996 * we should default to AC_VI.
997 */
998 switch (action_code) {
999 case WLAN_TDLS_SETUP_REQUEST:
1000 case WLAN_TDLS_SETUP_RESPONSE:
1001 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
1002 skb->priority = 2;
1003 break;
1004 default:
1005 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
1006 skb->priority = 5;
1007 break;
1008 }
1009
Liad Kaufman1277b4a2014-11-09 18:50:08 +02001010 /*
1011 * Set the WLAN_TDLS_TEARDOWN flag to indicate a teardown in progress.
1012 * Later, if no ACK is returned from peer, we will re-send the teardown
1013 * packet through the AP.
1014 */
1015 if ((action_code == WLAN_TDLS_TEARDOWN) &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001016 ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
Liad Kaufman1277b4a2014-11-09 18:50:08 +02001017 bool try_resend; /* Should we keep skb for possible resend */
1018
1019 /* If not sending directly to peer - no point in keeping skb */
1020 rcu_read_lock();
1021 sta = sta_info_get(sdata, peer);
1022 try_resend = sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
1023 rcu_read_unlock();
1024
1025 spin_lock_bh(&sdata->u.mgd.teardown_lock);
1026 if (try_resend && !sdata->u.mgd.teardown_skb) {
1027 /* Mark it as requiring TX status callback */
1028 flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
1029 IEEE80211_TX_INTFL_MLME_CONN_TX;
1030
1031 /*
1032 * skb is copied since mac80211 will later set
1033 * properties that might not be the same as the AP,
1034 * such as encryption, QoS, addresses, etc.
1035 *
1036 * No problem if skb_copy() fails, so no need to check.
1037 */
1038 sdata->u.mgd.teardown_skb = skb_copy(skb, GFP_ATOMIC);
1039 sdata->u.mgd.orig_teardown_skb = skb;
1040 }
1041 spin_unlock_bh(&sdata->u.mgd.teardown_lock);
1042 }
1043
Arik Nemtsov95224fe2014-05-01 10:17:28 +03001044 /* disable bottom halves when entering the Tx path */
1045 local_bh_disable();
Liad Kaufman1277b4a2014-11-09 18:50:08 +02001046 __ieee80211_subif_start_xmit(skb, dev, flags);
Arik Nemtsov95224fe2014-05-01 10:17:28 +03001047 local_bh_enable();
1048
1049 return ret;
1050
1051fail:
1052 dev_kfree_skb(skb);
1053 return ret;
1054}
1055
Arik Nemtsov191dd462014-06-11 17:18:23 +03001056static int
1057ieee80211_tdls_mgmt_setup(struct wiphy *wiphy, struct net_device *dev,
1058 const u8 *peer, u8 action_code, u8 dialog_token,
1059 u16 status_code, u32 peer_capability, bool initiator,
1060 const u8 *extra_ies, size_t extra_ies_len)
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001061{
1062 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1063 struct ieee80211_local *local = sdata->local;
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03001064 enum ieee80211_smps_mode smps_mode = sdata->u.mgd.driver_smps_mode;
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001065 int ret;
1066
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03001067 /* don't support setup with forced SMPS mode that's not off */
1068 if (smps_mode != IEEE80211_SMPS_AUTOMATIC &&
1069 smps_mode != IEEE80211_SMPS_OFF) {
1070 tdls_dbg(sdata, "Aborting TDLS setup due to SMPS mode %d\n",
1071 smps_mode);
1072 return -ENOTSUPP;
1073 }
1074
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001075 mutex_lock(&local->mtx);
1076
1077 /* we don't support concurrent TDLS peer setups */
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03001078 if (!is_zero_ether_addr(sdata->u.mgd.tdls_peer) &&
1079 !ether_addr_equal(sdata->u.mgd.tdls_peer, peer)) {
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001080 ret = -EBUSY;
Arik Nemtsovae2e9fb2015-03-01 09:10:09 +02001081 goto out_unlock;
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001082 }
1083
Arik Nemtsov7adc3e42014-06-11 17:18:26 +03001084 /*
1085 * make sure we have a STA representing the peer so we drop or buffer
1086 * non-TDLS-setup frames to the peer. We can't send other packets
Arik Nemtsov6ae32e52014-07-17 17:14:18 +03001087 * during setup through the AP path.
1088 * Allow error packets to be sent - sometimes we don't even add a STA
1089 * before failing the setup.
Arik Nemtsov7adc3e42014-06-11 17:18:26 +03001090 */
Arik Nemtsov6ae32e52014-07-17 17:14:18 +03001091 if (status_code == 0) {
1092 rcu_read_lock();
1093 if (!sta_info_get(sdata, peer)) {
1094 rcu_read_unlock();
1095 ret = -ENOLINK;
Arik Nemtsovae2e9fb2015-03-01 09:10:09 +02001096 goto out_unlock;
Arik Nemtsov6ae32e52014-07-17 17:14:18 +03001097 }
Arik Nemtsov7adc3e42014-06-11 17:18:26 +03001098 rcu_read_unlock();
Arik Nemtsov7adc3e42014-06-11 17:18:26 +03001099 }
Arik Nemtsov7adc3e42014-06-11 17:18:26 +03001100
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02001101 ieee80211_flush_queues(local, sdata, false);
Arik Nemtsovae2e9fb2015-03-01 09:10:09 +02001102 memcpy(sdata->u.mgd.tdls_peer, peer, ETH_ALEN);
1103 mutex_unlock(&local->mtx);
Arik Nemtsovdb67d662014-06-11 17:18:24 +03001104
Arik Nemtsovae2e9fb2015-03-01 09:10:09 +02001105 /* we cannot take the mutex while preparing the setup packet */
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001106 ret = ieee80211_tdls_prep_mgmt_packet(wiphy, dev, peer, action_code,
1107 dialog_token, status_code,
Arik Nemtsov2fb6b9b2014-06-11 17:18:22 +03001108 peer_capability, initiator,
Arik Nemtsovc2733902014-11-09 18:50:16 +02001109 extra_ies, extra_ies_len, 0,
1110 NULL);
Arik Nemtsovae2e9fb2015-03-01 09:10:09 +02001111 if (ret < 0) {
1112 mutex_lock(&local->mtx);
1113 eth_zero_addr(sdata->u.mgd.tdls_peer);
1114 mutex_unlock(&local->mtx);
1115 return ret;
1116 }
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001117
Arik Nemtsov191dd462014-06-11 17:18:23 +03001118 ieee80211_queue_delayed_work(&sdata->local->hw,
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03001119 &sdata->u.mgd.tdls_peer_del_work,
Arik Nemtsov191dd462014-06-11 17:18:23 +03001120 TDLS_PEER_SETUP_TIMEOUT);
Arik Nemtsovae2e9fb2015-03-01 09:10:09 +02001121 return 0;
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001122
Arik Nemtsovae2e9fb2015-03-01 09:10:09 +02001123out_unlock:
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001124 mutex_unlock(&local->mtx);
Arik Nemtsov191dd462014-06-11 17:18:23 +03001125 return ret;
1126}
1127
Arik Nemtsovdb67d662014-06-11 17:18:24 +03001128static int
1129ieee80211_tdls_mgmt_teardown(struct wiphy *wiphy, struct net_device *dev,
1130 const u8 *peer, u8 action_code, u8 dialog_token,
1131 u16 status_code, u32 peer_capability,
1132 bool initiator, const u8 *extra_ies,
1133 size_t extra_ies_len)
1134{
1135 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1136 struct ieee80211_local *local = sdata->local;
1137 struct sta_info *sta;
1138 int ret;
1139
1140 /*
1141 * No packets can be transmitted to the peer via the AP during setup -
1142 * the STA is set as a TDLS peer, but is not authorized.
1143 * During teardown, we prevent direct transmissions by stopping the
1144 * queues and flushing all direct packets.
1145 */
1146 ieee80211_stop_vif_queues(local, sdata,
1147 IEEE80211_QUEUE_STOP_REASON_TDLS_TEARDOWN);
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02001148 ieee80211_flush_queues(local, sdata, false);
Arik Nemtsovdb67d662014-06-11 17:18:24 +03001149
1150 ret = ieee80211_tdls_prep_mgmt_packet(wiphy, dev, peer, action_code,
1151 dialog_token, status_code,
1152 peer_capability, initiator,
Arik Nemtsovc2733902014-11-09 18:50:16 +02001153 extra_ies, extra_ies_len, 0,
1154 NULL);
Arik Nemtsovdb67d662014-06-11 17:18:24 +03001155 if (ret < 0)
1156 sdata_err(sdata, "Failed sending TDLS teardown packet %d\n",
1157 ret);
1158
1159 /*
1160 * Remove the STA AUTH flag to force further traffic through the AP. If
1161 * the STA was unreachable, it was already removed.
1162 */
1163 rcu_read_lock();
1164 sta = sta_info_get(sdata, peer);
1165 if (sta)
1166 clear_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
1167 rcu_read_unlock();
1168
1169 ieee80211_wake_vif_queues(local, sdata,
1170 IEEE80211_QUEUE_STOP_REASON_TDLS_TEARDOWN);
1171
1172 return 0;
1173}
1174
Arik Nemtsov191dd462014-06-11 17:18:23 +03001175int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
1176 const u8 *peer, u8 action_code, u8 dialog_token,
1177 u16 status_code, u32 peer_capability,
1178 bool initiator, const u8 *extra_ies,
1179 size_t extra_ies_len)
1180{
1181 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1182 int ret;
1183
1184 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
1185 return -ENOTSUPP;
1186
1187 /* make sure we are in managed mode, and associated */
1188 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
1189 !sdata->u.mgd.associated)
1190 return -EINVAL;
1191
1192 switch (action_code) {
1193 case WLAN_TDLS_SETUP_REQUEST:
1194 case WLAN_TDLS_SETUP_RESPONSE:
1195 ret = ieee80211_tdls_mgmt_setup(wiphy, dev, peer, action_code,
1196 dialog_token, status_code,
1197 peer_capability, initiator,
1198 extra_ies, extra_ies_len);
1199 break;
1200 case WLAN_TDLS_TEARDOWN:
Arik Nemtsovdb67d662014-06-11 17:18:24 +03001201 ret = ieee80211_tdls_mgmt_teardown(wiphy, dev, peer,
1202 action_code, dialog_token,
1203 status_code,
1204 peer_capability, initiator,
1205 extra_ies, extra_ies_len);
1206 break;
Arik Nemtsov191dd462014-06-11 17:18:23 +03001207 case WLAN_TDLS_DISCOVERY_REQUEST:
Arik Nemtsovee10f2c2014-06-11 17:18:27 +03001208 /*
1209 * Protect the discovery so we can hear the TDLS discovery
1210 * response frame. It is transmitted directly and not buffered
1211 * by the AP.
1212 */
1213 drv_mgd_protect_tdls_discover(sdata->local, sdata);
1214 /* fall-through */
1215 case WLAN_TDLS_SETUP_CONFIRM:
Arik Nemtsov191dd462014-06-11 17:18:23 +03001216 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
1217 /* no special handling */
1218 ret = ieee80211_tdls_prep_mgmt_packet(wiphy, dev, peer,
1219 action_code,
1220 dialog_token,
1221 status_code,
1222 peer_capability,
1223 initiator, extra_ies,
Arik Nemtsovc2733902014-11-09 18:50:16 +02001224 extra_ies_len, 0, NULL);
Arik Nemtsov191dd462014-06-11 17:18:23 +03001225 break;
1226 default:
1227 ret = -EOPNOTSUPP;
1228 break;
1229 }
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001230
1231 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM status %d\n",
1232 action_code, peer, ret);
1233 return ret;
1234}
1235
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +03001236static void iee80211_tdls_recalc_chanctx(struct ieee80211_sub_if_data *sdata)
1237{
1238 struct ieee80211_local *local = sdata->local;
1239 struct ieee80211_chanctx_conf *conf;
1240 struct ieee80211_chanctx *ctx;
1241
1242 mutex_lock(&local->chanctx_mtx);
1243 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1244 lockdep_is_held(&local->chanctx_mtx));
1245 if (conf) {
1246 ctx = container_of(conf, struct ieee80211_chanctx, conf);
1247 ieee80211_recalc_chanctx_chantype(local, ctx);
1248 }
1249 mutex_unlock(&local->chanctx_mtx);
1250}
1251
Arik Nemtsov95224fe2014-05-01 10:17:28 +03001252int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001253 const u8 *peer, enum nl80211_tdls_operation oper)
Arik Nemtsov95224fe2014-05-01 10:17:28 +03001254{
1255 struct sta_info *sta;
1256 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001257 struct ieee80211_local *local = sdata->local;
1258 int ret;
Arik Nemtsov95224fe2014-05-01 10:17:28 +03001259
1260 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
1261 return -ENOTSUPP;
1262
1263 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1264 return -EINVAL;
1265
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001266 switch (oper) {
1267 case NL80211_TDLS_ENABLE_LINK:
1268 case NL80211_TDLS_DISABLE_LINK:
1269 break;
1270 case NL80211_TDLS_TEARDOWN:
1271 case NL80211_TDLS_SETUP:
1272 case NL80211_TDLS_DISCOVERY_REQ:
1273 /* We don't support in-driver setup/teardown/discovery */
1274 return -ENOTSUPP;
1275 }
1276
1277 mutex_lock(&local->mtx);
Arik Nemtsov95224fe2014-05-01 10:17:28 +03001278 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
1279
1280 switch (oper) {
1281 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsovc5a71682015-05-19 14:36:48 +03001282 if (sdata->vif.csa_active) {
1283 tdls_dbg(sdata, "TDLS: disallow link during CSA\n");
1284 ret = -EBUSY;
1285 break;
1286 }
1287
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +03001288 iee80211_tdls_recalc_chanctx(sdata);
1289
Arik Nemtsov95224fe2014-05-01 10:17:28 +03001290 rcu_read_lock();
1291 sta = sta_info_get(sdata, peer);
1292 if (!sta) {
1293 rcu_read_unlock();
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001294 ret = -ENOLINK;
1295 break;
Arik Nemtsov95224fe2014-05-01 10:17:28 +03001296 }
1297
1298 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
1299 rcu_read_unlock();
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001300
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03001301 WARN_ON_ONCE(is_zero_ether_addr(sdata->u.mgd.tdls_peer) ||
1302 !ether_addr_equal(sdata->u.mgd.tdls_peer, peer));
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001303 ret = 0;
Arik Nemtsov95224fe2014-05-01 10:17:28 +03001304 break;
1305 case NL80211_TDLS_DISABLE_LINK:
Liad Kaufmanbb3f8482014-07-17 17:14:31 +03001306 /*
1307 * The teardown message in ieee80211_tdls_mgmt_teardown() was
1308 * created while the queues were stopped, so it might still be
1309 * pending. Before flushing the queues we need to be sure the
1310 * message is handled by the tasklet handling pending messages,
1311 * otherwise we might start destroying the station before
1312 * sending the teardown packet.
1313 * Note that this only forces the tasklet to flush pendings -
1314 * not to stop the tasklet from rescheduling itself.
1315 */
1316 tasklet_kill(&local->tx_pending_tasklet);
Arik Nemtsovdb67d662014-06-11 17:18:24 +03001317 /* flush a potentially queued teardown packet */
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02001318 ieee80211_flush_queues(local, sdata, false);
Arik Nemtsovdb67d662014-06-11 17:18:24 +03001319
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001320 ret = sta_info_destroy_addr(sdata, peer);
Arik Nemtsov0fabfaa2015-06-10 20:41:23 +03001321 iee80211_tdls_recalc_chanctx(sdata);
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001322 break;
Arik Nemtsov95224fe2014-05-01 10:17:28 +03001323 default:
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001324 ret = -ENOTSUPP;
1325 break;
Arik Nemtsov95224fe2014-05-01 10:17:28 +03001326 }
1327
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03001328 if (ret == 0 && ether_addr_equal(sdata->u.mgd.tdls_peer, peer)) {
1329 cancel_delayed_work(&sdata->u.mgd.tdls_peer_del_work);
1330 eth_zero_addr(sdata->u.mgd.tdls_peer);
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001331 }
1332
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03001333 if (ret == 0)
1334 ieee80211_queue_work(&sdata->local->hw,
1335 &sdata->u.mgd.request_smps_work);
1336
Arik Nemtsov17e6a592014-06-11 17:18:20 +03001337 mutex_unlock(&local->mtx);
1338 return ret;
Arik Nemtsov95224fe2014-05-01 10:17:28 +03001339}
Arik Nemtsovc887f0d32014-06-11 17:18:25 +03001340
1341void ieee80211_tdls_oper_request(struct ieee80211_vif *vif, const u8 *peer,
1342 enum nl80211_tdls_operation oper,
1343 u16 reason_code, gfp_t gfp)
1344{
1345 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1346
1347 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc) {
1348 sdata_err(sdata, "Discarding TDLS oper %d - not STA or disconnected\n",
1349 oper);
1350 return;
1351 }
1352
1353 cfg80211_tdls_oper_request(sdata->dev, peer, oper, reason_code, gfp);
1354}
1355EXPORT_SYMBOL(ieee80211_tdls_oper_request);
Arik Nemtsova7a6bdd2014-11-09 18:50:19 +02001356
1357static void
1358iee80211_tdls_add_ch_switch_timing(u8 *buf, u16 switch_time, u16 switch_timeout)
1359{
1360 struct ieee80211_ch_switch_timing *ch_sw;
1361
1362 *buf++ = WLAN_EID_CHAN_SWITCH_TIMING;
1363 *buf++ = sizeof(struct ieee80211_ch_switch_timing);
1364
1365 ch_sw = (void *)buf;
1366 ch_sw->switch_time = cpu_to_le16(switch_time);
1367 ch_sw->switch_timeout = cpu_to_le16(switch_timeout);
1368}
1369
1370/* find switch timing IE in SKB ready for Tx */
1371static const u8 *ieee80211_tdls_find_sw_timing_ie(struct sk_buff *skb)
1372{
1373 struct ieee80211_tdls_data *tf;
1374 const u8 *ie_start;
1375
1376 /*
1377 * Get the offset for the new location of the switch timing IE.
1378 * The SKB network header will now point to the "payload_type"
1379 * element of the TDLS data frame struct.
1380 */
1381 tf = container_of(skb->data + skb_network_offset(skb),
1382 struct ieee80211_tdls_data, payload_type);
1383 ie_start = tf->u.chan_switch_req.variable;
1384 return cfg80211_find_ie(WLAN_EID_CHAN_SWITCH_TIMING, ie_start,
1385 skb->len - (ie_start - skb->data));
1386}
1387
1388static struct sk_buff *
1389ieee80211_tdls_ch_sw_tmpl_get(struct sta_info *sta, u8 oper_class,
1390 struct cfg80211_chan_def *chandef,
1391 u32 *ch_sw_tm_ie_offset)
1392{
1393 struct ieee80211_sub_if_data *sdata = sta->sdata;
1394 u8 extra_ies[2 + sizeof(struct ieee80211_sec_chan_offs_ie) +
1395 2 + sizeof(struct ieee80211_ch_switch_timing)];
1396 int extra_ies_len = 2 + sizeof(struct ieee80211_ch_switch_timing);
1397 u8 *pos = extra_ies;
1398 struct sk_buff *skb;
1399
1400 /*
1401 * if chandef points to a wide channel add a Secondary-Channel
1402 * Offset information element
1403 */
1404 if (chandef->width == NL80211_CHAN_WIDTH_40) {
1405 struct ieee80211_sec_chan_offs_ie *sec_chan_ie;
1406 bool ht40plus;
1407
1408 *pos++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET;
1409 *pos++ = sizeof(*sec_chan_ie);
1410 sec_chan_ie = (void *)pos;
1411
1412 ht40plus = cfg80211_get_chandef_type(chandef) ==
1413 NL80211_CHAN_HT40PLUS;
1414 sec_chan_ie->sec_chan_offs = ht40plus ?
1415 IEEE80211_HT_PARAM_CHA_SEC_ABOVE :
1416 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1417 pos += sizeof(*sec_chan_ie);
1418
1419 extra_ies_len += 2 + sizeof(struct ieee80211_sec_chan_offs_ie);
1420 }
1421
1422 /* just set the values to 0, this is a template */
1423 iee80211_tdls_add_ch_switch_timing(pos, 0, 0);
1424
1425 skb = ieee80211_tdls_build_mgmt_packet_data(sdata, sta->sta.addr,
1426 WLAN_TDLS_CHANNEL_SWITCH_REQUEST,
1427 0, 0, !sta->sta.tdls_initiator,
1428 extra_ies, extra_ies_len,
1429 oper_class, chandef);
1430 if (!skb)
1431 return NULL;
1432
1433 skb = ieee80211_build_data_template(sdata, skb, 0);
1434 if (IS_ERR(skb)) {
1435 tdls_dbg(sdata, "Failed building TDLS channel switch frame\n");
1436 return NULL;
1437 }
1438
1439 if (ch_sw_tm_ie_offset) {
1440 const u8 *tm_ie = ieee80211_tdls_find_sw_timing_ie(skb);
1441
1442 if (!tm_ie) {
1443 tdls_dbg(sdata, "No switch timing IE in TDLS switch\n");
1444 dev_kfree_skb_any(skb);
1445 return NULL;
1446 }
1447
1448 *ch_sw_tm_ie_offset = tm_ie - skb->data;
1449 }
1450
1451 tdls_dbg(sdata,
1452 "TDLS channel switch request template for %pM ch %d width %d\n",
1453 sta->sta.addr, chandef->chan->center_freq, chandef->width);
1454 return skb;
1455}
1456
1457int
1458ieee80211_tdls_channel_switch(struct wiphy *wiphy, struct net_device *dev,
1459 const u8 *addr, u8 oper_class,
1460 struct cfg80211_chan_def *chandef)
1461{
1462 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1463 struct ieee80211_local *local = sdata->local;
1464 struct sta_info *sta;
1465 struct sk_buff *skb = NULL;
1466 u32 ch_sw_tm_ie;
1467 int ret;
1468
1469 mutex_lock(&local->sta_mtx);
1470 sta = sta_info_get(sdata, addr);
1471 if (!sta) {
1472 tdls_dbg(sdata,
1473 "Invalid TDLS peer %pM for channel switch request\n",
1474 addr);
1475 ret = -ENOENT;
1476 goto out;
1477 }
1478
1479 if (!test_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH)) {
1480 tdls_dbg(sdata, "TDLS channel switch unsupported by %pM\n",
1481 addr);
1482 ret = -ENOTSUPP;
1483 goto out;
1484 }
1485
1486 skb = ieee80211_tdls_ch_sw_tmpl_get(sta, oper_class, chandef,
1487 &ch_sw_tm_ie);
1488 if (!skb) {
1489 ret = -ENOENT;
1490 goto out;
1491 }
1492
1493 ret = drv_tdls_channel_switch(local, sdata, &sta->sta, oper_class,
1494 chandef, skb, ch_sw_tm_ie);
1495 if (!ret)
1496 set_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL);
1497
1498out:
1499 mutex_unlock(&local->sta_mtx);
1500 dev_kfree_skb_any(skb);
1501 return ret;
1502}
1503
1504void
1505ieee80211_tdls_cancel_channel_switch(struct wiphy *wiphy,
1506 struct net_device *dev,
1507 const u8 *addr)
1508{
1509 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1510 struct ieee80211_local *local = sdata->local;
1511 struct sta_info *sta;
1512
1513 mutex_lock(&local->sta_mtx);
1514 sta = sta_info_get(sdata, addr);
1515 if (!sta) {
1516 tdls_dbg(sdata,
1517 "Invalid TDLS peer %pM for channel switch cancel\n",
1518 addr);
1519 goto out;
1520 }
1521
1522 if (!test_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL)) {
1523 tdls_dbg(sdata, "TDLS channel switch not initiated by %pM\n",
1524 addr);
1525 goto out;
1526 }
1527
1528 drv_tdls_cancel_channel_switch(local, sdata, &sta->sta);
1529 clear_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL);
1530
1531out:
1532 mutex_unlock(&local->sta_mtx);
1533}
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +02001534
1535static struct sk_buff *
1536ieee80211_tdls_ch_sw_resp_tmpl_get(struct sta_info *sta,
1537 u32 *ch_sw_tm_ie_offset)
1538{
1539 struct ieee80211_sub_if_data *sdata = sta->sdata;
1540 struct sk_buff *skb;
1541 u8 extra_ies[2 + sizeof(struct ieee80211_ch_switch_timing)];
1542
1543 /* initial timing are always zero in the template */
1544 iee80211_tdls_add_ch_switch_timing(extra_ies, 0, 0);
1545
1546 skb = ieee80211_tdls_build_mgmt_packet_data(sdata, sta->sta.addr,
1547 WLAN_TDLS_CHANNEL_SWITCH_RESPONSE,
1548 0, 0, !sta->sta.tdls_initiator,
1549 extra_ies, sizeof(extra_ies), 0, NULL);
1550 if (!skb)
1551 return NULL;
1552
1553 skb = ieee80211_build_data_template(sdata, skb, 0);
1554 if (IS_ERR(skb)) {
1555 tdls_dbg(sdata,
1556 "Failed building TDLS channel switch resp frame\n");
1557 return NULL;
1558 }
1559
1560 if (ch_sw_tm_ie_offset) {
1561 const u8 *tm_ie = ieee80211_tdls_find_sw_timing_ie(skb);
1562
1563 if (!tm_ie) {
1564 tdls_dbg(sdata,
1565 "No switch timing IE in TDLS switch resp\n");
1566 dev_kfree_skb_any(skb);
1567 return NULL;
1568 }
1569
1570 *ch_sw_tm_ie_offset = tm_ie - skb->data;
1571 }
1572
1573 tdls_dbg(sdata, "TDLS get channel switch response template for %pM\n",
1574 sta->sta.addr);
1575 return skb;
1576}
1577
1578static int
1579ieee80211_process_tdls_channel_switch_resp(struct ieee80211_sub_if_data *sdata,
1580 struct sk_buff *skb)
1581{
1582 struct ieee80211_local *local = sdata->local;
1583 struct ieee802_11_elems elems;
1584 struct sta_info *sta;
1585 struct ieee80211_tdls_data *tf = (void *)skb->data;
1586 bool local_initiator;
1587 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
1588 int baselen = offsetof(typeof(*tf), u.chan_switch_resp.variable);
1589 struct ieee80211_tdls_ch_sw_params params = {};
1590 int ret;
1591
1592 params.action_code = WLAN_TDLS_CHANNEL_SWITCH_RESPONSE;
1593 params.timestamp = rx_status->device_timestamp;
1594
1595 if (skb->len < baselen) {
1596 tdls_dbg(sdata, "TDLS channel switch resp too short: %d\n",
1597 skb->len);
1598 return -EINVAL;
1599 }
1600
1601 mutex_lock(&local->sta_mtx);
1602 sta = sta_info_get(sdata, tf->sa);
1603 if (!sta || !test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH)) {
1604 tdls_dbg(sdata, "TDLS chan switch from non-peer sta %pM\n",
1605 tf->sa);
1606 ret = -EINVAL;
1607 goto out;
1608 }
1609
1610 params.sta = &sta->sta;
1611 params.status = le16_to_cpu(tf->u.chan_switch_resp.status_code);
1612 if (params.status != 0) {
1613 ret = 0;
1614 goto call_drv;
1615 }
1616
1617 ieee802_11_parse_elems(tf->u.chan_switch_resp.variable,
1618 skb->len - baselen, false, &elems);
1619 if (elems.parse_error) {
1620 tdls_dbg(sdata, "Invalid IEs in TDLS channel switch resp\n");
1621 ret = -EINVAL;
1622 goto out;
1623 }
1624
1625 if (!elems.ch_sw_timing || !elems.lnk_id) {
1626 tdls_dbg(sdata, "TDLS channel switch resp - missing IEs\n");
1627 ret = -EINVAL;
1628 goto out;
1629 }
1630
1631 /* validate the initiator is set correctly */
1632 local_initiator =
1633 !memcmp(elems.lnk_id->init_sta, sdata->vif.addr, ETH_ALEN);
1634 if (local_initiator == sta->sta.tdls_initiator) {
1635 tdls_dbg(sdata, "TDLS chan switch invalid lnk-id initiator\n");
1636 ret = -EINVAL;
1637 goto out;
1638 }
1639
1640 params.switch_time = le16_to_cpu(elems.ch_sw_timing->switch_time);
1641 params.switch_timeout = le16_to_cpu(elems.ch_sw_timing->switch_timeout);
1642
1643 params.tmpl_skb =
1644 ieee80211_tdls_ch_sw_resp_tmpl_get(sta, &params.ch_sw_tm_ie);
1645 if (!params.tmpl_skb) {
1646 ret = -ENOENT;
1647 goto out;
1648 }
1649
1650call_drv:
1651 drv_tdls_recv_channel_switch(sdata->local, sdata, &params);
1652
1653 tdls_dbg(sdata,
1654 "TDLS channel switch response received from %pM status %d\n",
1655 tf->sa, params.status);
1656
1657out:
1658 mutex_unlock(&local->sta_mtx);
1659 dev_kfree_skb_any(params.tmpl_skb);
1660 return ret;
1661}
1662
1663static int
1664ieee80211_process_tdls_channel_switch_req(struct ieee80211_sub_if_data *sdata,
1665 struct sk_buff *skb)
1666{
1667 struct ieee80211_local *local = sdata->local;
1668 struct ieee802_11_elems elems;
1669 struct cfg80211_chan_def chandef;
1670 struct ieee80211_channel *chan;
1671 enum nl80211_channel_type chan_type;
1672 int freq;
1673 u8 target_channel, oper_class;
1674 bool local_initiator;
1675 struct sta_info *sta;
1676 enum ieee80211_band band;
1677 struct ieee80211_tdls_data *tf = (void *)skb->data;
1678 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
1679 int baselen = offsetof(typeof(*tf), u.chan_switch_req.variable);
1680 struct ieee80211_tdls_ch_sw_params params = {};
1681 int ret = 0;
1682
1683 params.action_code = WLAN_TDLS_CHANNEL_SWITCH_REQUEST;
1684 params.timestamp = rx_status->device_timestamp;
1685
1686 if (skb->len < baselen) {
1687 tdls_dbg(sdata, "TDLS channel switch req too short: %d\n",
1688 skb->len);
1689 return -EINVAL;
1690 }
1691
1692 target_channel = tf->u.chan_switch_req.target_channel;
1693 oper_class = tf->u.chan_switch_req.oper_class;
1694
1695 /*
1696 * We can't easily infer the channel band. The operating class is
1697 * ambiguous - there are multiple tables (US/Europe/JP/Global). The
1698 * solution here is to treat channels with number >14 as 5GHz ones,
1699 * and specifically check for the (oper_class, channel) combinations
1700 * where this doesn't hold. These are thankfully unique according to
1701 * IEEE802.11-2012.
1702 * We consider only the 2GHz and 5GHz bands and 20MHz+ channels as
1703 * valid here.
1704 */
1705 if ((oper_class == 112 || oper_class == 2 || oper_class == 3 ||
1706 oper_class == 4 || oper_class == 5 || oper_class == 6) &&
1707 target_channel < 14)
1708 band = IEEE80211_BAND_5GHZ;
1709 else
1710 band = target_channel < 14 ? IEEE80211_BAND_2GHZ :
1711 IEEE80211_BAND_5GHZ;
1712
1713 freq = ieee80211_channel_to_frequency(target_channel, band);
1714 if (freq == 0) {
1715 tdls_dbg(sdata, "Invalid channel in TDLS chan switch: %d\n",
1716 target_channel);
1717 return -EINVAL;
1718 }
1719
1720 chan = ieee80211_get_channel(sdata->local->hw.wiphy, freq);
1721 if (!chan) {
1722 tdls_dbg(sdata,
1723 "Unsupported channel for TDLS chan switch: %d\n",
1724 target_channel);
1725 return -EINVAL;
1726 }
1727
1728 ieee802_11_parse_elems(tf->u.chan_switch_req.variable,
1729 skb->len - baselen, false, &elems);
1730 if (elems.parse_error) {
1731 tdls_dbg(sdata, "Invalid IEs in TDLS channel switch req\n");
1732 return -EINVAL;
1733 }
1734
1735 if (!elems.ch_sw_timing || !elems.lnk_id) {
1736 tdls_dbg(sdata, "TDLS channel switch req - missing IEs\n");
1737 return -EINVAL;
1738 }
1739
Arik Nemtsov42d8d782015-07-08 15:41:46 +03001740 if (!elems.sec_chan_offs) {
1741 chan_type = NL80211_CHAN_HT20;
1742 } else {
1743 switch (elems.sec_chan_offs->sec_chan_offs) {
1744 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
1745 chan_type = NL80211_CHAN_HT40PLUS;
1746 break;
1747 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
1748 chan_type = NL80211_CHAN_HT40MINUS;
1749 break;
1750 default:
1751 chan_type = NL80211_CHAN_HT20;
1752 break;
1753 }
1754 }
1755
1756 cfg80211_chandef_create(&chandef, chan, chan_type);
1757
1758 /* we will be active on the TDLS link */
1759 if (!cfg80211_reg_can_beacon_relax(sdata->local->hw.wiphy, &chandef,
1760 sdata->wdev.iftype)) {
1761 tdls_dbg(sdata, "TDLS chan switch to forbidden channel\n");
1762 return -EINVAL;
1763 }
1764
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +02001765 mutex_lock(&local->sta_mtx);
1766 sta = sta_info_get(sdata, tf->sa);
1767 if (!sta || !test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH)) {
1768 tdls_dbg(sdata, "TDLS chan switch from non-peer sta %pM\n",
1769 tf->sa);
1770 ret = -EINVAL;
1771 goto out;
1772 }
1773
1774 params.sta = &sta->sta;
1775
1776 /* validate the initiator is set correctly */
1777 local_initiator =
1778 !memcmp(elems.lnk_id->init_sta, sdata->vif.addr, ETH_ALEN);
1779 if (local_initiator == sta->sta.tdls_initiator) {
1780 tdls_dbg(sdata, "TDLS chan switch invalid lnk-id initiator\n");
1781 ret = -EINVAL;
1782 goto out;
1783 }
1784
Arik Nemtsov42d8d782015-07-08 15:41:46 +03001785 /* peer should have known better */
1786 if (!sta->sta.ht_cap.ht_supported && elems.sec_chan_offs &&
1787 elems.sec_chan_offs->sec_chan_offs) {
1788 tdls_dbg(sdata, "TDLS chan switch - wide chan unsupported\n");
1789 ret = -ENOTSUPP;
1790 goto out;
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +02001791 }
1792
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +02001793 params.chandef = &chandef;
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +02001794 params.switch_time = le16_to_cpu(elems.ch_sw_timing->switch_time);
1795 params.switch_timeout = le16_to_cpu(elems.ch_sw_timing->switch_timeout);
1796
1797 params.tmpl_skb =
1798 ieee80211_tdls_ch_sw_resp_tmpl_get(sta,
1799 &params.ch_sw_tm_ie);
1800 if (!params.tmpl_skb) {
1801 ret = -ENOENT;
1802 goto out;
1803 }
1804
1805 drv_tdls_recv_channel_switch(sdata->local, sdata, &params);
1806
1807 tdls_dbg(sdata,
1808 "TDLS ch switch request received from %pM ch %d width %d\n",
1809 tf->sa, params.chandef->chan->center_freq,
1810 params.chandef->width);
1811out:
1812 mutex_unlock(&local->sta_mtx);
1813 dev_kfree_skb_any(params.tmpl_skb);
1814 return ret;
1815}
1816
Arik Nemtsovc8ff71e2015-07-08 15:41:45 +03001817static void
1818ieee80211_process_tdls_channel_switch(struct ieee80211_sub_if_data *sdata,
1819 struct sk_buff *skb)
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +02001820{
1821 struct ieee80211_tdls_data *tf = (void *)skb->data;
1822 struct wiphy *wiphy = sdata->local->hw.wiphy;
1823
Arik Nemtsovc8ff71e2015-07-08 15:41:45 +03001824 ASSERT_RTNL();
1825
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +02001826 /* make sure the driver supports it */
1827 if (!(wiphy->features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
1828 return;
1829
1830 /* we want to access the entire packet */
1831 if (skb_linearize(skb))
1832 return;
1833 /*
1834 * The packet/size was already validated by mac80211 Rx path, only look
1835 * at the action type.
1836 */
1837 switch (tf->action_code) {
1838 case WLAN_TDLS_CHANNEL_SWITCH_REQUEST:
1839 ieee80211_process_tdls_channel_switch_req(sdata, skb);
1840 break;
1841 case WLAN_TDLS_CHANNEL_SWITCH_RESPONSE:
1842 ieee80211_process_tdls_channel_switch_resp(sdata, skb);
1843 break;
1844 default:
1845 WARN_ON_ONCE(1);
1846 return;
1847 }
1848}
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03001849
1850void ieee80211_teardown_tdls_peers(struct ieee80211_sub_if_data *sdata)
1851{
1852 struct sta_info *sta;
1853 u16 reason = WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED;
1854
1855 rcu_read_lock();
1856 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
1857 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
1858 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1859 continue;
1860
1861 ieee80211_tdls_oper_request(&sdata->vif, sta->sta.addr,
1862 NL80211_TDLS_TEARDOWN, reason,
1863 GFP_ATOMIC);
1864 }
1865 rcu_read_unlock();
1866}
Arik Nemtsovc8ff71e2015-07-08 15:41:45 +03001867
1868void ieee80211_tdls_chsw_work(struct work_struct *wk)
1869{
1870 struct ieee80211_local *local =
1871 container_of(wk, struct ieee80211_local, tdls_chsw_work);
1872 struct ieee80211_sub_if_data *sdata;
1873 struct sk_buff *skb;
1874 struct ieee80211_tdls_data *tf;
1875
1876 rtnl_lock();
1877 while ((skb = skb_dequeue(&local->skb_queue_tdls_chsw))) {
1878 tf = (struct ieee80211_tdls_data *)skb->data;
1879 list_for_each_entry(sdata, &local->interfaces, list) {
1880 if (!ieee80211_sdata_running(sdata) ||
1881 sdata->vif.type != NL80211_IFTYPE_STATION ||
1882 !ether_addr_equal(tf->da, sdata->vif.addr))
1883 continue;
1884
1885 ieee80211_process_tdls_channel_switch(sdata, skb);
1886 break;
1887 }
1888
1889 kfree_skb(skb);
1890 }
1891 rtnl_unlock();
1892}