blob: 8fb314b182e20752d61e1fcd325c5921ccdcce3b [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 Nemtsov95224fe2014-05-01 10:17:28 +03007 *
8 * This file is GPLv2 as found in COPYING.
9 */
10
11#include <linux/ieee80211.h>
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +030012#include <linux/log2.h>
Arik Nemtsovc887f0d32014-06-11 17:18:25 +030013#include <net/cfg80211.h>
Arik Nemtsov95224fe2014-05-01 10:17:28 +030014#include "ieee80211_i.h"
Arik Nemtsovee10f2c2014-06-11 17:18:27 +030015#include "driver-ops.h"
Arik Nemtsov95224fe2014-05-01 10:17:28 +030016
Arik Nemtsov17e6a592014-06-11 17:18:20 +030017/* give usermode some time for retries in setting up the TDLS session */
18#define TDLS_PEER_SETUP_TIMEOUT (15 * HZ)
19
20void ieee80211_tdls_peer_del_work(struct work_struct *wk)
21{
22 struct ieee80211_sub_if_data *sdata;
23 struct ieee80211_local *local;
24
25 sdata = container_of(wk, struct ieee80211_sub_if_data,
Arik Nemtsov81dd2b82014-07-17 17:14:25 +030026 u.mgd.tdls_peer_del_work.work);
Arik Nemtsov17e6a592014-06-11 17:18:20 +030027 local = sdata->local;
28
29 mutex_lock(&local->mtx);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +030030 if (!is_zero_ether_addr(sdata->u.mgd.tdls_peer)) {
31 tdls_dbg(sdata, "TDLS del peer %pM\n", sdata->u.mgd.tdls_peer);
32 sta_info_destroy_addr(sdata, sdata->u.mgd.tdls_peer);
33 eth_zero_addr(sdata->u.mgd.tdls_peer);
Arik Nemtsov17e6a592014-06-11 17:18:20 +030034 }
35 mutex_unlock(&local->mtx);
36}
37
Arik Nemtsov95224fe2014-05-01 10:17:28 +030038static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
39{
40 u8 *pos = (void *)skb_put(skb, 7);
41
42 *pos++ = WLAN_EID_EXT_CAPABILITY;
43 *pos++ = 5; /* len */
44 *pos++ = 0x0;
45 *pos++ = 0x0;
46 *pos++ = 0x0;
47 *pos++ = 0x0;
48 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
49}
50
Arik Nemtsovf0d29cb2014-11-09 18:50:12 +020051static u8
52ieee80211_tdls_add_subband(struct ieee80211_sub_if_data *sdata,
53 struct sk_buff *skb, u16 start, u16 end,
54 u16 spacing)
55{
56 u8 subband_cnt = 0, ch_cnt = 0;
57 struct ieee80211_channel *ch;
58 struct cfg80211_chan_def chandef;
59 int i, subband_start;
60
61 for (i = start; i <= end; i += spacing) {
62 if (!ch_cnt)
63 subband_start = i;
64
65 ch = ieee80211_get_channel(sdata->local->hw.wiphy, i);
66 if (ch) {
67 /* we will be active on the channel */
68 u32 flags = IEEE80211_CHAN_DISABLED |
69 IEEE80211_CHAN_NO_IR;
70 cfg80211_chandef_create(&chandef, ch,
71 NL80211_CHAN_HT20);
72 if (cfg80211_chandef_usable(sdata->local->hw.wiphy,
73 &chandef, flags)) {
74 ch_cnt++;
75 continue;
76 }
77 }
78
79 if (ch_cnt) {
80 u8 *pos = skb_put(skb, 2);
81 *pos++ = ieee80211_frequency_to_channel(subband_start);
82 *pos++ = ch_cnt;
83
84 subband_cnt++;
85 ch_cnt = 0;
86 }
87 }
88
89 return subband_cnt;
90}
91
92static void
93ieee80211_tdls_add_supp_channels(struct ieee80211_sub_if_data *sdata,
94 struct sk_buff *skb)
95{
96 /*
97 * Add possible channels for TDLS. These are channels that are allowed
98 * to be active.
99 */
100 u8 subband_cnt;
101 u8 *pos = skb_put(skb, 2);
102
103 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
104
105 /*
106 * 5GHz and 2GHz channels numbers can overlap. Ignore this for now, as
107 * this doesn't happen in real world scenarios.
108 */
109
110 /* 2GHz, with 5MHz spacing */
111 subband_cnt = ieee80211_tdls_add_subband(sdata, skb, 2412, 2472, 5);
112
113 /* 5GHz, with 20MHz spacing */
114 subband_cnt += ieee80211_tdls_add_subband(sdata, skb, 5000, 5825, 20);
115
116 /* length */
117 *pos = 2 * subband_cnt;
118}
119
Arik Nemtsovdd8c0b02014-07-17 17:14:22 +0300120static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata,
121 u16 status_code)
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300122{
123 struct ieee80211_local *local = sdata->local;
124 u16 capab;
125
Arik Nemtsovdd8c0b02014-07-17 17:14:22 +0300126 /* The capability will be 0 when sending a failure code */
127 if (status_code != 0)
128 return 0;
129
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300130 capab = 0;
131 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
132 return capab;
133
134 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
135 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
136 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
137 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
138
139 return capab;
140}
141
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300142static void ieee80211_tdls_add_link_ie(struct ieee80211_sub_if_data *sdata,
143 struct sk_buff *skb, const u8 *peer,
144 bool initiator)
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300145{
146 struct ieee80211_tdls_lnkie *lnkid;
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300147 const u8 *init_addr, *rsp_addr;
148
149 if (initiator) {
150 init_addr = sdata->vif.addr;
151 rsp_addr = peer;
152 } else {
153 init_addr = peer;
154 rsp_addr = sdata->vif.addr;
155 }
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300156
157 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
158
159 lnkid->ie_type = WLAN_EID_LINK_ID;
160 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
161
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300162 memcpy(lnkid->bssid, sdata->u.mgd.bssid, ETH_ALEN);
163 memcpy(lnkid->init_sta, init_addr, ETH_ALEN);
164 memcpy(lnkid->resp_sta, rsp_addr, ETH_ALEN);
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300165}
166
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300167/* translate numbering in the WMM parameter IE to the mac80211 notation */
168static enum ieee80211_ac_numbers ieee80211_ac_from_wmm(int ac)
169{
170 switch (ac) {
171 default:
172 WARN_ON_ONCE(1);
173 case 0:
174 return IEEE80211_AC_BE;
175 case 1:
176 return IEEE80211_AC_BK;
177 case 2:
178 return IEEE80211_AC_VI;
179 case 3:
180 return IEEE80211_AC_VO;
181 }
182}
183
184static u8 ieee80211_wmm_aci_aifsn(int aifsn, bool acm, int aci)
185{
186 u8 ret;
187
188 ret = aifsn & 0x0f;
189 if (acm)
190 ret |= 0x10;
191 ret |= (aci << 5) & 0x60;
192 return ret;
193}
194
195static u8 ieee80211_wmm_ecw(u16 cw_min, u16 cw_max)
196{
197 return ((ilog2(cw_min + 1) << 0x0) & 0x0f) |
198 ((ilog2(cw_max + 1) << 0x4) & 0xf0);
199}
200
201static void ieee80211_tdls_add_wmm_param_ie(struct ieee80211_sub_if_data *sdata,
202 struct sk_buff *skb)
203{
204 struct ieee80211_wmm_param_ie *wmm;
205 struct ieee80211_tx_queue_params *txq;
206 int i;
207
208 wmm = (void *)skb_put(skb, sizeof(*wmm));
209 memset(wmm, 0, sizeof(*wmm));
210
211 wmm->element_id = WLAN_EID_VENDOR_SPECIFIC;
212 wmm->len = sizeof(*wmm) - 2;
213
214 wmm->oui[0] = 0x00; /* Microsoft OUI 00:50:F2 */
215 wmm->oui[1] = 0x50;
216 wmm->oui[2] = 0xf2;
217 wmm->oui_type = 2; /* WME */
218 wmm->oui_subtype = 1; /* WME param */
219 wmm->version = 1; /* WME ver */
220 wmm->qos_info = 0; /* U-APSD not in use */
221
222 /*
223 * Use the EDCA parameters defined for the BSS, or default if the AP
224 * doesn't support it, as mandated by 802.11-2012 section 10.22.4
225 */
226 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
227 txq = &sdata->tx_conf[ieee80211_ac_from_wmm(i)];
228 wmm->ac[i].aci_aifsn = ieee80211_wmm_aci_aifsn(txq->aifs,
229 txq->acm, i);
230 wmm->ac[i].cw = ieee80211_wmm_ecw(txq->cw_min, txq->cw_max);
231 wmm->ac[i].txop_limit = cpu_to_le16(txq->txop);
232 }
233}
234
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300235static void
236ieee80211_tdls_add_setup_start_ies(struct ieee80211_sub_if_data *sdata,
237 struct sk_buff *skb, const u8 *peer,
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300238 u8 action_code, bool initiator,
239 const u8 *extra_ies, size_t extra_ies_len)
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300240{
241 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsov40b861a2014-07-17 17:14:23 +0300242 struct ieee80211_local *local = sdata->local;
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300243 struct ieee80211_supported_band *sband;
244 struct ieee80211_sta_ht_cap ht_cap;
245 struct sta_info *sta = NULL;
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300246 size_t offset = 0, noffset;
247 u8 *pos;
248
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300249 rcu_read_lock();
250
251 /* we should have the peer STA if we're already responding */
252 if (action_code == WLAN_TDLS_SETUP_RESPONSE) {
253 sta = sta_info_get(sdata, peer);
254 if (WARN_ON_ONCE(!sta)) {
255 rcu_read_unlock();
256 return;
257 }
258 }
259
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300260 ieee80211_add_srates_ie(sdata, skb, false, band);
261 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovf0d29cb2014-11-09 18:50:12 +0200262 ieee80211_tdls_add_supp_channels(sdata, skb);
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300263
264 /* add any custom IEs that go before Extended Capabilities */
265 if (extra_ies_len) {
266 static const u8 before_ext_cap[] = {
267 WLAN_EID_SUPP_RATES,
268 WLAN_EID_COUNTRY,
269 WLAN_EID_EXT_SUPP_RATES,
270 WLAN_EID_SUPPORTED_CHANNELS,
271 WLAN_EID_RSN,
272 };
273 noffset = ieee80211_ie_split(extra_ies, extra_ies_len,
274 before_ext_cap,
275 ARRAY_SIZE(before_ext_cap),
276 offset);
277 pos = skb_put(skb, noffset - offset);
278 memcpy(pos, extra_ies + offset, noffset - offset);
279 offset = noffset;
280 }
281
282 ieee80211_tdls_add_ext_capab(skb);
283
Arik Nemtsov40b861a2014-07-17 17:14:23 +0300284 /* add the QoS element if we support it */
285 if (local->hw.queues >= IEEE80211_NUM_ACS &&
286 action_code != WLAN_PUB_ACTION_TDLS_DISCOVER_RES)
287 ieee80211_add_wmm_info_ie(skb_put(skb, 9), 0); /* no U-APSD */
288
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300289 /* add any custom IEs that go before HT capabilities */
290 if (extra_ies_len) {
291 static const u8 before_ht_cap[] = {
292 WLAN_EID_SUPP_RATES,
293 WLAN_EID_COUNTRY,
294 WLAN_EID_EXT_SUPP_RATES,
295 WLAN_EID_SUPPORTED_CHANNELS,
296 WLAN_EID_RSN,
297 WLAN_EID_EXT_CAPABILITY,
298 WLAN_EID_QOS_CAPA,
299 WLAN_EID_FAST_BSS_TRANSITION,
300 WLAN_EID_TIMEOUT_INTERVAL,
301 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
302 };
303 noffset = ieee80211_ie_split(extra_ies, extra_ies_len,
304 before_ht_cap,
305 ARRAY_SIZE(before_ht_cap),
306 offset);
307 pos = skb_put(skb, noffset - offset);
308 memcpy(pos, extra_ies + offset, noffset - offset);
309 offset = noffset;
310 }
311
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300312 /*
313 * with TDLS we can switch channels, and HT-caps are not necessarily
314 * the same on all bands. The specification limits the setup to a
315 * single HT-cap, so use the current band for now.
316 */
317 sband = local->hw.wiphy->bands[band];
318 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
319 if ((action_code == WLAN_TDLS_SETUP_REQUEST ||
320 action_code == WLAN_TDLS_SETUP_RESPONSE) &&
321 ht_cap.ht_supported && (!sta || sta->sta.ht_cap.ht_supported)) {
322 if (action_code == WLAN_TDLS_SETUP_REQUEST) {
323 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
324
325 /* disable SMPS in TDLS initiator */
326 ht_cap.cap |= (WLAN_HT_CAP_SM_PS_DISABLED
327 << IEEE80211_HT_CAP_SM_PS_SHIFT);
328 } else {
329 /* disable SMPS in TDLS responder */
330 sta->sta.ht_cap.cap |=
331 (WLAN_HT_CAP_SM_PS_DISABLED
332 << IEEE80211_HT_CAP_SM_PS_SHIFT);
333
334 /* the peer caps are already intersected with our own */
335 memcpy(&ht_cap, &sta->sta.ht_cap, sizeof(ht_cap));
336 }
337
338 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
339 ieee80211_ie_build_ht_cap(pos, &ht_cap, ht_cap.cap);
340 }
341
342 rcu_read_unlock();
343
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300344 /* add any remaining IEs */
345 if (extra_ies_len) {
346 noffset = extra_ies_len;
347 pos = skb_put(skb, noffset - offset);
348 memcpy(pos, extra_ies + offset, noffset - offset);
349 }
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300350
351 ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator);
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300352}
353
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300354static void
355ieee80211_tdls_add_setup_cfm_ies(struct ieee80211_sub_if_data *sdata,
356 struct sk_buff *skb, const u8 *peer,
357 bool initiator, const u8 *extra_ies,
358 size_t extra_ies_len)
359{
360 struct ieee80211_local *local = sdata->local;
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300361 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300362 size_t offset = 0, noffset;
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300363 struct sta_info *sta, *ap_sta;
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300364 u8 *pos;
365
366 rcu_read_lock();
367
368 sta = sta_info_get(sdata, peer);
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300369 ap_sta = sta_info_get(sdata, ifmgd->bssid);
370 if (WARN_ON_ONCE(!sta || !ap_sta)) {
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300371 rcu_read_unlock();
372 return;
373 }
374
375 /* add any custom IEs that go before the QoS IE */
376 if (extra_ies_len) {
377 static const u8 before_qos[] = {
378 WLAN_EID_RSN,
379 };
380 noffset = ieee80211_ie_split(extra_ies, extra_ies_len,
381 before_qos,
382 ARRAY_SIZE(before_qos),
383 offset);
384 pos = skb_put(skb, noffset - offset);
385 memcpy(pos, extra_ies + offset, noffset - offset);
386 offset = noffset;
387 }
388
389 /* add the QoS param IE if both the peer and we support it */
Johannes Berga74a8c82014-07-22 14:50:47 +0200390 if (local->hw.queues >= IEEE80211_NUM_ACS && sta->sta.wme)
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300391 ieee80211_tdls_add_wmm_param_ie(sdata, skb);
392
Arik Nemtsov13cc8a42014-07-17 17:14:26 +0300393 /* add any custom IEs that go before HT operation */
394 if (extra_ies_len) {
395 static const u8 before_ht_op[] = {
396 WLAN_EID_RSN,
397 WLAN_EID_QOS_CAPA,
398 WLAN_EID_FAST_BSS_TRANSITION,
399 WLAN_EID_TIMEOUT_INTERVAL,
400 };
401 noffset = ieee80211_ie_split(extra_ies, extra_ies_len,
402 before_ht_op,
403 ARRAY_SIZE(before_ht_op),
404 offset);
405 pos = skb_put(skb, noffset - offset);
406 memcpy(pos, extra_ies + offset, noffset - offset);
407 offset = noffset;
408 }
409
410 /* if HT support is only added in TDLS, we need an HT-operation IE */
411 if (!ap_sta->sta.ht_cap.ht_supported && sta->sta.ht_cap.ht_supported) {
412 struct ieee80211_chanctx_conf *chanctx_conf =
413 rcu_dereference(sdata->vif.chanctx_conf);
414 if (!WARN_ON(!chanctx_conf)) {
415 pos = skb_put(skb, 2 +
416 sizeof(struct ieee80211_ht_operation));
417 /* send an empty HT operation IE */
418 ieee80211_ie_build_ht_oper(pos, &sta->sta.ht_cap,
419 &chanctx_conf->def, 0);
420 }
421 }
422
423 rcu_read_unlock();
424
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300425 /* add any remaining IEs */
426 if (extra_ies_len) {
427 noffset = extra_ies_len;
428 pos = skb_put(skb, noffset - offset);
429 memcpy(pos, extra_ies + offset, noffset - offset);
430 }
431
432 ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator);
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300433}
434
Arik Nemtsov46792a22014-07-17 17:14:19 +0300435static void ieee80211_tdls_add_ies(struct ieee80211_sub_if_data *sdata,
436 struct sk_buff *skb, const u8 *peer,
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300437 u8 action_code, u16 status_code,
438 bool initiator, const u8 *extra_ies,
439 size_t extra_ies_len)
Arik Nemtsov46792a22014-07-17 17:14:19 +0300440{
Arik Nemtsov46792a22014-07-17 17:14:19 +0300441 switch (action_code) {
442 case WLAN_TDLS_SETUP_REQUEST:
443 case WLAN_TDLS_SETUP_RESPONSE:
444 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300445 if (status_code == 0)
446 ieee80211_tdls_add_setup_start_ies(sdata, skb, peer,
447 action_code,
448 initiator,
449 extra_ies,
450 extra_ies_len);
Arik Nemtsov46792a22014-07-17 17:14:19 +0300451 break;
452 case WLAN_TDLS_SETUP_CONFIRM:
Arik Nemtsov6f7eaa42014-07-17 17:14:24 +0300453 if (status_code == 0)
454 ieee80211_tdls_add_setup_cfm_ies(sdata, skb, peer,
455 initiator, extra_ies,
456 extra_ies_len);
457 break;
Arik Nemtsov46792a22014-07-17 17:14:19 +0300458 case WLAN_TDLS_TEARDOWN:
459 case WLAN_TDLS_DISCOVERY_REQUEST:
Arik Nemtsovf09a87d2014-07-17 17:14:20 +0300460 if (extra_ies_len)
461 memcpy(skb_put(skb, extra_ies_len), extra_ies,
462 extra_ies_len);
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300463 if (status_code == 0 || action_code == WLAN_TDLS_TEARDOWN)
464 ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator);
Arik Nemtsov46792a22014-07-17 17:14:19 +0300465 break;
466 }
467
Arik Nemtsov46792a22014-07-17 17:14:19 +0300468}
469
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300470static int
471ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200472 const u8 *peer, u8 action_code, u8 dialog_token,
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300473 u16 status_code, struct sk_buff *skb)
474{
475 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300476 struct ieee80211_tdls_data *tf;
477
478 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
479
480 memcpy(tf->da, peer, ETH_ALEN);
481 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
482 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
483 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
484
Arik Nemtsov59cd85c2014-09-09 17:11:02 +0300485 /* network header is after the ethernet header */
486 skb_set_network_header(skb, ETH_HLEN);
487
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300488 switch (action_code) {
489 case WLAN_TDLS_SETUP_REQUEST:
490 tf->category = WLAN_CATEGORY_TDLS;
491 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
492
493 skb_put(skb, sizeof(tf->u.setup_req));
494 tf->u.setup_req.dialog_token = dialog_token;
495 tf->u.setup_req.capability =
Arik Nemtsovdd8c0b02014-07-17 17:14:22 +0300496 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata,
497 status_code));
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300498 break;
499 case WLAN_TDLS_SETUP_RESPONSE:
500 tf->category = WLAN_CATEGORY_TDLS;
501 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
502
503 skb_put(skb, sizeof(tf->u.setup_resp));
504 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
505 tf->u.setup_resp.dialog_token = dialog_token;
506 tf->u.setup_resp.capability =
Arik Nemtsovdd8c0b02014-07-17 17:14:22 +0300507 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata,
508 status_code));
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300509 break;
510 case WLAN_TDLS_SETUP_CONFIRM:
511 tf->category = WLAN_CATEGORY_TDLS;
512 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
513
514 skb_put(skb, sizeof(tf->u.setup_cfm));
515 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
516 tf->u.setup_cfm.dialog_token = dialog_token;
517 break;
518 case WLAN_TDLS_TEARDOWN:
519 tf->category = WLAN_CATEGORY_TDLS;
520 tf->action_code = WLAN_TDLS_TEARDOWN;
521
522 skb_put(skb, sizeof(tf->u.teardown));
523 tf->u.teardown.reason_code = cpu_to_le16(status_code);
524 break;
525 case WLAN_TDLS_DISCOVERY_REQUEST:
526 tf->category = WLAN_CATEGORY_TDLS;
527 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
528
529 skb_put(skb, sizeof(tf->u.discover_req));
530 tf->u.discover_req.dialog_token = dialog_token;
531 break;
532 default:
533 return -EINVAL;
534 }
535
536 return 0;
537}
538
539static int
540ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200541 const u8 *peer, u8 action_code, u8 dialog_token,
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300542 u16 status_code, struct sk_buff *skb)
543{
544 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300545 struct ieee80211_mgmt *mgmt;
546
547 mgmt = (void *)skb_put(skb, 24);
548 memset(mgmt, 0, 24);
549 memcpy(mgmt->da, peer, ETH_ALEN);
550 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
551 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
552
553 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
554 IEEE80211_STYPE_ACTION);
555
556 switch (action_code) {
557 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
558 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
559 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
560 mgmt->u.action.u.tdls_discover_resp.action_code =
561 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
562 mgmt->u.action.u.tdls_discover_resp.dialog_token =
563 dialog_token;
564 mgmt->u.action.u.tdls_discover_resp.capability =
Arik Nemtsovdd8c0b02014-07-17 17:14:22 +0300565 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata,
566 status_code));
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300567 break;
568 default:
569 return -EINVAL;
570 }
571
572 return 0;
573}
574
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300575static int
576ieee80211_tdls_prep_mgmt_packet(struct wiphy *wiphy, struct net_device *dev,
577 const u8 *peer, u8 action_code,
578 u8 dialog_token, u16 status_code,
Arik Nemtsov2fb6b9b2014-06-11 17:18:22 +0300579 u32 peer_capability, bool initiator,
580 const u8 *extra_ies, size_t extra_ies_len)
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300581{
582 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
583 struct ieee80211_local *local = sdata->local;
584 struct sk_buff *skb = NULL;
Liad Kaufman1277b4a2014-11-09 18:50:08 +0200585 u32 flags = 0;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300586 bool send_direct;
Arik Nemtsov626911c2014-07-17 17:14:17 +0300587 struct sta_info *sta;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300588 int ret;
589
Liad Kaufman1277b4a2014-11-09 18:50:08 +0200590 skb = netdev_alloc_skb(dev,
591 local->hw.extra_tx_headroom +
592 max(sizeof(struct ieee80211_mgmt),
593 sizeof(struct ieee80211_tdls_data)) +
594 50 + /* supported rates */
595 7 + /* ext capab */
596 26 + /* max(WMM-info, WMM-param) */
597 2 + max(sizeof(struct ieee80211_ht_cap),
598 sizeof(struct ieee80211_ht_operation)) +
Arik Nemtsovf0d29cb2014-11-09 18:50:12 +0200599 50 + /* supported channels */
Liad Kaufman1277b4a2014-11-09 18:50:08 +0200600 extra_ies_len +
601 sizeof(struct ieee80211_tdls_lnkie));
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300602 if (!skb)
603 return -ENOMEM;
604
605 skb_reserve(skb, local->hw.extra_tx_headroom);
606
607 switch (action_code) {
608 case WLAN_TDLS_SETUP_REQUEST:
609 case WLAN_TDLS_SETUP_RESPONSE:
610 case WLAN_TDLS_SETUP_CONFIRM:
611 case WLAN_TDLS_TEARDOWN:
612 case WLAN_TDLS_DISCOVERY_REQUEST:
613 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
614 action_code, dialog_token,
615 status_code, skb);
616 send_direct = false;
617 break;
618 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
619 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
620 dialog_token, status_code,
621 skb);
622 send_direct = true;
623 break;
624 default:
625 ret = -ENOTSUPP;
626 break;
627 }
628
629 if (ret < 0)
630 goto fail;
631
Arik Nemtsov626911c2014-07-17 17:14:17 +0300632 rcu_read_lock();
633 sta = sta_info_get(sdata, peer);
634
635 /* infer the initiator if we can, to support old userspace */
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300636 switch (action_code) {
637 case WLAN_TDLS_SETUP_REQUEST:
Arik Nemtsov8b941482014-10-22 12:32:48 +0300638 if (sta) {
Arik Nemtsov626911c2014-07-17 17:14:17 +0300639 set_sta_flag(sta, WLAN_STA_TDLS_INITIATOR);
Arik Nemtsov8b941482014-10-22 12:32:48 +0300640 sta->sta.tdls_initiator = false;
641 }
Arik Nemtsov626911c2014-07-17 17:14:17 +0300642 /* fall-through */
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300643 case WLAN_TDLS_SETUP_CONFIRM:
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300644 case WLAN_TDLS_DISCOVERY_REQUEST:
Arik Nemtsov626911c2014-07-17 17:14:17 +0300645 initiator = true;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300646 break;
647 case WLAN_TDLS_SETUP_RESPONSE:
Arik Nemtsov626911c2014-07-17 17:14:17 +0300648 /*
649 * In some testing scenarios, we send a request and response.
650 * Make the last packet sent take effect for the initiator
651 * value.
652 */
Arik Nemtsov8b941482014-10-22 12:32:48 +0300653 if (sta) {
Arik Nemtsov626911c2014-07-17 17:14:17 +0300654 clear_sta_flag(sta, WLAN_STA_TDLS_INITIATOR);
Arik Nemtsov8b941482014-10-22 12:32:48 +0300655 sta->sta.tdls_initiator = true;
656 }
Arik Nemtsov626911c2014-07-17 17:14:17 +0300657 /* fall-through */
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300658 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
Arik Nemtsov626911c2014-07-17 17:14:17 +0300659 initiator = false;
Arik Nemtsov2fb6b9b2014-06-11 17:18:22 +0300660 break;
661 case WLAN_TDLS_TEARDOWN:
662 /* any value is ok */
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300663 break;
664 default:
665 ret = -ENOTSUPP;
Arik Nemtsov626911c2014-07-17 17:14:17 +0300666 break;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300667 }
668
Arik Nemtsov46792a22014-07-17 17:14:19 +0300669 if (sta && test_sta_flag(sta, WLAN_STA_TDLS_INITIATOR))
670 initiator = true;
Arik Nemtsov2fb6b9b2014-06-11 17:18:22 +0300671
Arik Nemtsov626911c2014-07-17 17:14:17 +0300672 rcu_read_unlock();
673 if (ret < 0)
674 goto fail;
675
Arik Nemtsov1606ef42014-07-17 17:14:21 +0300676 ieee80211_tdls_add_ies(sdata, skb, peer, action_code, status_code,
677 initiator, extra_ies, extra_ies_len);
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300678 if (send_direct) {
679 ieee80211_tx_skb(sdata, skb);
680 return 0;
681 }
682
683 /*
684 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
685 * we should default to AC_VI.
686 */
687 switch (action_code) {
688 case WLAN_TDLS_SETUP_REQUEST:
689 case WLAN_TDLS_SETUP_RESPONSE:
690 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
691 skb->priority = 2;
692 break;
693 default:
694 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
695 skb->priority = 5;
696 break;
697 }
698
Liad Kaufman1277b4a2014-11-09 18:50:08 +0200699 /*
700 * Set the WLAN_TDLS_TEARDOWN flag to indicate a teardown in progress.
701 * Later, if no ACK is returned from peer, we will re-send the teardown
702 * packet through the AP.
703 */
704 if ((action_code == WLAN_TDLS_TEARDOWN) &&
705 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) {
706 struct sta_info *sta = NULL;
707 bool try_resend; /* Should we keep skb for possible resend */
708
709 /* If not sending directly to peer - no point in keeping skb */
710 rcu_read_lock();
711 sta = sta_info_get(sdata, peer);
712 try_resend = sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
713 rcu_read_unlock();
714
715 spin_lock_bh(&sdata->u.mgd.teardown_lock);
716 if (try_resend && !sdata->u.mgd.teardown_skb) {
717 /* Mark it as requiring TX status callback */
718 flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
719 IEEE80211_TX_INTFL_MLME_CONN_TX;
720
721 /*
722 * skb is copied since mac80211 will later set
723 * properties that might not be the same as the AP,
724 * such as encryption, QoS, addresses, etc.
725 *
726 * No problem if skb_copy() fails, so no need to check.
727 */
728 sdata->u.mgd.teardown_skb = skb_copy(skb, GFP_ATOMIC);
729 sdata->u.mgd.orig_teardown_skb = skb;
730 }
731 spin_unlock_bh(&sdata->u.mgd.teardown_lock);
732 }
733
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300734 /* disable bottom halves when entering the Tx path */
735 local_bh_disable();
Liad Kaufman1277b4a2014-11-09 18:50:08 +0200736 __ieee80211_subif_start_xmit(skb, dev, flags);
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300737 local_bh_enable();
738
739 return ret;
740
741fail:
742 dev_kfree_skb(skb);
743 return ret;
744}
745
Arik Nemtsov191dd462014-06-11 17:18:23 +0300746static int
747ieee80211_tdls_mgmt_setup(struct wiphy *wiphy, struct net_device *dev,
748 const u8 *peer, u8 action_code, u8 dialog_token,
749 u16 status_code, u32 peer_capability, bool initiator,
750 const u8 *extra_ies, size_t extra_ies_len)
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300751{
752 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
753 struct ieee80211_local *local = sdata->local;
754 int ret;
755
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300756 mutex_lock(&local->mtx);
757
758 /* we don't support concurrent TDLS peer setups */
Arik Nemtsov81dd2b82014-07-17 17:14:25 +0300759 if (!is_zero_ether_addr(sdata->u.mgd.tdls_peer) &&
760 !ether_addr_equal(sdata->u.mgd.tdls_peer, peer)) {
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300761 ret = -EBUSY;
762 goto exit;
763 }
764
Arik Nemtsov7adc3e42014-06-11 17:18:26 +0300765 /*
766 * make sure we have a STA representing the peer so we drop or buffer
767 * non-TDLS-setup frames to the peer. We can't send other packets
Arik Nemtsov6ae32e52014-07-17 17:14:18 +0300768 * during setup through the AP path.
769 * Allow error packets to be sent - sometimes we don't even add a STA
770 * before failing the setup.
Arik Nemtsov7adc3e42014-06-11 17:18:26 +0300771 */
Arik Nemtsov6ae32e52014-07-17 17:14:18 +0300772 if (status_code == 0) {
773 rcu_read_lock();
774 if (!sta_info_get(sdata, peer)) {
775 rcu_read_unlock();
776 ret = -ENOLINK;
777 goto exit;
778 }
Arik Nemtsov7adc3e42014-06-11 17:18:26 +0300779 rcu_read_unlock();
Arik Nemtsov7adc3e42014-06-11 17:18:26 +0300780 }
Arik Nemtsov7adc3e42014-06-11 17:18:26 +0300781
Arik Nemtsovdb67d662014-06-11 17:18:24 +0300782 ieee80211_flush_queues(local, sdata);
783
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300784 ret = ieee80211_tdls_prep_mgmt_packet(wiphy, dev, peer, action_code,
785 dialog_token, status_code,
Arik Nemtsov2fb6b9b2014-06-11 17:18:22 +0300786 peer_capability, initiator,
787 extra_ies, extra_ies_len);
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300788 if (ret < 0)
789 goto exit;
790
Arik Nemtsov81dd2b82014-07-17 17:14:25 +0300791 memcpy(sdata->u.mgd.tdls_peer, peer, ETH_ALEN);
Arik Nemtsov191dd462014-06-11 17:18:23 +0300792 ieee80211_queue_delayed_work(&sdata->local->hw,
Arik Nemtsov81dd2b82014-07-17 17:14:25 +0300793 &sdata->u.mgd.tdls_peer_del_work,
Arik Nemtsov191dd462014-06-11 17:18:23 +0300794 TDLS_PEER_SETUP_TIMEOUT);
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300795
796exit:
797 mutex_unlock(&local->mtx);
Arik Nemtsov191dd462014-06-11 17:18:23 +0300798 return ret;
799}
800
Arik Nemtsovdb67d662014-06-11 17:18:24 +0300801static int
802ieee80211_tdls_mgmt_teardown(struct wiphy *wiphy, struct net_device *dev,
803 const u8 *peer, u8 action_code, u8 dialog_token,
804 u16 status_code, u32 peer_capability,
805 bool initiator, const u8 *extra_ies,
806 size_t extra_ies_len)
807{
808 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
809 struct ieee80211_local *local = sdata->local;
810 struct sta_info *sta;
811 int ret;
812
813 /*
814 * No packets can be transmitted to the peer via the AP during setup -
815 * the STA is set as a TDLS peer, but is not authorized.
816 * During teardown, we prevent direct transmissions by stopping the
817 * queues and flushing all direct packets.
818 */
819 ieee80211_stop_vif_queues(local, sdata,
820 IEEE80211_QUEUE_STOP_REASON_TDLS_TEARDOWN);
821 ieee80211_flush_queues(local, sdata);
822
823 ret = ieee80211_tdls_prep_mgmt_packet(wiphy, dev, peer, action_code,
824 dialog_token, status_code,
825 peer_capability, initiator,
826 extra_ies, extra_ies_len);
827 if (ret < 0)
828 sdata_err(sdata, "Failed sending TDLS teardown packet %d\n",
829 ret);
830
831 /*
832 * Remove the STA AUTH flag to force further traffic through the AP. If
833 * the STA was unreachable, it was already removed.
834 */
835 rcu_read_lock();
836 sta = sta_info_get(sdata, peer);
837 if (sta)
838 clear_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
839 rcu_read_unlock();
840
841 ieee80211_wake_vif_queues(local, sdata,
842 IEEE80211_QUEUE_STOP_REASON_TDLS_TEARDOWN);
843
844 return 0;
845}
846
Arik Nemtsov191dd462014-06-11 17:18:23 +0300847int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
848 const u8 *peer, u8 action_code, u8 dialog_token,
849 u16 status_code, u32 peer_capability,
850 bool initiator, const u8 *extra_ies,
851 size_t extra_ies_len)
852{
853 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
854 int ret;
855
856 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
857 return -ENOTSUPP;
858
859 /* make sure we are in managed mode, and associated */
860 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
861 !sdata->u.mgd.associated)
862 return -EINVAL;
863
864 switch (action_code) {
865 case WLAN_TDLS_SETUP_REQUEST:
866 case WLAN_TDLS_SETUP_RESPONSE:
867 ret = ieee80211_tdls_mgmt_setup(wiphy, dev, peer, action_code,
868 dialog_token, status_code,
869 peer_capability, initiator,
870 extra_ies, extra_ies_len);
871 break;
872 case WLAN_TDLS_TEARDOWN:
Arik Nemtsovdb67d662014-06-11 17:18:24 +0300873 ret = ieee80211_tdls_mgmt_teardown(wiphy, dev, peer,
874 action_code, dialog_token,
875 status_code,
876 peer_capability, initiator,
877 extra_ies, extra_ies_len);
878 break;
Arik Nemtsov191dd462014-06-11 17:18:23 +0300879 case WLAN_TDLS_DISCOVERY_REQUEST:
Arik Nemtsovee10f2c2014-06-11 17:18:27 +0300880 /*
881 * Protect the discovery so we can hear the TDLS discovery
882 * response frame. It is transmitted directly and not buffered
883 * by the AP.
884 */
885 drv_mgd_protect_tdls_discover(sdata->local, sdata);
886 /* fall-through */
887 case WLAN_TDLS_SETUP_CONFIRM:
Arik Nemtsov191dd462014-06-11 17:18:23 +0300888 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
889 /* no special handling */
890 ret = ieee80211_tdls_prep_mgmt_packet(wiphy, dev, peer,
891 action_code,
892 dialog_token,
893 status_code,
894 peer_capability,
895 initiator, extra_ies,
896 extra_ies_len);
897 break;
898 default:
899 ret = -EOPNOTSUPP;
900 break;
901 }
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300902
903 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM status %d\n",
904 action_code, peer, ret);
905 return ret;
906}
907
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300908int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200909 const u8 *peer, enum nl80211_tdls_operation oper)
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300910{
911 struct sta_info *sta;
912 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300913 struct ieee80211_local *local = sdata->local;
914 int ret;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300915
916 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
917 return -ENOTSUPP;
918
919 if (sdata->vif.type != NL80211_IFTYPE_STATION)
920 return -EINVAL;
921
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300922 switch (oper) {
923 case NL80211_TDLS_ENABLE_LINK:
924 case NL80211_TDLS_DISABLE_LINK:
925 break;
926 case NL80211_TDLS_TEARDOWN:
927 case NL80211_TDLS_SETUP:
928 case NL80211_TDLS_DISCOVERY_REQ:
929 /* We don't support in-driver setup/teardown/discovery */
930 return -ENOTSUPP;
931 }
932
933 mutex_lock(&local->mtx);
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300934 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
935
936 switch (oper) {
937 case NL80211_TDLS_ENABLE_LINK:
938 rcu_read_lock();
939 sta = sta_info_get(sdata, peer);
940 if (!sta) {
941 rcu_read_unlock();
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300942 ret = -ENOLINK;
943 break;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300944 }
945
946 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
947 rcu_read_unlock();
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300948
Arik Nemtsov81dd2b82014-07-17 17:14:25 +0300949 WARN_ON_ONCE(is_zero_ether_addr(sdata->u.mgd.tdls_peer) ||
950 !ether_addr_equal(sdata->u.mgd.tdls_peer, peer));
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300951 ret = 0;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300952 break;
953 case NL80211_TDLS_DISABLE_LINK:
Liad Kaufmanbb3f8482014-07-17 17:14:31 +0300954 /*
955 * The teardown message in ieee80211_tdls_mgmt_teardown() was
956 * created while the queues were stopped, so it might still be
957 * pending. Before flushing the queues we need to be sure the
958 * message is handled by the tasklet handling pending messages,
959 * otherwise we might start destroying the station before
960 * sending the teardown packet.
961 * Note that this only forces the tasklet to flush pendings -
962 * not to stop the tasklet from rescheduling itself.
963 */
964 tasklet_kill(&local->tx_pending_tasklet);
Arik Nemtsovdb67d662014-06-11 17:18:24 +0300965 /* flush a potentially queued teardown packet */
966 ieee80211_flush_queues(local, sdata);
967
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300968 ret = sta_info_destroy_addr(sdata, peer);
969 break;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300970 default:
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300971 ret = -ENOTSUPP;
972 break;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300973 }
974
Arik Nemtsov81dd2b82014-07-17 17:14:25 +0300975 if (ret == 0 && ether_addr_equal(sdata->u.mgd.tdls_peer, peer)) {
976 cancel_delayed_work(&sdata->u.mgd.tdls_peer_del_work);
977 eth_zero_addr(sdata->u.mgd.tdls_peer);
Arik Nemtsov17e6a592014-06-11 17:18:20 +0300978 }
979
980 mutex_unlock(&local->mtx);
981 return ret;
Arik Nemtsov95224fe2014-05-01 10:17:28 +0300982}
Arik Nemtsovc887f0d32014-06-11 17:18:25 +0300983
984void ieee80211_tdls_oper_request(struct ieee80211_vif *vif, const u8 *peer,
985 enum nl80211_tdls_operation oper,
986 u16 reason_code, gfp_t gfp)
987{
988 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
989
990 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc) {
991 sdata_err(sdata, "Discarding TDLS oper %d - not STA or disconnected\n",
992 oper);
993 return;
994 }
995
996 cfg80211_tdls_oper_request(sdata->dev, peer, oper, reason_code, gfp);
997}
998EXPORT_SYMBOL(ieee80211_tdls_oper_request);