mac80211: remove useless skb->encapsulation check
[linux-2.6-block.git] / net / mac80211 / cfg.c
CommitLineData
f0706e82
JB
1/*
2 * mac80211 configuration hooks for cfg80211
3 *
026331c4 4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
d98ad83e 5 * Copyright 2013-2014 Intel Mobile Communications GmbH
f0706e82
JB
6 *
7 * This file is GPLv2 as found in COPYING.
8 */
9
e8cbb4cb 10#include <linux/ieee80211.h>
f0706e82
JB
11#include <linux/nl80211.h>
12#include <linux/rtnetlink.h>
5a0e3ad6 13#include <linux/slab.h>
881d966b 14#include <net/net_namespace.h>
5dfdaf58 15#include <linux/rcupdate.h>
dfe018bf 16#include <linux/if_ether.h>
f0706e82
JB
17#include <net/cfg80211.h>
18#include "ieee80211_i.h"
24487981 19#include "driver-ops.h"
e0eb6859 20#include "cfg.h"
2c8dccc7 21#include "rate.h"
c5dd9c2b 22#include "mesh.h"
02219b3a 23#include "wme.h"
c5dd9c2b 24
552bff0c
JB
25static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
26 const char *name,
6bab2e19 27 unsigned char name_assign_type,
84efbb84
JB
28 enum nl80211_iftype type,
29 u32 *flags,
30 struct vif_params *params)
f0706e82
JB
31{
32 struct ieee80211_local *local = wiphy_priv(wiphy);
84efbb84 33 struct wireless_dev *wdev;
8cc9a739
MW
34 struct ieee80211_sub_if_data *sdata;
35 int err;
f0706e82 36
6bab2e19 37 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
f9e10ce4
JB
38 if (err)
39 return ERR_PTR(err);
8cc9a739 40
f9e10ce4 41 if (type == NL80211_IFTYPE_MONITOR && flags) {
84efbb84 42 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
f9e10ce4
JB
43 sdata->u.mntr_flags = *flags;
44 }
45
84efbb84 46 return wdev;
f0706e82
JB
47}
48
84efbb84 49static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
f0706e82 50{
84efbb84 51 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
f0706e82 52
75636525 53 return 0;
f0706e82
JB
54}
55
e36d56b6
JB
56static int ieee80211_change_iface(struct wiphy *wiphy,
57 struct net_device *dev,
2ec600d6
LCC
58 enum nl80211_iftype type, u32 *flags,
59 struct vif_params *params)
42613db7 60{
9607e6b6 61 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
f3947e2d 62 int ret;
42613db7 63
05c914fe 64 ret = ieee80211_if_change_type(sdata, type);
f3947e2d
JB
65 if (ret)
66 return ret;
42613db7 67
9bc383de
JB
68 if (type == NL80211_IFTYPE_AP_VLAN &&
69 params && params->use_4addr == 0)
a9b3cd7f 70 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
9bc383de
JB
71 else if (type == NL80211_IFTYPE_STATION &&
72 params && params->use_4addr >= 0)
73 sdata->u.mgd.use_4addr = params->use_4addr;
74
85416a4f
CL
75 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
76 struct ieee80211_local *local = sdata->local;
77
78 if (ieee80211_sdata_running(sdata)) {
31eba5bc
FF
79 u32 mask = MONITOR_FLAG_COOK_FRAMES |
80 MONITOR_FLAG_ACTIVE;
81
85416a4f 82 /*
31eba5bc
FF
83 * Prohibit MONITOR_FLAG_COOK_FRAMES and
84 * MONITOR_FLAG_ACTIVE to be changed while the
85 * interface is up.
85416a4f
CL
86 * Else we would need to add a lot of cruft
87 * to update everything:
88 * cooked_mntrs, monitor and all fif_* counters
89 * reconfigure hardware
90 */
31eba5bc 91 if ((*flags & mask) != (sdata->u.mntr_flags & mask))
85416a4f
CL
92 return -EBUSY;
93
94 ieee80211_adjust_monitor_flags(sdata, -1);
95 sdata->u.mntr_flags = *flags;
96 ieee80211_adjust_monitor_flags(sdata, 1);
97
98 ieee80211_configure_filter(local);
99 } else {
100 /*
101 * Because the interface is down, ieee80211_do_stop
102 * and ieee80211_do_open take care of "everything"
103 * mentioned in the comment above.
104 */
105 sdata->u.mntr_flags = *flags;
106 }
107 }
f7917af9 108
42613db7
JB
109 return 0;
110}
111
f142c6b9
JB
112static int ieee80211_start_p2p_device(struct wiphy *wiphy,
113 struct wireless_dev *wdev)
114{
b6a55015
LC
115 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
116 int ret;
117
118 mutex_lock(&sdata->local->chanctx_mtx);
119 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
120 mutex_unlock(&sdata->local->chanctx_mtx);
121 if (ret < 0)
122 return ret;
123
f142c6b9
JB
124 return ieee80211_do_open(wdev, true);
125}
126
127static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
128 struct wireless_dev *wdev)
129{
130 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
131}
132
b53be792
SW
133static int ieee80211_set_noack_map(struct wiphy *wiphy,
134 struct net_device *dev,
135 u16 noack_map)
136{
137 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
138
139 sdata->noack_map = noack_map;
17c18bf8
JB
140
141 ieee80211_check_fast_xmit_iface(sdata);
142
b53be792
SW
143 return 0;
144}
145
e8cbb4cb 146static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
e31b8213 147 u8 key_idx, bool pairwise, const u8 *mac_addr,
e8cbb4cb
JB
148 struct key_params *params)
149{
26a58456 150 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2475b1cc 151 struct ieee80211_local *local = sdata->local;
e8cbb4cb 152 struct sta_info *sta = NULL;
2475b1cc 153 const struct ieee80211_cipher_scheme *cs = NULL;
db4d1169 154 struct ieee80211_key *key;
3b96766f 155 int err;
e8cbb4cb 156
26a58456 157 if (!ieee80211_sdata_running(sdata))
ad0e2b5a
JB
158 return -ENETDOWN;
159
97359d12 160 /* reject WEP and TKIP keys if WEP failed to initialize */
e8cbb4cb
JB
161 switch (params->cipher) {
162 case WLAN_CIPHER_SUITE_WEP40:
e8cbb4cb 163 case WLAN_CIPHER_SUITE_TKIP:
97359d12 164 case WLAN_CIPHER_SUITE_WEP104:
2475b1cc 165 if (IS_ERR(local->wep_tx_tfm))
97359d12 166 return -EINVAL;
3cfcf6ac 167 break;
2475b1cc 168 case WLAN_CIPHER_SUITE_CCMP:
2b2ba0db 169 case WLAN_CIPHER_SUITE_CCMP_256:
2475b1cc 170 case WLAN_CIPHER_SUITE_AES_CMAC:
56c52da2 171 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
8ade538b
JM
172 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
173 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2475b1cc 174 case WLAN_CIPHER_SUITE_GCMP:
00b9cfa3 175 case WLAN_CIPHER_SUITE_GCMP_256:
2475b1cc 176 break;
e8cbb4cb 177 default:
2475b1cc 178 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
97359d12 179 break;
e8cbb4cb
JB
180 }
181
97359d12 182 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
2475b1cc
MS
183 params->key, params->seq_len, params->seq,
184 cs);
1ac62ba7
BH
185 if (IS_ERR(key))
186 return PTR_ERR(key);
db4d1169 187
e31b8213
JB
188 if (pairwise)
189 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
190
2475b1cc 191 mutex_lock(&local->sta_mtx);
3b96766f 192
e8cbb4cb 193 if (mac_addr) {
ff973af7
TP
194 if (ieee80211_vif_is_mesh(&sdata->vif))
195 sta = sta_info_get(sdata, mac_addr);
196 else
197 sta = sta_info_get_bss(sdata, mac_addr);
1626e0fa
JB
198 /*
199 * The ASSOC test makes sure the driver is ready to
200 * receive the key. When wpa_supplicant has roamed
201 * using FT, it attempts to set the key before
202 * association has completed, this rejects that attempt
d070f913 203 * so it will set the key again after association.
1626e0fa
JB
204 *
205 * TODO: accept the key if we have a station entry and
206 * add it to the device after the station.
207 */
208 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
79cf2dfa 209 ieee80211_key_free_unused(key);
3b96766f
JB
210 err = -ENOENT;
211 goto out_unlock;
db4d1169 212 }
e8cbb4cb
JB
213 }
214
e548c49e
JB
215 switch (sdata->vif.type) {
216 case NL80211_IFTYPE_STATION:
217 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
218 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
219 break;
220 case NL80211_IFTYPE_AP:
221 case NL80211_IFTYPE_AP_VLAN:
222 /* Keys without a station are used for TX only */
223 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
224 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
225 break;
226 case NL80211_IFTYPE_ADHOC:
227 /* no MFP (yet) */
228 break;
229 case NL80211_IFTYPE_MESH_POINT:
230#ifdef CONFIG_MAC80211_MESH
231 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
232 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
233 break;
234#endif
235 case NL80211_IFTYPE_WDS:
236 case NL80211_IFTYPE_MONITOR:
237 case NL80211_IFTYPE_P2P_DEVICE:
238 case NL80211_IFTYPE_UNSPECIFIED:
239 case NUM_NL80211_IFTYPES:
240 case NL80211_IFTYPE_P2P_CLIENT:
241 case NL80211_IFTYPE_P2P_GO:
6e0bd6c3 242 case NL80211_IFTYPE_OCB:
e548c49e
JB
243 /* shouldn't happen */
244 WARN_ON_ONCE(1);
245 break;
246 }
247
2475b1cc
MS
248 if (sta)
249 sta->cipher_scheme = cs;
250
3ffc2a90 251 err = ieee80211_key_link(key, sdata, sta);
db4d1169 252
3b96766f 253 out_unlock:
2475b1cc 254 mutex_unlock(&local->sta_mtx);
3b96766f
JB
255
256 return err;
e8cbb4cb
JB
257}
258
259static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
e31b8213 260 u8 key_idx, bool pairwise, const u8 *mac_addr)
e8cbb4cb 261{
5c0c3641
JB
262 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
263 struct ieee80211_local *local = sdata->local;
e8cbb4cb 264 struct sta_info *sta;
5c0c3641 265 struct ieee80211_key *key = NULL;
e8cbb4cb
JB
266 int ret;
267
5c0c3641
JB
268 mutex_lock(&local->sta_mtx);
269 mutex_lock(&local->key_mtx);
3b96766f 270
e8cbb4cb 271 if (mac_addr) {
3b96766f
JB
272 ret = -ENOENT;
273
0e5ded5a 274 sta = sta_info_get_bss(sdata, mac_addr);
e8cbb4cb 275 if (!sta)
3b96766f 276 goto out_unlock;
e8cbb4cb 277
5c0c3641 278 if (pairwise)
2475b1cc 279 key = key_mtx_dereference(local, sta->ptk[key_idx]);
5c0c3641 280 else
40b275b6 281 key = key_mtx_dereference(local, sta->gtk[key_idx]);
5c0c3641 282 } else
40b275b6 283 key = key_mtx_dereference(local, sdata->keys[key_idx]);
e8cbb4cb 284
5c0c3641 285 if (!key) {
3b96766f
JB
286 ret = -ENOENT;
287 goto out_unlock;
288 }
e8cbb4cb 289
3b8d9c29 290 ieee80211_key_free(key, true);
e8cbb4cb 291
3b96766f
JB
292 ret = 0;
293 out_unlock:
5c0c3641
JB
294 mutex_unlock(&local->key_mtx);
295 mutex_unlock(&local->sta_mtx);
3b96766f
JB
296
297 return ret;
e8cbb4cb
JB
298}
299
62da92fb 300static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
e31b8213
JB
301 u8 key_idx, bool pairwise, const u8 *mac_addr,
302 void *cookie,
62da92fb
JB
303 void (*callback)(void *cookie,
304 struct key_params *params))
305{
14db74bc 306 struct ieee80211_sub_if_data *sdata;
62da92fb
JB
307 struct sta_info *sta = NULL;
308 u8 seq[6] = {0};
309 struct key_params params;
e31b8213 310 struct ieee80211_key *key = NULL;
aba83a0b 311 u64 pn64;
62da92fb
JB
312 u32 iv32;
313 u16 iv16;
314 int err = -ENOENT;
315
14db74bc
JB
316 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
317
3b96766f
JB
318 rcu_read_lock();
319
62da92fb 320 if (mac_addr) {
0e5ded5a 321 sta = sta_info_get_bss(sdata, mac_addr);
62da92fb
JB
322 if (!sta)
323 goto out;
324
354e159d 325 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
2475b1cc 326 key = rcu_dereference(sta->ptk[key_idx]);
31f1f4ec
MS
327 else if (!pairwise &&
328 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
a3836e02 329 key = rcu_dereference(sta->gtk[key_idx]);
62da92fb 330 } else
a3836e02 331 key = rcu_dereference(sdata->keys[key_idx]);
62da92fb
JB
332
333 if (!key)
334 goto out;
335
336 memset(&params, 0, sizeof(params));
337
97359d12 338 params.cipher = key->conf.cipher;
62da92fb 339
97359d12
JB
340 switch (key->conf.cipher) {
341 case WLAN_CIPHER_SUITE_TKIP:
b0f76b33
HH
342 iv32 = key->u.tkip.tx.iv32;
343 iv16 = key->u.tkip.tx.iv16;
62da92fb 344
24487981
JB
345 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
346 drv_get_tkip_seq(sdata->local,
347 key->conf.hw_key_idx,
348 &iv32, &iv16);
62da92fb
JB
349
350 seq[0] = iv16 & 0xff;
351 seq[1] = (iv16 >> 8) & 0xff;
352 seq[2] = iv32 & 0xff;
353 seq[3] = (iv32 >> 8) & 0xff;
354 seq[4] = (iv32 >> 16) & 0xff;
355 seq[5] = (iv32 >> 24) & 0xff;
356 params.seq = seq;
357 params.seq_len = 6;
358 break;
97359d12 359 case WLAN_CIPHER_SUITE_CCMP:
2b2ba0db 360 case WLAN_CIPHER_SUITE_CCMP_256:
aba83a0b
JB
361 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
362 seq[0] = pn64;
363 seq[1] = pn64 >> 8;
364 seq[2] = pn64 >> 16;
365 seq[3] = pn64 >> 24;
366 seq[4] = pn64 >> 32;
367 seq[5] = pn64 >> 40;
62da92fb
JB
368 params.seq = seq;
369 params.seq_len = 6;
370 break;
97359d12 371 case WLAN_CIPHER_SUITE_AES_CMAC:
56c52da2 372 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
75396ae6
JB
373 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
374 seq[0] = pn64;
375 seq[1] = pn64 >> 8;
376 seq[2] = pn64 >> 16;
377 seq[3] = pn64 >> 24;
378 seq[4] = pn64 >> 32;
379 seq[5] = pn64 >> 40;
3cfcf6ac
JM
380 params.seq = seq;
381 params.seq_len = 6;
382 break;
8ade538b
JM
383 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
384 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
385 pn64 = atomic64_read(&key->u.aes_gmac.tx_pn);
386 seq[0] = pn64;
387 seq[1] = pn64 >> 8;
388 seq[2] = pn64 >> 16;
389 seq[3] = pn64 >> 24;
390 seq[4] = pn64 >> 32;
391 seq[5] = pn64 >> 40;
392 params.seq = seq;
393 params.seq_len = 6;
394 break;
00b9cfa3
JM
395 case WLAN_CIPHER_SUITE_GCMP:
396 case WLAN_CIPHER_SUITE_GCMP_256:
397 pn64 = atomic64_read(&key->u.gcmp.tx_pn);
398 seq[0] = pn64;
399 seq[1] = pn64 >> 8;
400 seq[2] = pn64 >> 16;
401 seq[3] = pn64 >> 24;
402 seq[4] = pn64 >> 32;
403 seq[5] = pn64 >> 40;
404 params.seq = seq;
405 params.seq_len = 6;
406 break;
62da92fb
JB
407 }
408
409 params.key = key->conf.key;
410 params.key_len = key->conf.keylen;
411
412 callback(cookie, &params);
413 err = 0;
414
415 out:
3b96766f 416 rcu_read_unlock();
62da92fb
JB
417 return err;
418}
419
e8cbb4cb
JB
420static int ieee80211_config_default_key(struct wiphy *wiphy,
421 struct net_device *dev,
dbd2fd65
JB
422 u8 key_idx, bool uni,
423 bool multi)
e8cbb4cb 424{
ad0e2b5a 425 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3b96766f 426
f7e0104c 427 ieee80211_set_default_key(sdata, key_idx, uni, multi);
e8cbb4cb
JB
428
429 return 0;
430}
431
3cfcf6ac
JM
432static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
433 struct net_device *dev,
434 u8 key_idx)
435{
66c52421 436 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3cfcf6ac 437
3cfcf6ac
JM
438 ieee80211_set_default_mgmt_key(sdata, key_idx);
439
3cfcf6ac
JM
440 return 0;
441}
442
6b62bf32
TP
443void sta_set_rate_info_tx(struct sta_info *sta,
444 const struct ieee80211_tx_rate *rate,
445 struct rate_info *rinfo)
446{
447 rinfo->flags = 0;
8bc83c24 448 if (rate->flags & IEEE80211_TX_RC_MCS) {
6b62bf32 449 rinfo->flags |= RATE_INFO_FLAGS_MCS;
8bc83c24
JB
450 rinfo->mcs = rate->idx;
451 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
452 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
453 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
454 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
455 } else {
456 struct ieee80211_supported_band *sband;
2103dec1
SW
457 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
458 u16 brate;
459
8bc83c24
JB
460 sband = sta->local->hw.wiphy->bands[
461 ieee80211_get_sdata_band(sta->sdata)];
2103dec1
SW
462 brate = sband->bitrates[rate->idx].bitrate;
463 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
8bc83c24 464 }
6b62bf32 465 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
b51f3bee
JB
466 rinfo->bw = RATE_INFO_BW_40;
467 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
468 rinfo->bw = RATE_INFO_BW_80;
469 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
470 rinfo->bw = RATE_INFO_BW_160;
471 else
472 rinfo->bw = RATE_INFO_BW_20;
6b62bf32
TP
473 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
474 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
6b62bf32
TP
475}
476
003e676a
S
477void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
478{
479 rinfo->flags = 0;
480
481 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
482 rinfo->flags |= RATE_INFO_FLAGS_MCS;
483 rinfo->mcs = sta->last_rx_rate_idx;
484 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
485 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
486 rinfo->nss = sta->last_rx_rate_vht_nss;
487 rinfo->mcs = sta->last_rx_rate_idx;
488 } else {
489 struct ieee80211_supported_band *sband;
2103dec1
SW
490 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
491 u16 brate;
003e676a
S
492
493 sband = sta->local->hw.wiphy->bands[
494 ieee80211_get_sdata_band(sta->sdata)];
2103dec1
SW
495 brate = sband->bitrates[sta->last_rx_rate_idx].bitrate;
496 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
003e676a
S
497 }
498
003e676a
S
499 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
500 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
b51f3bee
JB
501
502 if (sta->last_rx_rate_flag & RX_FLAG_5MHZ)
503 rinfo->bw = RATE_INFO_BW_5;
504 else if (sta->last_rx_rate_flag & RX_FLAG_10MHZ)
505 rinfo->bw = RATE_INFO_BW_10;
506 else if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
507 rinfo->bw = RATE_INFO_BW_40;
508 else if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80MHZ)
509 rinfo->bw = RATE_INFO_BW_80;
510 else if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_160MHZ)
511 rinfo->bw = RATE_INFO_BW_160;
512 else
513 rinfo->bw = RATE_INFO_BW_20;
003e676a
S
514}
515
c5dd9c2b 516static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 517 int idx, u8 *mac, struct station_info *sinfo)
c5dd9c2b 518{
3b53fde8 519 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
66572cfc 520 struct ieee80211_local *local = sdata->local;
c5dd9c2b 521 struct sta_info *sta;
d0709a65
JB
522 int ret = -ENOENT;
523
66572cfc 524 mutex_lock(&local->sta_mtx);
c5dd9c2b 525
3b53fde8 526 sta = sta_info_get_by_idx(sdata, idx);
d0709a65
JB
527 if (sta) {
528 ret = 0;
17741cdc 529 memcpy(mac, sta->sta.addr, ETH_ALEN);
d0709a65
JB
530 sta_set_sinfo(sta, sinfo);
531 }
c5dd9c2b 532
66572cfc 533 mutex_unlock(&local->sta_mtx);
c5dd9c2b 534
d0709a65 535 return ret;
c5dd9c2b
LCC
536}
537
1289723e
HS
538static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
539 int idx, struct survey_info *survey)
540{
541 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
542
1289723e
HS
543 return drv_get_survey(local, idx, survey);
544}
545
7bbdd2d9 546static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 547 const u8 *mac, struct station_info *sinfo)
7bbdd2d9 548{
abe60632 549 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
66572cfc 550 struct ieee80211_local *local = sdata->local;
7bbdd2d9 551 struct sta_info *sta;
d0709a65 552 int ret = -ENOENT;
7bbdd2d9 553
66572cfc 554 mutex_lock(&local->sta_mtx);
7bbdd2d9 555
0e5ded5a 556 sta = sta_info_get_bss(sdata, mac);
d0709a65
JB
557 if (sta) {
558 ret = 0;
559 sta_set_sinfo(sta, sinfo);
560 }
561
66572cfc 562 mutex_unlock(&local->sta_mtx);
d0709a65
JB
563
564 return ret;
7bbdd2d9
JB
565}
566
55de908a 567static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
683b6d3b 568 struct cfg80211_chan_def *chandef)
3d9e6e12
JB
569{
570 struct ieee80211_local *local = wiphy_priv(wiphy);
55de908a
JB
571 struct ieee80211_sub_if_data *sdata;
572 int ret = 0;
3d9e6e12 573
4bf88530 574 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
55de908a 575 return 0;
3d9e6e12 576
34a3740d 577 mutex_lock(&local->mtx);
55de908a
JB
578 mutex_lock(&local->iflist_mtx);
579 if (local->use_chanctx) {
580 sdata = rcu_dereference_protected(
581 local->monitor_sdata,
582 lockdep_is_held(&local->iflist_mtx));
583 if (sdata) {
584 ieee80211_vif_release_channel(sdata);
4bf88530 585 ret = ieee80211_vif_use_channel(sdata, chandef,
55de908a
JB
586 IEEE80211_CHANCTX_EXCLUSIVE);
587 }
588 } else if (local->open_count == local->monitors) {
675a0b04 589 local->_oper_chandef = *chandef;
55de908a
JB
590 ieee80211_hw_config(local, 0);
591 }
3d9e6e12 592
4bf88530
JB
593 if (ret == 0)
594 local->monitor_chandef = *chandef;
55de908a 595 mutex_unlock(&local->iflist_mtx);
34a3740d 596 mutex_unlock(&local->mtx);
3d9e6e12 597
55de908a 598 return ret;
e8c9bd5b
JB
599}
600
02945821 601static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
af296bdb
MK
602 const u8 *resp, size_t resp_len,
603 const struct ieee80211_csa_settings *csa)
02945821 604{
aa7a0080 605 struct probe_resp *new, *old;
02945821
AN
606
607 if (!resp || !resp_len)
aba4e6ff 608 return 1;
02945821 609
7ca133bc 610 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
02945821 611
aa7a0080 612 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
02945821
AN
613 if (!new)
614 return -ENOMEM;
615
aa7a0080
ES
616 new->len = resp_len;
617 memcpy(new->data, resp, resp_len);
02945821 618
af296bdb
MK
619 if (csa)
620 memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
621 csa->n_counter_offsets_presp *
622 sizeof(new->csa_counter_offsets[0]));
623
02945821 624 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
aa7a0080
ES
625 if (old)
626 kfree_rcu(old, rcu_head);
02945821
AN
627
628 return 0;
629}
630
0ae07968 631static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
af296bdb
MK
632 struct cfg80211_beacon_data *params,
633 const struct ieee80211_csa_settings *csa)
5dfdaf58
JB
634{
635 struct beacon_data *new, *old;
636 int new_head_len, new_tail_len;
8860020e
JB
637 int size, err;
638 u32 changed = BSS_CHANGED_BEACON;
5dfdaf58 639
7ca133bc
SW
640 old = sdata_dereference(sdata->u.ap.beacon, sdata);
641
5dfdaf58 642
5dfdaf58
JB
643 /* Need to have a beacon head if we don't have one yet */
644 if (!params->head && !old)
8860020e 645 return -EINVAL;
5dfdaf58
JB
646
647 /* new or old head? */
648 if (params->head)
649 new_head_len = params->head_len;
650 else
651 new_head_len = old->head_len;
652
653 /* new or old tail? */
654 if (params->tail || !old)
655 /* params->tail_len will be zero for !params->tail */
656 new_tail_len = params->tail_len;
657 else
658 new_tail_len = old->tail_len;
659
660 size = sizeof(*new) + new_head_len + new_tail_len;
661
662 new = kzalloc(size, GFP_KERNEL);
663 if (!new)
664 return -ENOMEM;
665
666 /* start filling the new info now */
667
5dfdaf58
JB
668 /*
669 * pointers go into the block we allocated,
670 * memory is | beacon_data | head | tail |
671 */
672 new->head = ((u8 *) new) + sizeof(*new);
673 new->tail = new->head + new_head_len;
674 new->head_len = new_head_len;
675 new->tail_len = new_tail_len;
676
af296bdb
MK
677 if (csa) {
678 new->csa_current_counter = csa->count;
679 memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
680 csa->n_counter_offsets_beacon *
681 sizeof(new->csa_counter_offsets[0]));
682 }
683
5dfdaf58
JB
684 /* copy in head */
685 if (params->head)
686 memcpy(new->head, params->head, new_head_len);
687 else
688 memcpy(new->head, old->head, new_head_len);
689
690 /* copy in optional tail */
691 if (params->tail)
692 memcpy(new->tail, params->tail, new_tail_len);
693 else
694 if (old)
695 memcpy(new->tail, old->tail, new_tail_len);
696
02945821 697 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
af296bdb 698 params->probe_resp_len, csa);
8860020e
JB
699 if (err < 0)
700 return err;
701 if (err == 0)
02945821
AN
702 changed |= BSS_CHANGED_AP_PROBE_RESP;
703
8860020e
JB
704 rcu_assign_pointer(sdata->u.ap.beacon, new);
705
706 if (old)
707 kfree_rcu(old, rcu_head);
7827493b 708
8860020e 709 return changed;
5dfdaf58
JB
710}
711
8860020e
JB
712static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
713 struct cfg80211_ap_settings *params)
5dfdaf58 714{
8860020e 715 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
34a3740d 716 struct ieee80211_local *local = sdata->local;
5dfdaf58 717 struct beacon_data *old;
665c93a9 718 struct ieee80211_sub_if_data *vlan;
8860020e
JB
719 u32 changed = BSS_CHANGED_BEACON_INT |
720 BSS_CHANGED_BEACON_ENABLED |
721 BSS_CHANGED_BEACON |
339afbf4 722 BSS_CHANGED_SSID |
4bcc56bb
JB
723 BSS_CHANGED_P2P_PS |
724 BSS_CHANGED_TXPOWER;
8860020e 725 int err;
14db74bc 726
7ca133bc 727 old = sdata_dereference(sdata->u.ap.beacon, sdata);
5dfdaf58
JB
728 if (old)
729 return -EALREADY;
730
f6993174
EP
731 switch (params->smps_mode) {
732 case NL80211_SMPS_OFF:
733 sdata->smps_mode = IEEE80211_SMPS_OFF;
734 break;
735 case NL80211_SMPS_STATIC:
736 sdata->smps_mode = IEEE80211_SMPS_STATIC;
737 break;
738 case NL80211_SMPS_DYNAMIC:
739 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
740 break;
741 default:
742 return -EINVAL;
743 }
04ecd257
JB
744 sdata->needed_rx_chains = sdata->local->rx_chains;
745
34a3740d 746 mutex_lock(&local->mtx);
4bf88530 747 err = ieee80211_vif_use_channel(sdata, &params->chandef,
55de908a 748 IEEE80211_CHANCTX_SHARED);
4e141dad
MK
749 if (!err)
750 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
34a3740d 751 mutex_unlock(&local->mtx);
aa430da4
JB
752 if (err)
753 return err;
754
665c93a9
JB
755 /*
756 * Apply control port protocol, this allows us to
757 * not encrypt dynamic WEP control frames.
758 */
759 sdata->control_port_protocol = params->crypto.control_port_ethertype;
760 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
2475b1cc
MS
761 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
762 &params->crypto,
763 sdata->vif.type);
764
665c93a9
JB
765 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
766 vlan->control_port_protocol =
767 params->crypto.control_port_ethertype;
768 vlan->control_port_no_encrypt =
769 params->crypto.control_port_no_encrypt;
2475b1cc
MS
770 vlan->encrypt_headroom =
771 ieee80211_cs_headroom(sdata->local,
772 &params->crypto,
773 vlan->vif.type);
665c93a9
JB
774 }
775
8860020e
JB
776 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
777 sdata->vif.bss_conf.dtim_period = params->dtim_period;
d6a83228 778 sdata->vif.bss_conf.enable_beacon = true;
8860020e
JB
779
780 sdata->vif.bss_conf.ssid_len = params->ssid_len;
781 if (params->ssid_len)
782 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
783 params->ssid_len);
784 sdata->vif.bss_conf.hidden_ssid =
785 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
786
67baf663
JD
787 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
788 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
789 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
790 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
791 if (params->p2p_opp_ps)
792 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
793 IEEE80211_P2P_OPPPS_ENABLE_BIT;
339afbf4 794
af296bdb 795 err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
0297ea17
EG
796 if (err < 0) {
797 ieee80211_vif_release_channel(sdata);
8860020e 798 return err;
0297ea17 799 }
8860020e
JB
800 changed |= err;
801
1041638f
JB
802 err = drv_start_ap(sdata->local, sdata);
803 if (err) {
7ca133bc
SW
804 old = sdata_dereference(sdata->u.ap.beacon, sdata);
805
1041638f
JB
806 if (old)
807 kfree_rcu(old, rcu_head);
808 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
0297ea17 809 ieee80211_vif_release_channel(sdata);
1041638f
JB
810 return err;
811 }
812
057d5f4b 813 ieee80211_recalc_dtim(local, sdata);
8860020e
JB
814 ieee80211_bss_info_change_notify(sdata, changed);
815
3edaf3e6
JB
816 netif_carrier_on(dev);
817 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
818 netif_carrier_on(vlan->dev);
819
665c93a9 820 return 0;
5dfdaf58
JB
821}
822
8860020e
JB
823static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
824 struct cfg80211_beacon_data *params)
5dfdaf58 825{
14db74bc 826 struct ieee80211_sub_if_data *sdata;
5dfdaf58 827 struct beacon_data *old;
8860020e 828 int err;
5dfdaf58 829
14db74bc 830 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
dbd72850 831 sdata_assert_lock(sdata);
14db74bc 832
73da7d5b
SW
833 /* don't allow changing the beacon while CSA is in place - offset
834 * of channel switch counter may change
835 */
836 if (sdata->vif.csa_active)
837 return -EBUSY;
838
7ca133bc 839 old = sdata_dereference(sdata->u.ap.beacon, sdata);
5dfdaf58
JB
840 if (!old)
841 return -ENOENT;
842
af296bdb 843 err = ieee80211_assign_beacon(sdata, params, NULL);
8860020e
JB
844 if (err < 0)
845 return err;
846 ieee80211_bss_info_change_notify(sdata, err);
847 return 0;
5dfdaf58
JB
848}
849
8860020e 850static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
5dfdaf58 851{
7b20b8e8
JB
852 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
853 struct ieee80211_sub_if_data *vlan;
854 struct ieee80211_local *local = sdata->local;
855 struct beacon_data *old_beacon;
856 struct probe_resp *old_probe_resp;
d2859df5 857 struct cfg80211_chan_def chandef;
14db74bc 858
dbd72850
MK
859 sdata_assert_lock(sdata);
860
7ca133bc 861 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
7b20b8e8 862 if (!old_beacon)
5dfdaf58 863 return -ENOENT;
7ca133bc 864 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
5dfdaf58 865
73da7d5b 866 /* abort any running channel switch */
59af6928 867 mutex_lock(&local->mtx);
73da7d5b 868 sdata->vif.csa_active = false;
a46992b4
LC
869 if (sdata->csa_block_tx) {
870 ieee80211_wake_vif_queues(local, sdata,
871 IEEE80211_QUEUE_STOP_REASON_CSA);
872 sdata->csa_block_tx = false;
873 }
874
59af6928
MK
875 mutex_unlock(&local->mtx);
876
1f3b8a2b
SW
877 kfree(sdata->u.ap.next_beacon);
878 sdata->u.ap.next_beacon = NULL;
879
7b20b8e8 880 /* turn off carrier for this interface and dependent VLANs */
3edaf3e6
JB
881 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
882 netif_carrier_off(vlan->dev);
883 netif_carrier_off(dev);
884
7b20b8e8 885 /* remove beacon and probe response */
a9b3cd7f 886 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
7b20b8e8
JB
887 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
888 kfree_rcu(old_beacon, rcu_head);
889 if (old_probe_resp)
890 kfree_rcu(old_probe_resp, rcu_head);
8ffcc704 891 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
8860020e 892
e716251d 893 __sta_info_flush(sdata, true);
7907c7d3 894 ieee80211_free_keys(sdata, true);
75de9113 895
d6a83228 896 sdata->vif.bss_conf.enable_beacon = false;
0eabccd9 897 sdata->vif.bss_conf.ssid_len = 0;
d6a83228 898 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
2d0ddec5 899 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
8860020e 900
a6b368f6 901 if (sdata->wdev.cac_started) {
d2859df5 902 chandef = sdata->vif.bss_conf.chandef;
a6b368f6 903 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
d2859df5
JD
904 cfg80211_cac_event(sdata->dev, &chandef,
905 NL80211_RADAR_CAC_ABORTED,
a6b368f6
SW
906 GFP_KERNEL);
907 }
908
1041638f
JB
909 drv_stop_ap(sdata->local, sdata);
910
7b20b8e8
JB
911 /* free all potentially still buffered bcast frames */
912 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
913 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
914
34a3740d 915 mutex_lock(&local->mtx);
4e141dad 916 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
55de908a 917 ieee80211_vif_release_channel(sdata);
34a3740d 918 mutex_unlock(&local->mtx);
55de908a 919
2d0ddec5 920 return 0;
5dfdaf58
JB
921}
922
4fd6931e
JB
923/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
924struct iapp_layer2_update {
925 u8 da[ETH_ALEN]; /* broadcast */
926 u8 sa[ETH_ALEN]; /* STA addr */
927 __be16 len; /* 6 */
928 u8 dsap; /* 0 */
929 u8 ssap; /* 0 */
930 u8 control;
931 u8 xid_info[3];
bc10502d 932} __packed;
4fd6931e
JB
933
934static void ieee80211_send_layer2_update(struct sta_info *sta)
935{
936 struct iapp_layer2_update *msg;
937 struct sk_buff *skb;
938
939 /* Send Level 2 Update Frame to update forwarding tables in layer 2
940 * bridge devices */
941
942 skb = dev_alloc_skb(sizeof(*msg));
943 if (!skb)
944 return;
945 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
946
947 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
948 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
949
e83e6541 950 eth_broadcast_addr(msg->da);
17741cdc 951 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
4fd6931e
JB
952 msg->len = htons(6);
953 msg->dsap = 0;
954 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
955 msg->control = 0xaf; /* XID response lsb.1111F101.
956 * F=0 (no poll command; unsolicited frame) */
957 msg->xid_info[0] = 0x81; /* XID format identifier */
958 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
959 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
960
d0709a65
JB
961 skb->dev = sta->sdata->dev;
962 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
4fd6931e 963 memset(skb->cb, 0, sizeof(skb->cb));
06ee1c26 964 netif_rx_ni(skb);
4fd6931e
JB
965}
966
d582cffb
JB
967static int sta_apply_auth_flags(struct ieee80211_local *local,
968 struct sta_info *sta,
969 u32 mask, u32 set)
970{
971 int ret;
972
973 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
974 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
975 !test_sta_flag(sta, WLAN_STA_AUTH)) {
976 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
977 if (ret)
978 return ret;
979 }
980
981 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
982 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
983 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
c23e31cf
MP
984 /*
985 * When peer becomes associated, init rate control as
986 * well. Some drivers require rate control initialized
987 * before drv_sta_state() is called.
988 */
989 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
990 rate_control_rate_init(sta);
991
d582cffb
JB
992 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
993 if (ret)
994 return ret;
995 }
996
997 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
998 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
999 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1000 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1001 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1002 else
1003 ret = 0;
1004 if (ret)
1005 return ret;
1006 }
1007
1008 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1009 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1010 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1011 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1012 if (ret)
1013 return ret;
1014 }
1015
1016 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1017 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1018 test_sta_flag(sta, WLAN_STA_AUTH)) {
1019 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1020 if (ret)
1021 return ret;
1022 }
1023
1024 return 0;
1025}
1026
d9a7ddb0
JB
1027static int sta_apply_parameters(struct ieee80211_local *local,
1028 struct sta_info *sta,
1029 struct station_parameters *params)
4fd6931e 1030{
d9a7ddb0 1031 int ret = 0;
8318d78a 1032 struct ieee80211_supported_band *sband;
d0709a65 1033 struct ieee80211_sub_if_data *sdata = sta->sdata;
55de908a 1034 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
eccb8e8f 1035 u32 mask, set;
4fd6931e 1036
55de908a 1037 sband = local->hw.wiphy->bands[band];
ae5eb026 1038
eccb8e8f
JB
1039 mask = params->sta_flags_mask;
1040 set = params->sta_flags_set;
73651ee6 1041
d582cffb
JB
1042 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1043 /*
1044 * In mesh mode, ASSOCIATED isn't part of the nl80211
1045 * API but must follow AUTHENTICATED for driver state.
1046 */
1047 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1048 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1049 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1050 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
77ee7c89
JB
1051 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1052 /*
1053 * TDLS -- everything follows authorized, but
1054 * only becoming authorized is possible, not
1055 * going back
1056 */
1057 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1058 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1059 BIT(NL80211_STA_FLAG_ASSOCIATED);
1060 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1061 BIT(NL80211_STA_FLAG_ASSOCIATED);
1062 }
eccb8e8f 1063 }
4fd6931e 1064
2c44be81
JB
1065 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1066 local->hw.queues >= IEEE80211_NUM_ACS)
1067 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1068
68885a54
AN
1069 /* auth flags will be set later for TDLS stations */
1070 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1071 ret = sta_apply_auth_flags(local, sta, mask, set);
1072 if (ret)
1073 return ret;
1074 }
d9a7ddb0 1075
eccb8e8f 1076 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
eccb8e8f 1077 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
c2c98fde
JB
1078 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1079 else
1080 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
eccb8e8f 1081 }
4fd6931e 1082
eccb8e8f 1083 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
64a8cef4 1084 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
eccb8e8f 1085 if (set & BIT(NL80211_STA_FLAG_MFP))
c2c98fde
JB
1086 set_sta_flag(sta, WLAN_STA_MFP);
1087 else
1088 clear_sta_flag(sta, WLAN_STA_MFP);
4fd6931e 1089 }
b39c48fa 1090
07ba55d7 1091 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
07ba55d7 1092 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
c2c98fde
JB
1093 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1094 else
1095 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
07ba55d7 1096 }
4fd6931e 1097
9041c1fa
AN
1098 /* mark TDLS channel switch support, if the AP allows it */
1099 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1100 !sdata->u.mgd.tdls_chan_switch_prohibited &&
1101 params->ext_capab_len >= 4 &&
1102 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1103 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1104
3b9ce80c
JB
1105 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1106 sta->sta.uapsd_queues = params->uapsd_queues;
1107 sta->sta.max_sp = params->max_sp;
1108 }
9533b4ac 1109
51b50fbe
JB
1110 /*
1111 * cfg80211 validates this (1-2007) and allows setting the AID
1112 * only when creating a new station entry
1113 */
1114 if (params->aid)
1115 sta->sta.aid = params->aid;
1116
73651ee6 1117 /*
ba23d206
JB
1118 * Some of the following updates would be racy if called on an
1119 * existing station, via ieee80211_change_station(). However,
1120 * all such changes are rejected by cfg80211 except for updates
1121 * changing the supported rates on an existing but not yet used
1122 * TDLS peer.
73651ee6
JB
1123 */
1124
4fd6931e
JB
1125 if (params->listen_interval >= 0)
1126 sta->listen_interval = params->listen_interval;
1127
1128 if (params->supported_rates) {
2103dec1
SW
1129 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1130 sband, params->supported_rates,
1131 params->supported_rates_len,
1132 &sta->sta.supp_rates[band]);
4fd6931e 1133 }
c5dd9c2b 1134
d9fe60de 1135 if (params->ht_capa)
ef96a842 1136 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
e1a0c6b3 1137 params->ht_capa, sta);
36aedc90 1138
f461be3e
MP
1139 if (params->vht_capa)
1140 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
4a34215e 1141 params->vht_capa, sta);
f461be3e 1142
b1bce14a 1143 if (params->opmode_notif_used) {
b1bce14a
MK
1144 /* returned value is only needed for rc update, but the
1145 * rc isn't initialized here yet, so ignore it
1146 */
1147 __ieee80211_vht_handle_opmode(sdata, sta,
1148 params->opmode_notif,
1149 band, false);
1150 }
1151
9c3990aa 1152 if (ieee80211_vif_is_mesh(&sdata->vif)) {
4daf50f2 1153#ifdef CONFIG_MAC80211_MESH
39886b61 1154 u32 changed = 0;
77ee7c89
JB
1155
1156 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
9c3990aa 1157 switch (params->plink_state) {
57cf8043 1158 case NL80211_PLINK_ESTAB:
1617bab8
MP
1159 if (sta->plink_state != NL80211_PLINK_ESTAB)
1160 changed = mesh_plink_inc_estab_count(
1161 sdata);
1162 sta->plink_state = params->plink_state;
3f52b7e3
MP
1163
1164 ieee80211_mps_sta_status_update(sta);
39886b61
TP
1165 changed |= ieee80211_mps_set_sta_local_pm(sta,
1166 sdata->u.mesh.mshcfg.power_mode);
1617bab8
MP
1167 break;
1168 case NL80211_PLINK_LISTEN:
57cf8043 1169 case NL80211_PLINK_BLOCKED:
1617bab8
MP
1170 case NL80211_PLINK_OPN_SNT:
1171 case NL80211_PLINK_OPN_RCVD:
1172 case NL80211_PLINK_CNF_RCVD:
1173 case NL80211_PLINK_HOLDING:
1174 if (sta->plink_state == NL80211_PLINK_ESTAB)
1175 changed = mesh_plink_dec_estab_count(
1176 sdata);
9c3990aa 1177 sta->plink_state = params->plink_state;
3f52b7e3
MP
1178
1179 ieee80211_mps_sta_status_update(sta);
446075d7
MP
1180 changed |= ieee80211_mps_set_sta_local_pm(sta,
1181 NL80211_MESH_POWER_UNKNOWN);
9c3990aa
JC
1182 break;
1183 default:
1184 /* nothing */
1185 break;
1186 }
77ee7c89
JB
1187 }
1188
1189 switch (params->plink_action) {
1190 case NL80211_PLINK_ACTION_NO_ACTION:
1191 /* nothing */
1192 break;
1193 case NL80211_PLINK_ACTION_OPEN:
1194 changed |= mesh_plink_open(sta);
1195 break;
1196 case NL80211_PLINK_ACTION_BLOCK:
1197 changed |= mesh_plink_block(sta);
1198 break;
1617bab8 1199 }
3f52b7e3
MP
1200
1201 if (params->local_pm)
39886b61
TP
1202 changed |=
1203 ieee80211_mps_set_sta_local_pm(sta,
1204 params->local_pm);
6c751ef8 1205 ieee80211_mbss_info_change_notify(sdata, changed);
4daf50f2 1206#endif
902acc78 1207 }
d9a7ddb0 1208
68885a54
AN
1209 /* set the STA state after all sta info from usermode has been set */
1210 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1211 ret = sta_apply_auth_flags(local, sta, mask, set);
1212 if (ret)
1213 return ret;
1214 }
1215
d9a7ddb0 1216 return 0;
4fd6931e
JB
1217}
1218
1219static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
3b3a0162
JB
1220 const u8 *mac,
1221 struct station_parameters *params)
4fd6931e 1222{
14db74bc 1223 struct ieee80211_local *local = wiphy_priv(wiphy);
4fd6931e
JB
1224 struct sta_info *sta;
1225 struct ieee80211_sub_if_data *sdata;
73651ee6 1226 int err;
b8d476c8 1227 int layer2_update;
4fd6931e 1228
4fd6931e
JB
1229 if (params->vlan) {
1230 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1231
05c914fe
JB
1232 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1233 sdata->vif.type != NL80211_IFTYPE_AP)
4fd6931e
JB
1234 return -EINVAL;
1235 } else
1236 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1237
b203ca39 1238 if (ether_addr_equal(mac, sdata->vif.addr))
03e4497e
JB
1239 return -EINVAL;
1240
1241 if (is_multicast_ether_addr(mac))
1242 return -EINVAL;
1243
1244 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
73651ee6
JB
1245 if (!sta)
1246 return -ENOMEM;
4fd6931e 1247
d582cffb
JB
1248 /*
1249 * defaults -- if userspace wants something else we'll
1250 * change it accordingly in sta_apply_parameters()
1251 */
77ee7c89
JB
1252 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1253 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1254 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
0c4972cc
AN
1255 } else {
1256 sta->sta.tdls = true;
77ee7c89 1257 }
4fd6931e 1258
d9a7ddb0
JB
1259 err = sta_apply_parameters(local, sta, params);
1260 if (err) {
1261 sta_info_free(local, sta);
1262 return err;
1263 }
4fd6931e 1264
d64cf63e 1265 /*
77ee7c89
JB
1266 * for TDLS, rate control should be initialized only when
1267 * rates are known and station is marked authorized
d64cf63e
AN
1268 */
1269 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1270 rate_control_rate_init(sta);
4fd6931e 1271
b8d476c8
JM
1272 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1273 sdata->vif.type == NL80211_IFTYPE_AP;
1274
34e89507 1275 err = sta_info_insert_rcu(sta);
73651ee6 1276 if (err) {
73651ee6
JB
1277 rcu_read_unlock();
1278 return err;
1279 }
1280
b8d476c8 1281 if (layer2_update)
73651ee6
JB
1282 ieee80211_send_layer2_update(sta);
1283
1284 rcu_read_unlock();
1285
4fd6931e
JB
1286 return 0;
1287}
1288
1289static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
89c771e5 1290 struct station_del_parameters *params)
4fd6931e 1291{
14db74bc 1292 struct ieee80211_sub_if_data *sdata;
4fd6931e 1293
14db74bc
JB
1294 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1295
89c771e5
JM
1296 if (params->mac)
1297 return sta_info_destroy_addr_bss(sdata, params->mac);
4fd6931e 1298
b998e8bb 1299 sta_info_flush(sdata);
4fd6931e
JB
1300 return 0;
1301}
1302
1303static int ieee80211_change_station(struct wiphy *wiphy,
3b3a0162 1304 struct net_device *dev, const u8 *mac,
4fd6931e
JB
1305 struct station_parameters *params)
1306{
abe60632 1307 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
14db74bc 1308 struct ieee80211_local *local = wiphy_priv(wiphy);
4fd6931e
JB
1309 struct sta_info *sta;
1310 struct ieee80211_sub_if_data *vlansdata;
77ee7c89 1311 enum cfg80211_station_type statype;
35b88623 1312 int err;
4fd6931e 1313
87be1e1e 1314 mutex_lock(&local->sta_mtx);
98dd6a57 1315
0e5ded5a 1316 sta = sta_info_get_bss(sdata, mac);
98dd6a57 1317 if (!sta) {
77ee7c89
JB
1318 err = -ENOENT;
1319 goto out_err;
98dd6a57 1320 }
4fd6931e 1321
77ee7c89
JB
1322 switch (sdata->vif.type) {
1323 case NL80211_IFTYPE_MESH_POINT:
a6dad6a2 1324 if (sdata->u.mesh.user_mpm)
eef941e6 1325 statype = CFG80211_STA_MESH_PEER_USER;
77ee7c89 1326 else
eef941e6 1327 statype = CFG80211_STA_MESH_PEER_KERNEL;
77ee7c89
JB
1328 break;
1329 case NL80211_IFTYPE_ADHOC:
1330 statype = CFG80211_STA_IBSS;
1331 break;
1332 case NL80211_IFTYPE_STATION:
1333 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1334 statype = CFG80211_STA_AP_STA;
1335 break;
1336 }
1337 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1338 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1339 else
1340 statype = CFG80211_STA_TDLS_PEER_SETUP;
1341 break;
1342 case NL80211_IFTYPE_AP:
1343 case NL80211_IFTYPE_AP_VLAN:
1344 statype = CFG80211_STA_AP_CLIENT;
1345 break;
1346 default:
1347 err = -EOPNOTSUPP;
1348 goto out_err;
bdd90d5e
JB
1349 }
1350
77ee7c89
JB
1351 err = cfg80211_check_station_change(wiphy, params, statype);
1352 if (err)
1353 goto out_err;
1354
d0709a65 1355 if (params->vlan && params->vlan != sta->sdata->dev) {
7e3ed02c
FF
1356 bool prev_4addr = false;
1357 bool new_4addr = false;
1358
4fd6931e
JB
1359 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1360
9bc383de 1361 if (params->vlan->ieee80211_ptr->use_4addr) {
3305443c 1362 if (vlansdata->u.vlan.sta) {
77ee7c89
JB
1363 err = -EBUSY;
1364 goto out_err;
3305443c 1365 }
f14543ee 1366
cf778b00 1367 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
7e3ed02c
FF
1368 new_4addr = true;
1369 }
1370
1371 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1372 sta->sdata->u.vlan.sta) {
0c2bef46 1373 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
7e3ed02c 1374 prev_4addr = true;
f14543ee
FF
1375 }
1376
14db74bc 1377 sta->sdata = vlansdata;
7e3ed02c
FF
1378
1379 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1380 prev_4addr != new_4addr) {
1381 if (new_4addr)
1382 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1383 else
1384 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1385 }
1386
4fd6931e
JB
1387 ieee80211_send_layer2_update(sta);
1388 }
1389
35b88623 1390 err = sta_apply_parameters(local, sta, params);
77ee7c89
JB
1391 if (err)
1392 goto out_err;
4fd6931e 1393
87be1e1e 1394 mutex_unlock(&local->sta_mtx);
98dd6a57 1395
687da132
EG
1396 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1397 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1398 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1399 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1400 sta_info_tx_streams(sta) != 1) {
1401 ht_dbg(sta->sdata,
1402 "%pM just authorized and MIMO capable - update SMPS\n",
1403 sta->sta.addr);
1404 ieee80211_send_smps_action(sta->sdata,
1405 sta->sdata->bss->req_smps,
1406 sta->sta.addr,
1407 sta->sdata->vif.bss_conf.bssid);
1408 }
1409
808118cb 1410 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
ab095877 1411 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
808118cb 1412 ieee80211_recalc_ps(local, -1);
ab095877
EP
1413 ieee80211_recalc_ps_vif(sdata);
1414 }
77ee7c89 1415
4fd6931e 1416 return 0;
77ee7c89
JB
1417out_err:
1418 mutex_unlock(&local->sta_mtx);
1419 return err;
4fd6931e
JB
1420}
1421
c5dd9c2b
LCC
1422#ifdef CONFIG_MAC80211_MESH
1423static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 1424 const u8 *dst, const u8 *next_hop)
c5dd9c2b 1425{
14db74bc 1426 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
1427 struct mesh_path *mpath;
1428 struct sta_info *sta;
c5dd9c2b 1429
14db74bc
JB
1430 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1431
d0709a65 1432 rcu_read_lock();
abe60632 1433 sta = sta_info_get(sdata, next_hop);
d0709a65
JB
1434 if (!sta) {
1435 rcu_read_unlock();
c5dd9c2b 1436 return -ENOENT;
d0709a65 1437 }
c5dd9c2b 1438
ae76eef0
BC
1439 mpath = mesh_path_add(sdata, dst);
1440 if (IS_ERR(mpath)) {
d0709a65 1441 rcu_read_unlock();
ae76eef0 1442 return PTR_ERR(mpath);
d0709a65 1443 }
c5dd9c2b 1444
c5dd9c2b 1445 mesh_path_fix_nexthop(mpath, sta);
d0709a65 1446
c5dd9c2b
LCC
1447 rcu_read_unlock();
1448 return 0;
1449}
1450
1451static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 1452 const u8 *dst)
c5dd9c2b 1453{
f698d856
JBG
1454 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1455
c5dd9c2b 1456 if (dst)
bf7cd94d 1457 return mesh_path_del(sdata, dst);
c5dd9c2b 1458
ece1a2e7 1459 mesh_path_flush_by_iface(sdata);
c5dd9c2b
LCC
1460 return 0;
1461}
1462
3b3a0162
JB
1463static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1464 const u8 *dst, const u8 *next_hop)
c5dd9c2b 1465{
14db74bc 1466 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
1467 struct mesh_path *mpath;
1468 struct sta_info *sta;
1469
14db74bc
JB
1470 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1471
d0709a65
JB
1472 rcu_read_lock();
1473
abe60632 1474 sta = sta_info_get(sdata, next_hop);
d0709a65
JB
1475 if (!sta) {
1476 rcu_read_unlock();
c5dd9c2b 1477 return -ENOENT;
d0709a65 1478 }
c5dd9c2b 1479
bf7cd94d 1480 mpath = mesh_path_lookup(sdata, dst);
c5dd9c2b
LCC
1481 if (!mpath) {
1482 rcu_read_unlock();
c5dd9c2b
LCC
1483 return -ENOENT;
1484 }
1485
1486 mesh_path_fix_nexthop(mpath, sta);
d0709a65 1487
c5dd9c2b
LCC
1488 rcu_read_unlock();
1489 return 0;
1490}
1491
1492static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1493 struct mpath_info *pinfo)
1494{
a3836e02
JB
1495 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1496
1497 if (next_hop_sta)
1498 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
c5dd9c2b 1499 else
c84a67a2 1500 eth_zero_addr(next_hop);
c5dd9c2b 1501
7ce8c7a3
LAYS
1502 memset(pinfo, 0, sizeof(*pinfo));
1503
f5ea9120
JB
1504 pinfo->generation = mesh_paths_generation;
1505
c5dd9c2b 1506 pinfo->filled = MPATH_INFO_FRAME_QLEN |
d19b3bf6 1507 MPATH_INFO_SN |
c5dd9c2b
LCC
1508 MPATH_INFO_METRIC |
1509 MPATH_INFO_EXPTIME |
1510 MPATH_INFO_DISCOVERY_TIMEOUT |
1511 MPATH_INFO_DISCOVERY_RETRIES |
1512 MPATH_INFO_FLAGS;
1513
1514 pinfo->frame_qlen = mpath->frame_queue.qlen;
d19b3bf6 1515 pinfo->sn = mpath->sn;
c5dd9c2b
LCC
1516 pinfo->metric = mpath->metric;
1517 if (time_before(jiffies, mpath->exp_time))
1518 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1519 pinfo->discovery_timeout =
1520 jiffies_to_msecs(mpath->discovery_timeout);
1521 pinfo->discovery_retries = mpath->discovery_retries;
c5dd9c2b
LCC
1522 if (mpath->flags & MESH_PATH_ACTIVE)
1523 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1524 if (mpath->flags & MESH_PATH_RESOLVING)
1525 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
d19b3bf6
RP
1526 if (mpath->flags & MESH_PATH_SN_VALID)
1527 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
c5dd9c2b
LCC
1528 if (mpath->flags & MESH_PATH_FIXED)
1529 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
7ce8c7a3
LAYS
1530 if (mpath->flags & MESH_PATH_RESOLVED)
1531 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
c5dd9c2b
LCC
1532}
1533
1534static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1535 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1536
1537{
14db74bc 1538 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
1539 struct mesh_path *mpath;
1540
14db74bc
JB
1541 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1542
c5dd9c2b 1543 rcu_read_lock();
bf7cd94d 1544 mpath = mesh_path_lookup(sdata, dst);
c5dd9c2b
LCC
1545 if (!mpath) {
1546 rcu_read_unlock();
1547 return -ENOENT;
1548 }
1549 memcpy(dst, mpath->dst, ETH_ALEN);
1550 mpath_set_pinfo(mpath, next_hop, pinfo);
1551 rcu_read_unlock();
1552 return 0;
1553}
1554
1555static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
3b3a0162
JB
1556 int idx, u8 *dst, u8 *next_hop,
1557 struct mpath_info *pinfo)
c5dd9c2b 1558{
14db74bc 1559 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
1560 struct mesh_path *mpath;
1561
14db74bc
JB
1562 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1563
c5dd9c2b 1564 rcu_read_lock();
bf7cd94d 1565 mpath = mesh_path_lookup_by_idx(sdata, idx);
c5dd9c2b
LCC
1566 if (!mpath) {
1567 rcu_read_unlock();
1568 return -ENOENT;
1569 }
1570 memcpy(dst, mpath->dst, ETH_ALEN);
1571 mpath_set_pinfo(mpath, next_hop, pinfo);
1572 rcu_read_unlock();
1573 return 0;
1574}
93da9cc1 1575
a2db2ed3
HR
1576static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
1577 struct mpath_info *pinfo)
1578{
1579 memset(pinfo, 0, sizeof(*pinfo));
1580 memcpy(mpp, mpath->mpp, ETH_ALEN);
1581
1582 pinfo->generation = mpp_paths_generation;
1583}
1584
1585static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
1586 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
1587
1588{
1589 struct ieee80211_sub_if_data *sdata;
1590 struct mesh_path *mpath;
1591
1592 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1593
1594 rcu_read_lock();
1595 mpath = mpp_path_lookup(sdata, dst);
1596 if (!mpath) {
1597 rcu_read_unlock();
1598 return -ENOENT;
1599 }
1600 memcpy(dst, mpath->dst, ETH_ALEN);
1601 mpp_set_pinfo(mpath, mpp, pinfo);
1602 rcu_read_unlock();
1603 return 0;
1604}
1605
1606static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
1607 int idx, u8 *dst, u8 *mpp,
1608 struct mpath_info *pinfo)
1609{
1610 struct ieee80211_sub_if_data *sdata;
1611 struct mesh_path *mpath;
1612
1613 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1614
1615 rcu_read_lock();
1616 mpath = mpp_path_lookup_by_idx(sdata, idx);
1617 if (!mpath) {
1618 rcu_read_unlock();
1619 return -ENOENT;
1620 }
1621 memcpy(dst, mpath->dst, ETH_ALEN);
1622 mpp_set_pinfo(mpath, mpp, pinfo);
1623 rcu_read_unlock();
1624 return 0;
1625}
1626
24bdd9f4 1627static int ieee80211_get_mesh_config(struct wiphy *wiphy,
93da9cc1 1628 struct net_device *dev,
1629 struct mesh_config *conf)
1630{
1631 struct ieee80211_sub_if_data *sdata;
1632 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1633
93da9cc1 1634 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1635 return 0;
1636}
1637
1638static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1639{
1640 return (mask >> (parm-1)) & 0x1;
1641}
1642
c80d545d
JC
1643static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1644 const struct mesh_setup *setup)
1645{
1646 u8 *new_ie;
1647 const u8 *old_ie;
4bb62344
CYY
1648 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1649 struct ieee80211_sub_if_data, u.mesh);
c80d545d 1650
581a8b0f 1651 /* allocate information elements */
c80d545d 1652 new_ie = NULL;
581a8b0f 1653 old_ie = ifmsh->ie;
c80d545d 1654
581a8b0f
JC
1655 if (setup->ie_len) {
1656 new_ie = kmemdup(setup->ie, setup->ie_len,
c80d545d
JC
1657 GFP_KERNEL);
1658 if (!new_ie)
1659 return -ENOMEM;
1660 }
581a8b0f
JC
1661 ifmsh->ie_len = setup->ie_len;
1662 ifmsh->ie = new_ie;
1663 kfree(old_ie);
c80d545d
JC
1664
1665 /* now copy the rest of the setup parameters */
1666 ifmsh->mesh_id_len = setup->mesh_id_len;
1667 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
d299a1f2 1668 ifmsh->mesh_sp_id = setup->sync_method;
c80d545d
JC
1669 ifmsh->mesh_pp_id = setup->path_sel_proto;
1670 ifmsh->mesh_pm_id = setup->path_metric;
a6dad6a2 1671 ifmsh->user_mpm = setup->user_mpm;
0d4261ad 1672 ifmsh->mesh_auth_id = setup->auth_id;
b130e5ce
JC
1673 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1674 if (setup->is_authenticated)
1675 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1676 if (setup->is_secure)
1677 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
c80d545d 1678
4bb62344
CYY
1679 /* mcast rate setting in Mesh Node */
1680 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1681 sizeof(setup->mcast_rate));
ffb3cf30 1682 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
4bb62344 1683
9bdbf04d
MP
1684 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1685 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1686
c80d545d
JC
1687 return 0;
1688}
1689
24bdd9f4 1690static int ieee80211_update_mesh_config(struct wiphy *wiphy,
29cbe68c
JB
1691 struct net_device *dev, u32 mask,
1692 const struct mesh_config *nconf)
93da9cc1 1693{
1694 struct mesh_config *conf;
1695 struct ieee80211_sub_if_data *sdata;
63c5723b
RP
1696 struct ieee80211_if_mesh *ifmsh;
1697
93da9cc1 1698 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
63c5723b 1699 ifmsh = &sdata->u.mesh;
93da9cc1 1700
93da9cc1 1701 /* Set the config options which we are interested in setting */
1702 conf = &(sdata->u.mesh.mshcfg);
1703 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1704 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1705 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1706 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1707 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1708 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1709 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1710 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1711 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1712 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1713 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1714 conf->dot11MeshTTL = nconf->dot11MeshTTL;
45904f21 1715 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
58886a90 1716 conf->element_ttl = nconf->element_ttl;
146bb483
TP
1717 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1718 if (ifmsh->user_mpm)
1719 return -EBUSY;
93da9cc1 1720 conf->auto_open_plinks = nconf->auto_open_plinks;
146bb483 1721 }
d299a1f2
JC
1722 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1723 conf->dot11MeshNbrOffsetMaxNeighbor =
1724 nconf->dot11MeshNbrOffsetMaxNeighbor;
93da9cc1 1725 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1726 conf->dot11MeshHWMPmaxPREQretries =
1727 nconf->dot11MeshHWMPmaxPREQretries;
1728 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1729 conf->path_refresh_time = nconf->path_refresh_time;
1730 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1731 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1732 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1733 conf->dot11MeshHWMPactivePathTimeout =
1734 nconf->dot11MeshHWMPactivePathTimeout;
1735 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1736 conf->dot11MeshHWMPpreqMinInterval =
1737 nconf->dot11MeshHWMPpreqMinInterval;
dca7e943
TP
1738 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1739 conf->dot11MeshHWMPperrMinInterval =
1740 nconf->dot11MeshHWMPperrMinInterval;
93da9cc1 1741 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1742 mask))
1743 conf->dot11MeshHWMPnetDiameterTraversalTime =
1744 nconf->dot11MeshHWMPnetDiameterTraversalTime;
63c5723b
RP
1745 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1746 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1747 ieee80211_mesh_root_setup(ifmsh);
1748 }
16dd7267 1749 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
c6133661
TP
1750 /* our current gate announcement implementation rides on root
1751 * announcements, so require this ifmsh to also be a root node
1752 * */
1753 if (nconf->dot11MeshGateAnnouncementProtocol &&
dbb912cd
CYY
1754 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1755 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
c6133661
TP
1756 ieee80211_mesh_root_setup(ifmsh);
1757 }
16dd7267
JC
1758 conf->dot11MeshGateAnnouncementProtocol =
1759 nconf->dot11MeshGateAnnouncementProtocol;
1760 }
a4f606ea 1761 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
0507e159
JC
1762 conf->dot11MeshHWMPRannInterval =
1763 nconf->dot11MeshHWMPRannInterval;
94f90656
CYY
1764 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1765 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
55335137
AN
1766 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1767 /* our RSSI threshold implementation is supported only for
1768 * devices that report signal in dBm.
1769 */
1770 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1771 return -ENOTSUPP;
1772 conf->rssi_threshold = nconf->rssi_threshold;
1773 }
70c33eaa
AN
1774 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1775 conf->ht_opmode = nconf->ht_opmode;
1776 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1777 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1778 }
ac1073a6
CYY
1779 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1780 conf->dot11MeshHWMPactivePathToRootTimeout =
1781 nconf->dot11MeshHWMPactivePathToRootTimeout;
1782 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1783 conf->dot11MeshHWMProotInterval =
1784 nconf->dot11MeshHWMProotInterval;
728b19e5
CYY
1785 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1786 conf->dot11MeshHWMPconfirmationInterval =
1787 nconf->dot11MeshHWMPconfirmationInterval;
3f52b7e3
MP
1788 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1789 conf->power_mode = nconf->power_mode;
1790 ieee80211_mps_local_status_update(sdata);
1791 }
2b5e1967 1792 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
3f52b7e3
MP
1793 conf->dot11MeshAwakeWindowDuration =
1794 nconf->dot11MeshAwakeWindowDuration;
66de6713
CT
1795 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1796 conf->plink_timeout = nconf->plink_timeout;
2b5e1967 1797 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
93da9cc1 1798 return 0;
1799}
1800
29cbe68c
JB
1801static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1802 const struct mesh_config *conf,
1803 const struct mesh_setup *setup)
1804{
1805 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1806 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
c80d545d 1807 int err;
29cbe68c 1808
c80d545d
JC
1809 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1810 err = copy_mesh_setup(ifmsh, setup);
1811 if (err)
1812 return err;
cc1d2806 1813
04ecd257
JB
1814 /* can mesh use other SMPS modes? */
1815 sdata->smps_mode = IEEE80211_SMPS_OFF;
1816 sdata->needed_rx_chains = sdata->local->rx_chains;
1817
34a3740d 1818 mutex_lock(&sdata->local->mtx);
4bf88530 1819 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
55de908a 1820 IEEE80211_CHANCTX_SHARED);
34a3740d 1821 mutex_unlock(&sdata->local->mtx);
cc1d2806
JB
1822 if (err)
1823 return err;
1824
2b5e1967 1825 return ieee80211_start_mesh(sdata);
29cbe68c
JB
1826}
1827
1828static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1829{
1830 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1831
1832 ieee80211_stop_mesh(sdata);
34a3740d 1833 mutex_lock(&sdata->local->mtx);
55de908a 1834 ieee80211_vif_release_channel(sdata);
34a3740d 1835 mutex_unlock(&sdata->local->mtx);
29cbe68c
JB
1836
1837 return 0;
1838}
c5dd9c2b
LCC
1839#endif
1840
9f1ba906
JM
1841static int ieee80211_change_bss(struct wiphy *wiphy,
1842 struct net_device *dev,
1843 struct bss_parameters *params)
1844{
55de908a
JB
1845 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1846 enum ieee80211_band band;
9f1ba906
JM
1847 u32 changed = 0;
1848
7ca133bc 1849 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
55de908a
JB
1850 return -ENOENT;
1851
1852 band = ieee80211_get_sdata_band(sdata);
9f1ba906 1853
9f1ba906 1854 if (params->use_cts_prot >= 0) {
bda3933a 1855 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
9f1ba906
JM
1856 changed |= BSS_CHANGED_ERP_CTS_PROT;
1857 }
1858 if (params->use_short_preamble >= 0) {
bda3933a 1859 sdata->vif.bss_conf.use_short_preamble =
9f1ba906
JM
1860 params->use_short_preamble;
1861 changed |= BSS_CHANGED_ERP_PREAMBLE;
1862 }
43d35343
FF
1863
1864 if (!sdata->vif.bss_conf.use_short_slot &&
55de908a 1865 band == IEEE80211_BAND_5GHZ) {
43d35343
FF
1866 sdata->vif.bss_conf.use_short_slot = true;
1867 changed |= BSS_CHANGED_ERP_SLOT;
1868 }
1869
9f1ba906 1870 if (params->use_short_slot_time >= 0) {
bda3933a 1871 sdata->vif.bss_conf.use_short_slot =
9f1ba906
JM
1872 params->use_short_slot_time;
1873 changed |= BSS_CHANGED_ERP_SLOT;
1874 }
1875
90c97a04 1876 if (params->basic_rates) {
2103dec1
SW
1877 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1878 wiphy->bands[band],
1879 params->basic_rates,
1880 params->basic_rates_len,
1881 &sdata->vif.bss_conf.basic_rates);
90c97a04
JM
1882 changed |= BSS_CHANGED_BASIC_RATES;
1883 }
1884
7b7b5e56
FF
1885 if (params->ap_isolate >= 0) {
1886 if (params->ap_isolate)
1887 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1888 else
1889 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1890 }
1891
80d7e403
HS
1892 if (params->ht_opmode >= 0) {
1893 sdata->vif.bss_conf.ht_operation_mode =
1894 (u16) params->ht_opmode;
1895 changed |= BSS_CHANGED_HT;
1896 }
1897
339afbf4 1898 if (params->p2p_ctwindow >= 0) {
67baf663
JD
1899 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1900 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1901 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1902 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
339afbf4
JB
1903 changed |= BSS_CHANGED_P2P_PS;
1904 }
1905
67baf663
JD
1906 if (params->p2p_opp_ps > 0) {
1907 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1908 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1909 changed |= BSS_CHANGED_P2P_PS;
1910 } else if (params->p2p_opp_ps == 0) {
1911 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1912 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
339afbf4
JB
1913 changed |= BSS_CHANGED_P2P_PS;
1914 }
1915
9f1ba906
JM
1916 ieee80211_bss_info_change_notify(sdata, changed);
1917
1918 return 0;
1919}
1920
31888487 1921static int ieee80211_set_txq_params(struct wiphy *wiphy,
f70f01c2 1922 struct net_device *dev,
31888487
JM
1923 struct ieee80211_txq_params *params)
1924{
1925 struct ieee80211_local *local = wiphy_priv(wiphy);
f6f3def3 1926 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
31888487
JM
1927 struct ieee80211_tx_queue_params p;
1928
1929 if (!local->ops->conf_tx)
1930 return -EOPNOTSUPP;
1931
54bcbc69
JB
1932 if (local->hw.queues < IEEE80211_NUM_ACS)
1933 return -EOPNOTSUPP;
1934
31888487
JM
1935 memset(&p, 0, sizeof(p));
1936 p.aifs = params->aifs;
1937 p.cw_max = params->cwmax;
1938 p.cw_min = params->cwmin;
1939 p.txop = params->txop;
ab13315a
KV
1940
1941 /*
1942 * Setting tx queue params disables u-apsd because it's only
1943 * called in master mode.
1944 */
1945 p.uapsd = false;
1946
a3304b0a
JB
1947 sdata->tx_conf[params->ac] = p;
1948 if (drv_conf_tx(local, sdata, params->ac, &p)) {
0fb9a9ec 1949 wiphy_debug(local->hw.wiphy,
a3304b0a
JB
1950 "failed to set TX queue parameters for AC %d\n",
1951 params->ac);
31888487
JM
1952 return -EINVAL;
1953 }
1954
7d25745d
JB
1955 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1956
31888487
JM
1957 return 0;
1958}
1959
665af4fc 1960#ifdef CONFIG_PM
ff1b6e69
JB
1961static int ieee80211_suspend(struct wiphy *wiphy,
1962 struct cfg80211_wowlan *wowlan)
665af4fc 1963{
eecc4800 1964 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
665af4fc
BC
1965}
1966
1967static int ieee80211_resume(struct wiphy *wiphy)
1968{
1969 return __ieee80211_resume(wiphy_priv(wiphy));
1970}
1971#else
1972#define ieee80211_suspend NULL
1973#define ieee80211_resume NULL
1974#endif
1975
2a519311 1976static int ieee80211_scan(struct wiphy *wiphy,
2a519311
JB
1977 struct cfg80211_scan_request *req)
1978{
fd014284
JB
1979 struct ieee80211_sub_if_data *sdata;
1980
1981 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2a519311 1982
2ca27bcf
JB
1983 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1984 case NL80211_IFTYPE_STATION:
1985 case NL80211_IFTYPE_ADHOC:
1986 case NL80211_IFTYPE_MESH_POINT:
1987 case NL80211_IFTYPE_P2P_CLIENT:
f142c6b9 1988 case NL80211_IFTYPE_P2P_DEVICE:
2ca27bcf
JB
1989 break;
1990 case NL80211_IFTYPE_P2P_GO:
1991 if (sdata->local->ops->hw_scan)
1992 break;
e9d7732e
JB
1993 /*
1994 * FIXME: implement NoA while scanning in software,
1995 * for now fall through to allow scanning only when
1996 * beaconing hasn't been configured yet
1997 */
2ca27bcf 1998 case NL80211_IFTYPE_AP:
5c95b940
AQ
1999 /*
2000 * If the scan has been forced (and the driver supports
2001 * forcing), don't care about being beaconing already.
2002 * This will create problems to the attached stations (e.g. all
2003 * the frames sent while scanning on other channel will be
2004 * lost)
2005 */
2006 if (sdata->u.ap.beacon &&
2007 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2008 !(req->flags & NL80211_SCAN_FLAG_AP)))
2ca27bcf
JB
2009 return -EOPNOTSUPP;
2010 break;
2011 default:
2012 return -EOPNOTSUPP;
2013 }
2a519311
JB
2014
2015 return ieee80211_request_scan(sdata, req);
2016}
2017
79f460ca
LC
2018static int
2019ieee80211_sched_scan_start(struct wiphy *wiphy,
2020 struct net_device *dev,
2021 struct cfg80211_sched_scan_request *req)
2022{
2023 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2024
2025 if (!sdata->local->ops->sched_scan_start)
2026 return -EOPNOTSUPP;
2027
2028 return ieee80211_request_sched_scan_start(sdata, req);
2029}
2030
2031static int
85a9994a 2032ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
79f460ca
LC
2033{
2034 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2035
2036 if (!sdata->local->ops->sched_scan_stop)
2037 return -EOPNOTSUPP;
2038
85a9994a 2039 return ieee80211_request_sched_scan_stop(sdata);
79f460ca
LC
2040}
2041
636a5d36
JM
2042static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2043 struct cfg80211_auth_request *req)
2044{
77fdaa12 2045 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
636a5d36
JM
2046}
2047
2048static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2049 struct cfg80211_assoc_request *req)
2050{
77fdaa12 2051 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
636a5d36
JM
2052}
2053
2054static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
63c9c5e7 2055 struct cfg80211_deauth_request *req)
636a5d36 2056{
63c9c5e7 2057 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
636a5d36
JM
2058}
2059
2060static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
63c9c5e7 2061 struct cfg80211_disassoc_request *req)
636a5d36 2062{
63c9c5e7 2063 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
636a5d36
JM
2064}
2065
af8cdcd8
JB
2066static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2067 struct cfg80211_ibss_params *params)
2068{
55de908a 2069 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
af8cdcd8
JB
2070}
2071
2072static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2073{
55de908a 2074 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
af8cdcd8
JB
2075}
2076
239281f8
RL
2077static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2078 struct ocb_setup *setup)
2079{
2080 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2081}
2082
2083static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2084{
2085 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2086}
2087
391e53e3
AQ
2088static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2089 int rate[IEEE80211_NUM_BANDS])
2090{
2091 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2092
9887dbf5
CD
2093 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2094 sizeof(int) * IEEE80211_NUM_BANDS);
391e53e3
AQ
2095
2096 return 0;
2097}
2098
b9a5f8ca
JM
2099static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2100{
2101 struct ieee80211_local *local = wiphy_priv(wiphy);
24487981 2102 int err;
b9a5f8ca 2103
f23a4780 2104 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
17c18bf8
JB
2105 ieee80211_check_fast_xmit_all(local);
2106
f23a4780
AN
2107 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2108
17c18bf8
JB
2109 if (err) {
2110 ieee80211_check_fast_xmit_all(local);
f23a4780 2111 return err;
17c18bf8 2112 }
f23a4780
AN
2113 }
2114
a4bcaf55
LB
2115 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2116 (changed & WIPHY_PARAM_DYN_ACK)) {
2117 s16 coverage_class;
2118
2119 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2120 wiphy->coverage_class : -1;
2121 err = drv_set_coverage_class(local, coverage_class);
310bc676
LT
2122
2123 if (err)
2124 return err;
2125 }
2126
b9a5f8ca 2127 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
24487981 2128 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
b9a5f8ca 2129
24487981
JB
2130 if (err)
2131 return err;
b9a5f8ca
JM
2132 }
2133
8bc83c24
JB
2134 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2135 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2136 return -EINVAL;
b9a5f8ca 2137 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
8bc83c24
JB
2138 }
2139 if (changed & WIPHY_PARAM_RETRY_LONG) {
2140 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2141 return -EINVAL;
b9a5f8ca 2142 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
8bc83c24 2143 }
b9a5f8ca
JM
2144 if (changed &
2145 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2146 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2147
2148 return 0;
2149}
2150
7643a2c3 2151static int ieee80211_set_tx_power(struct wiphy *wiphy,
c8442118 2152 struct wireless_dev *wdev,
fa61cf70 2153 enum nl80211_tx_power_setting type, int mbm)
7643a2c3
JB
2154{
2155 struct ieee80211_local *local = wiphy_priv(wiphy);
1ea6f9c0 2156 struct ieee80211_sub_if_data *sdata;
db82d8a9
LB
2157 enum nl80211_tx_power_setting txp_type = type;
2158 bool update_txp_type = false;
7643a2c3 2159
1ea6f9c0
JB
2160 if (wdev) {
2161 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2162
2163 switch (type) {
2164 case NL80211_TX_POWER_AUTOMATIC:
2165 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
db82d8a9 2166 txp_type = NL80211_TX_POWER_LIMITED;
1ea6f9c0
JB
2167 break;
2168 case NL80211_TX_POWER_LIMITED:
2169 case NL80211_TX_POWER_FIXED:
2170 if (mbm < 0 || (mbm % 100))
2171 return -EOPNOTSUPP;
2172 sdata->user_power_level = MBM_TO_DBM(mbm);
2173 break;
2174 }
2175
db82d8a9
LB
2176 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2177 update_txp_type = true;
2178 sdata->vif.bss_conf.txpower_type = txp_type;
2179 }
2180
2181 ieee80211_recalc_txpower(sdata, update_txp_type);
1ea6f9c0
JB
2182
2183 return 0;
2184 }
55de908a 2185
7643a2c3 2186 switch (type) {
fa61cf70 2187 case NL80211_TX_POWER_AUTOMATIC:
1ea6f9c0 2188 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
db82d8a9 2189 txp_type = NL80211_TX_POWER_LIMITED;
7643a2c3 2190 break;
fa61cf70 2191 case NL80211_TX_POWER_LIMITED:
fa61cf70
JO
2192 case NL80211_TX_POWER_FIXED:
2193 if (mbm < 0 || (mbm % 100))
2194 return -EOPNOTSUPP;
fa61cf70 2195 local->user_power_level = MBM_TO_DBM(mbm);
7643a2c3 2196 break;
7643a2c3
JB
2197 }
2198
1ea6f9c0 2199 mutex_lock(&local->iflist_mtx);
db82d8a9 2200 list_for_each_entry(sdata, &local->interfaces, list) {
1ea6f9c0 2201 sdata->user_power_level = local->user_power_level;
db82d8a9
LB
2202 if (txp_type != sdata->vif.bss_conf.txpower_type)
2203 update_txp_type = true;
2204 sdata->vif.bss_conf.txpower_type = txp_type;
2205 }
1ea6f9c0 2206 list_for_each_entry(sdata, &local->interfaces, list)
db82d8a9 2207 ieee80211_recalc_txpower(sdata, update_txp_type);
1ea6f9c0 2208 mutex_unlock(&local->iflist_mtx);
7643a2c3
JB
2209
2210 return 0;
2211}
2212
c8442118
JB
2213static int ieee80211_get_tx_power(struct wiphy *wiphy,
2214 struct wireless_dev *wdev,
2215 int *dbm)
7643a2c3
JB
2216{
2217 struct ieee80211_local *local = wiphy_priv(wiphy);
1ea6f9c0 2218 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
7643a2c3 2219
5b3dc42b
FF
2220 if (local->ops->get_txpower)
2221 return drv_get_txpower(local, sdata, dbm);
2222
1ea6f9c0
JB
2223 if (!local->use_chanctx)
2224 *dbm = local->hw.conf.power_level;
2225 else
2226 *dbm = sdata->vif.bss_conf.txpower;
7643a2c3 2227
7643a2c3
JB
2228 return 0;
2229}
2230
ab737a4f 2231static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
388ac775 2232 const u8 *addr)
ab737a4f
JB
2233{
2234 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2235
2236 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2237
2238 return 0;
2239}
2240
1f87f7d3
JB
2241static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2242{
2243 struct ieee80211_local *local = wiphy_priv(wiphy);
2244
2245 drv_rfkill_poll(local);
2246}
2247
aff89a9b 2248#ifdef CONFIG_NL80211_TESTMODE
fc73f11f
DS
2249static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2250 struct wireless_dev *wdev,
2251 void *data, int len)
aff89a9b
JB
2252{
2253 struct ieee80211_local *local = wiphy_priv(wiphy);
52981cd7 2254 struct ieee80211_vif *vif = NULL;
aff89a9b
JB
2255
2256 if (!local->ops->testmode_cmd)
2257 return -EOPNOTSUPP;
2258
52981cd7
DS
2259 if (wdev) {
2260 struct ieee80211_sub_if_data *sdata;
2261
2262 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2263 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2264 vif = &sdata->vif;
2265 }
2266
2267 return local->ops->testmode_cmd(&local->hw, vif, data, len);
aff89a9b 2268}
71063f0e
WYG
2269
2270static int ieee80211_testmode_dump(struct wiphy *wiphy,
2271 struct sk_buff *skb,
2272 struct netlink_callback *cb,
2273 void *data, int len)
2274{
2275 struct ieee80211_local *local = wiphy_priv(wiphy);
2276
2277 if (!local->ops->testmode_dump)
2278 return -EOPNOTSUPP;
2279
2280 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2281}
aff89a9b
JB
2282#endif
2283
687da132
EG
2284int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2285 enum ieee80211_smps_mode smps_mode)
2286{
2287 struct sta_info *sta;
2288 enum ieee80211_smps_mode old_req;
687da132
EG
2289
2290 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2291 return -EINVAL;
2292
2293 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2294 return 0;
2295
2296 old_req = sdata->u.ap.req_smps;
2297 sdata->u.ap.req_smps = smps_mode;
2298
2299 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2300 if (old_req == smps_mode ||
2301 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2302 return 0;
2303
2304 /* If no associated stations, there's no need to do anything */
2305 if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
2306 sdata->smps_mode = smps_mode;
2307 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2308 return 0;
2309 }
2310
2311 ht_dbg(sdata,
6a8b4adb 2312 "SMPS %d requested in AP mode, sending Action frame to %d stations\n",
687da132
EG
2313 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2314
2315 mutex_lock(&sdata->local->sta_mtx);
7d9bb2f0
JB
2316 list_for_each_entry(sta, &sdata->local->sta_list, list) {
2317 /*
2318 * Only stations associated to our AP and
2319 * associated VLANs
2320 */
2321 if (sta->sdata->bss != &sdata->u.ap)
2322 continue;
687da132 2323
7d9bb2f0
JB
2324 /* This station doesn't support MIMO - skip it */
2325 if (sta_info_tx_streams(sta) == 1)
2326 continue;
687da132 2327
7d9bb2f0
JB
2328 /*
2329 * Don't wake up a STA just to send the action frame
2330 * unless we are getting more restrictive.
2331 */
2332 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2333 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2334 smps_mode)) {
2335 ht_dbg(sdata, "Won't send SMPS to sleeping STA %pM\n",
2336 sta->sta.addr);
2337 continue;
2338 }
687da132 2339
7d9bb2f0
JB
2340 /*
2341 * If the STA is not authorized, wait until it gets
2342 * authorized and the action frame will be sent then.
2343 */
2344 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2345 continue;
687da132 2346
7d9bb2f0
JB
2347 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2348 ieee80211_send_smps_action(sdata, smps_mode, sta->sta.addr,
2349 sdata->vif.bss_conf.bssid);
687da132
EG
2350 }
2351 mutex_unlock(&sdata->local->sta_mtx);
2352
2353 sdata->smps_mode = smps_mode;
2354 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2355
2356 return 0;
2357}
2358
2359int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2360 enum ieee80211_smps_mode smps_mode)
0f78231b
JB
2361{
2362 const u8 *ap;
2363 enum ieee80211_smps_mode old_req;
2364 int err;
2365
8d61ffa5 2366 lockdep_assert_held(&sdata->wdev.mtx);
243e6df4 2367
687da132
EG
2368 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2369 return -EINVAL;
2370
0f78231b
JB
2371 old_req = sdata->u.mgd.req_smps;
2372 sdata->u.mgd.req_smps = smps_mode;
2373
2374 if (old_req == smps_mode &&
2375 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2376 return 0;
2377
2378 /*
2379 * If not associated, or current association is not an HT
04ecd257
JB
2380 * association, there's no need to do anything, just store
2381 * the new value until we associate.
0f78231b
JB
2382 */
2383 if (!sdata->u.mgd.associated ||
4bf88530 2384 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
0f78231b 2385 return 0;
0f78231b 2386
0c1ad2ca 2387 ap = sdata->u.mgd.associated->bssid;
0f78231b
JB
2388
2389 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2390 if (sdata->u.mgd.powersave)
2391 smps_mode = IEEE80211_SMPS_DYNAMIC;
2392 else
2393 smps_mode = IEEE80211_SMPS_OFF;
2394 }
2395
2396 /* send SM PS frame to AP */
2397 err = ieee80211_send_smps_action(sdata, smps_mode,
2398 ap, ap);
2399 if (err)
2400 sdata->u.mgd.req_smps = old_req;
2401
2402 return err;
2403}
2404
bc92afd9
JB
2405static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2406 bool enabled, int timeout)
2407{
2408 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2409 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
bc92afd9 2410
2d3db210 2411 if (sdata->vif.type != NL80211_IFTYPE_STATION)
e5de30c9
BP
2412 return -EOPNOTSUPP;
2413
bc92afd9
JB
2414 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2415 return -EOPNOTSUPP;
2416
2417 if (enabled == sdata->u.mgd.powersave &&
ff616381 2418 timeout == local->dynamic_ps_forced_timeout)
bc92afd9
JB
2419 return 0;
2420
2421 sdata->u.mgd.powersave = enabled;
ff616381 2422 local->dynamic_ps_forced_timeout = timeout;
bc92afd9 2423
0f78231b 2424 /* no change, but if automatic follow powersave */
ed405be5 2425 sdata_lock(sdata);
687da132 2426 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
ed405be5 2427 sdata_unlock(sdata);
0f78231b 2428
bc92afd9
JB
2429 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2430 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2431
2432 ieee80211_recalc_ps(local, -1);
ab095877 2433 ieee80211_recalc_ps_vif(sdata);
bc92afd9
JB
2434
2435 return 0;
2436}
2437
a97c13c3
JO
2438static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2439 struct net_device *dev,
2440 s32 rssi_thold, u32 rssi_hyst)
2441{
2442 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
a97c13c3
JO
2443 struct ieee80211_vif *vif = &sdata->vif;
2444 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2445
a97c13c3
JO
2446 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2447 rssi_hyst == bss_conf->cqm_rssi_hyst)
2448 return 0;
2449
2450 bss_conf->cqm_rssi_thold = rssi_thold;
2451 bss_conf->cqm_rssi_hyst = rssi_hyst;
2452
2453 /* tell the driver upon association, unless already associated */
ea086359
JB
2454 if (sdata->u.mgd.associated &&
2455 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
a97c13c3
JO
2456 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2457
2458 return 0;
2459}
2460
9930380f
JB
2461static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2462 struct net_device *dev,
2463 const u8 *addr,
2464 const struct cfg80211_bitrate_mask *mask)
2465{
2466 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2467 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
bdbfd6b5 2468 int i, ret;
2c7e6bc9 2469
554a43d5
EP
2470 if (!ieee80211_sdata_running(sdata))
2471 return -ENETDOWN;
2472
bdbfd6b5
SM
2473 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2474 ret = drv_set_bitrate_mask(local, sdata, mask);
2475 if (ret)
2476 return ret;
2477 }
9930380f 2478
19468413 2479 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
2ffbe6d3
FF
2480 struct ieee80211_supported_band *sband = wiphy->bands[i];
2481 int j;
2482
37eb0b16 2483 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
d1e33e65
JD
2484 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2485 sizeof(mask->control[i].ht_mcs));
2ffbe6d3
FF
2486
2487 sdata->rc_has_mcs_mask[i] = false;
2488 if (!sband)
2489 continue;
2490
2491 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2492 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2493 sdata->rc_has_mcs_mask[i] = true;
2494 break;
2495 }
19468413 2496 }
9930380f 2497
37eb0b16 2498 return 0;
9930380f
JB
2499}
2500
eaa336b0
EP
2501static bool ieee80211_coalesce_started_roc(struct ieee80211_local *local,
2502 struct ieee80211_roc_work *new_roc,
2503 struct ieee80211_roc_work *cur_roc)
2504{
2505 unsigned long j = jiffies;
2506 unsigned long cur_roc_end = cur_roc->hw_start_time +
2507 msecs_to_jiffies(cur_roc->duration);
2508 struct ieee80211_roc_work *next_roc;
2509 int new_dur;
2510
2511 if (WARN_ON(!cur_roc->started || !cur_roc->hw_begun))
2512 return false;
2513
2514 if (time_after(j + IEEE80211_ROC_MIN_LEFT, cur_roc_end))
2515 return false;
2516
2517 ieee80211_handle_roc_started(new_roc);
2518
2519 new_dur = new_roc->duration - jiffies_to_msecs(cur_roc_end - j);
2520
2521 /* cur_roc is long enough - add new_roc to the dependents list. */
2522 if (new_dur <= 0) {
2523 list_add_tail(&new_roc->list, &cur_roc->dependents);
2524 return true;
2525 }
2526
2527 new_roc->duration = new_dur;
2528
2529 /*
2530 * if cur_roc was already coalesced before, we might
2531 * want to extend the next roc instead of adding
2532 * a new one.
2533 */
2534 next_roc = list_entry(cur_roc->list.next,
2535 struct ieee80211_roc_work, list);
2536 if (&next_roc->list != &local->roc_list &&
2537 next_roc->chan == new_roc->chan &&
2538 next_roc->sdata == new_roc->sdata &&
2539 !WARN_ON(next_roc->started)) {
2540 list_add_tail(&new_roc->list, &next_roc->dependents);
2541 next_roc->duration = max(next_roc->duration,
2542 new_roc->duration);
2543 next_roc->type = max(next_roc->type, new_roc->type);
2544 return true;
2545 }
2546
2547 /* add right after cur_roc */
2548 list_add(&new_roc->list, &cur_roc->list);
2549
2550 return true;
2551}
2552
2eb278e0
JB
2553static int ieee80211_start_roc_work(struct ieee80211_local *local,
2554 struct ieee80211_sub_if_data *sdata,
2555 struct ieee80211_channel *channel,
2eb278e0 2556 unsigned int duration, u64 *cookie,
d339d5ca
IP
2557 struct sk_buff *txskb,
2558 enum ieee80211_roc_type type)
2eb278e0
JB
2559{
2560 struct ieee80211_roc_work *roc, *tmp;
2561 bool queued = false;
21f83589 2562 int ret;
21f83589
JB
2563
2564 lockdep_assert_held(&local->mtx);
2565
fe57d9f5
JB
2566 if (local->use_chanctx && !local->ops->remain_on_channel)
2567 return -EOPNOTSUPP;
2568
2eb278e0
JB
2569 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2570 if (!roc)
2571 return -ENOMEM;
2572
2fae062e
IP
2573 /*
2574 * If the duration is zero, then the driver
2575 * wouldn't actually do anything. Set it to
2576 * 10 for now.
2577 *
2578 * TODO: cancel the off-channel operation
2579 * when we get the SKB's TX status and
2580 * the wait time was zero before.
2581 */
2582 if (!duration)
2583 duration = 10;
2584
2eb278e0 2585 roc->chan = channel;
2eb278e0
JB
2586 roc->duration = duration;
2587 roc->req_duration = duration;
2588 roc->frame = txskb;
d339d5ca 2589 roc->type = type;
2eb278e0
JB
2590 roc->mgmt_tx_cookie = (unsigned long)txskb;
2591 roc->sdata = sdata;
2592 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2593 INIT_LIST_HEAD(&roc->dependents);
2594
2f617435
EP
2595 /*
2596 * cookie is either the roc cookie (for normal roc)
2597 * or the SKB (for mgmt TX)
2598 */
2599 if (!txskb) {
2600 /* local->mtx protects this */
2601 local->roc_cookie_counter++;
2602 roc->cookie = local->roc_cookie_counter;
2603 /* wow, you wrapped 64 bits ... more likely a bug */
2604 if (WARN_ON(roc->cookie == 0)) {
2605 roc->cookie = 1;
2606 local->roc_cookie_counter++;
2607 }
2608 *cookie = roc->cookie;
2609 } else {
2610 *cookie = (unsigned long)txskb;
2611 }
2612
2eb278e0 2613 /* if there's one pending or we're scanning, queue this one */
164eb02d 2614 if (!list_empty(&local->roc_list) ||
5cbc95a7 2615 local->scanning || ieee80211_is_radar_required(local))
2eb278e0
JB
2616 goto out_check_combine;
2617
2618 /* if not HW assist, just queue & schedule work */
2619 if (!local->ops->remain_on_channel) {
2620 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2621 goto out_queue;
2622 }
2623
2624 /* otherwise actually kick it off here (for error handling) */
2625
d339d5ca 2626 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
21f83589 2627 if (ret) {
2eb278e0
JB
2628 kfree(roc);
2629 return ret;
21f83589
JB
2630 }
2631
2eb278e0
JB
2632 roc->started = true;
2633 goto out_queue;
2634
2635 out_check_combine:
2636 list_for_each_entry(tmp, &local->roc_list, list) {
42d97a59 2637 if (tmp->chan != channel || tmp->sdata != sdata)
2eb278e0
JB
2638 continue;
2639
2640 /*
2641 * Extend this ROC if possible:
2642 *
2643 * If it hasn't started yet, just increase the duration
2644 * and add the new one to the list of dependents.
d339d5ca
IP
2645 * If the type of the new ROC has higher priority, modify the
2646 * type of the previous one to match that of the new one.
2eb278e0
JB
2647 */
2648 if (!tmp->started) {
2649 list_add_tail(&roc->list, &tmp->dependents);
2650 tmp->duration = max(tmp->duration, roc->duration);
d339d5ca 2651 tmp->type = max(tmp->type, roc->type);
2eb278e0
JB
2652 queued = true;
2653 break;
2654 }
2655
2656 /* If it has already started, it's more difficult ... */
2657 if (local->ops->remain_on_channel) {
2eb278e0
JB
2658 /*
2659 * In the offloaded ROC case, if it hasn't begun, add
2660 * this new one to the dependent list to be handled
d339d5ca 2661 * when the master one begins. If it has begun,
2eb278e0
JB
2662 * check that there's still a minimum time left and
2663 * if so, start this one, transmitting the frame, but
d339d5ca 2664 * add it to the list directly after this one with
2eb278e0
JB
2665 * a reduced time so we'll ask the driver to execute
2666 * it right after finishing the previous one, in the
2667 * hope that it'll also be executed right afterwards,
2668 * effectively extending the old one.
2669 * If there's no minimum time left, just add it to the
2670 * normal list.
d339d5ca
IP
2671 * TODO: the ROC type is ignored here, assuming that it
2672 * is better to immediately use the current ROC.
2eb278e0
JB
2673 */
2674 if (!tmp->hw_begun) {
2675 list_add_tail(&roc->list, &tmp->dependents);
2676 queued = true;
2677 break;
2678 }
2679
eaa336b0 2680 if (ieee80211_coalesce_started_roc(local, roc, tmp))
2eb278e0 2681 queued = true;
2eb278e0
JB
2682 } else if (del_timer_sync(&tmp->work.timer)) {
2683 unsigned long new_end;
2684
2685 /*
2686 * In the software ROC case, cancel the timer, if
2687 * that fails then the finish work is already
2688 * queued/pending and thus we queue the new ROC
2689 * normally, if that succeeds then we can extend
2690 * the timer duration and TX the frame (if any.)
2691 */
2692
2693 list_add_tail(&roc->list, &tmp->dependents);
2694 queued = true;
2695
2696 new_end = jiffies + msecs_to_jiffies(roc->duration);
2697
2698 /* ok, it was started & we canceled timer */
2699 if (time_after(new_end, tmp->work.timer.expires))
2700 mod_timer(&tmp->work.timer, new_end);
2701 else
2702 add_timer(&tmp->work.timer);
2703
2704 ieee80211_handle_roc_started(roc);
2705 }
2706 break;
2707 }
2708
2709 out_queue:
2710 if (!queued)
2711 list_add_tail(&roc->list, &local->roc_list);
2712
2eb278e0 2713 return 0;
21f83589
JB
2714}
2715
b8bc4b0a 2716static int ieee80211_remain_on_channel(struct wiphy *wiphy,
71bbc994 2717 struct wireless_dev *wdev,
b8bc4b0a 2718 struct ieee80211_channel *chan,
b8bc4b0a
JB
2719 unsigned int duration,
2720 u64 *cookie)
2721{
71bbc994 2722 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
21f83589 2723 struct ieee80211_local *local = sdata->local;
2eb278e0 2724 int ret;
21f83589 2725
2eb278e0 2726 mutex_lock(&local->mtx);
42d97a59 2727 ret = ieee80211_start_roc_work(local, sdata, chan,
d339d5ca
IP
2728 duration, cookie, NULL,
2729 IEEE80211_ROC_TYPE_NORMAL);
2eb278e0 2730 mutex_unlock(&local->mtx);
b8bc4b0a 2731
2eb278e0 2732 return ret;
b8bc4b0a
JB
2733}
2734
2eb278e0
JB
2735static int ieee80211_cancel_roc(struct ieee80211_local *local,
2736 u64 cookie, bool mgmt_tx)
21f83589 2737{
2eb278e0 2738 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
21f83589
JB
2739 int ret;
2740
2eb278e0
JB
2741 mutex_lock(&local->mtx);
2742 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
e979e33c
JB
2743 struct ieee80211_roc_work *dep, *tmp2;
2744
2745 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
50febf6a 2746 if (!mgmt_tx && dep->cookie != cookie)
e979e33c
JB
2747 continue;
2748 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2749 continue;
2750 /* found dependent item -- just remove it */
2751 list_del(&dep->list);
2752 mutex_unlock(&local->mtx);
2753
3fbd45ca 2754 ieee80211_roc_notify_destroy(dep, true);
e979e33c
JB
2755 return 0;
2756 }
2757
50febf6a 2758 if (!mgmt_tx && roc->cookie != cookie)
2eb278e0
JB
2759 continue;
2760 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2761 continue;
21f83589 2762
2eb278e0
JB
2763 found = roc;
2764 break;
2765 }
21f83589 2766
2eb278e0
JB
2767 if (!found) {
2768 mutex_unlock(&local->mtx);
2769 return -ENOENT;
2770 }
21f83589 2771
e979e33c
JB
2772 /*
2773 * We found the item to cancel, so do that. Note that it
2774 * may have dependents, which we also cancel (and send
2775 * the expired signal for.) Not doing so would be quite
2776 * tricky here, but we may need to fix it later.
2777 */
2778
2eb278e0
JB
2779 if (local->ops->remain_on_channel) {
2780 if (found->started) {
2781 ret = drv_cancel_remain_on_channel(local);
2782 if (WARN_ON_ONCE(ret)) {
2783 mutex_unlock(&local->mtx);
2784 return ret;
2785 }
2786 }
21f83589 2787
2eb278e0 2788 list_del(&found->list);
21f83589 2789
0f6b3f59
JB
2790 if (found->started)
2791 ieee80211_start_next_roc(local);
2eb278e0 2792 mutex_unlock(&local->mtx);
21f83589 2793
3fbd45ca 2794 ieee80211_roc_notify_destroy(found, true);
2eb278e0
JB
2795 } else {
2796 /* work may be pending so use it all the time */
2797 found->abort = true;
2798 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
21f83589 2799
21f83589
JB
2800 mutex_unlock(&local->mtx);
2801
2eb278e0
JB
2802 /* work will clean up etc */
2803 flush_delayed_work(&found->work);
3fbd45ca
JB
2804 WARN_ON(!found->to_be_freed);
2805 kfree(found);
21f83589 2806 }
b8bc4b0a 2807
2eb278e0 2808 return 0;
b8bc4b0a
JB
2809}
2810
2eb278e0 2811static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
71bbc994 2812 struct wireless_dev *wdev,
2eb278e0 2813 u64 cookie)
f30221e4 2814{
71bbc994 2815 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2eb278e0 2816 struct ieee80211_local *local = sdata->local;
f30221e4 2817
2eb278e0 2818 return ieee80211_cancel_roc(local, cookie, false);
f30221e4
JB
2819}
2820
164eb02d
SW
2821static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2822 struct net_device *dev,
31559f35
JD
2823 struct cfg80211_chan_def *chandef,
2824 u32 cac_time_ms)
164eb02d
SW
2825{
2826 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2827 struct ieee80211_local *local = sdata->local;
164eb02d
SW
2828 int err;
2829
34a3740d
JB
2830 mutex_lock(&local->mtx);
2831 if (!list_empty(&local->roc_list) || local->scanning) {
2832 err = -EBUSY;
2833 goto out_unlock;
2834 }
164eb02d
SW
2835
2836 /* whatever, but channel contexts should not complain about that one */
2837 sdata->smps_mode = IEEE80211_SMPS_OFF;
2838 sdata->needed_rx_chains = local->rx_chains;
164eb02d 2839
164eb02d
SW
2840 err = ieee80211_vif_use_channel(sdata, chandef,
2841 IEEE80211_CHANCTX_SHARED);
164eb02d 2842 if (err)
34a3740d 2843 goto out_unlock;
164eb02d 2844
164eb02d 2845 ieee80211_queue_delayed_work(&sdata->local->hw,
31559f35
JD
2846 &sdata->dfs_cac_timer_work,
2847 msecs_to_jiffies(cac_time_ms));
164eb02d 2848
34a3740d
JB
2849 out_unlock:
2850 mutex_unlock(&local->mtx);
2851 return err;
164eb02d
SW
2852}
2853
73da7d5b
SW
2854static struct cfg80211_beacon_data *
2855cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2856{
2857 struct cfg80211_beacon_data *new_beacon;
2858 u8 *pos;
2859 int len;
2860
2861 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2862 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2863 beacon->probe_resp_len;
2864
2865 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2866 if (!new_beacon)
2867 return NULL;
2868
2869 pos = (u8 *)(new_beacon + 1);
2870 if (beacon->head_len) {
2871 new_beacon->head_len = beacon->head_len;
2872 new_beacon->head = pos;
2873 memcpy(pos, beacon->head, beacon->head_len);
2874 pos += beacon->head_len;
2875 }
2876 if (beacon->tail_len) {
2877 new_beacon->tail_len = beacon->tail_len;
2878 new_beacon->tail = pos;
2879 memcpy(pos, beacon->tail, beacon->tail_len);
2880 pos += beacon->tail_len;
2881 }
2882 if (beacon->beacon_ies_len) {
2883 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2884 new_beacon->beacon_ies = pos;
2885 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2886 pos += beacon->beacon_ies_len;
2887 }
2888 if (beacon->proberesp_ies_len) {
2889 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2890 new_beacon->proberesp_ies = pos;
2891 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2892 pos += beacon->proberesp_ies_len;
2893 }
2894 if (beacon->assocresp_ies_len) {
2895 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2896 new_beacon->assocresp_ies = pos;
2897 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2898 pos += beacon->assocresp_ies_len;
2899 }
2900 if (beacon->probe_resp_len) {
2901 new_beacon->probe_resp_len = beacon->probe_resp_len;
2902 beacon->probe_resp = pos;
2903 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2904 pos += beacon->probe_resp_len;
2905 }
2906
2907 return new_beacon;
2908}
2909
66e01cf9 2910void ieee80211_csa_finish(struct ieee80211_vif *vif)
73da7d5b 2911{
66e01cf9 2912 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
73da7d5b 2913
66e01cf9
LC
2914 ieee80211_queue_work(&sdata->local->hw,
2915 &sdata->csa_finalize_work);
2916}
2917EXPORT_SYMBOL(ieee80211_csa_finish);
e487eaeb 2918
66199506
MK
2919static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
2920 u32 *changed)
66e01cf9 2921{
66199506 2922 int err;
7578d575 2923
cd7760e6
SW
2924 switch (sdata->vif.type) {
2925 case NL80211_IFTYPE_AP:
af296bdb
MK
2926 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2927 NULL);
97518af1
MK
2928 kfree(sdata->u.ap.next_beacon);
2929 sdata->u.ap.next_beacon = NULL;
2930
cd7760e6 2931 if (err < 0)
66199506
MK
2932 return err;
2933 *changed |= err;
cd7760e6
SW
2934 break;
2935 case NL80211_IFTYPE_ADHOC:
faf046e7
MK
2936 err = ieee80211_ibss_finish_csa(sdata);
2937 if (err < 0)
66199506
MK
2938 return err;
2939 *changed |= err;
cd7760e6 2940 break;
b8456a14
CYY
2941#ifdef CONFIG_MAC80211_MESH
2942 case NL80211_IFTYPE_MESH_POINT:
2943 err = ieee80211_mesh_finish_csa(sdata);
2944 if (err < 0)
66199506
MK
2945 return err;
2946 *changed |= err;
b8456a14
CYY
2947 break;
2948#endif
cd7760e6
SW
2949 default:
2950 WARN_ON(1);
66199506
MK
2951 return -EINVAL;
2952 }
2953
2954 return 0;
2955}
2956
cf8767dd 2957static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
66199506
MK
2958{
2959 struct ieee80211_local *local = sdata->local;
2960 u32 changed = 0;
2961 int err;
2962
2963 sdata_assert_lock(sdata);
2964 lockdep_assert_held(&local->mtx);
03078de4 2965 lockdep_assert_held(&local->chanctx_mtx);
66199506 2966
03078de4
MK
2967 /*
2968 * using reservation isn't immediate as it may be deferred until later
2969 * with multi-vif. once reservation is complete it will re-schedule the
2970 * work with no reserved_chanctx so verify chandef to check if it
2971 * completed successfully
2972 */
66199506 2973
03078de4
MK
2974 if (sdata->reserved_chanctx) {
2975 /*
2976 * with multi-vif csa driver may call ieee80211_csa_finish()
2977 * many times while waiting for other interfaces to use their
2978 * reservations
2979 */
2980 if (sdata->reserved_ready)
2981 return 0;
2982
408b18ab 2983 return ieee80211_vif_use_reserved_context(sdata);
cd7760e6 2984 }
73da7d5b 2985
03078de4
MK
2986 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
2987 &sdata->csa_chandef))
2988 return -EINVAL;
2989
66199506
MK
2990 sdata->vif.csa_active = false;
2991
2992 err = ieee80211_set_after_csa_beacon(sdata, &changed);
2993 if (err)
cf8767dd 2994 return err;
faf046e7 2995
66199506 2996 ieee80211_bss_info_change_notify(sdata, changed);
59af6928 2997
a46992b4
LC
2998 if (sdata->csa_block_tx) {
2999 ieee80211_wake_vif_queues(local, sdata,
3000 IEEE80211_QUEUE_STOP_REASON_CSA);
3001 sdata->csa_block_tx = false;
3002 }
cf8767dd 3003
f1d65583
LC
3004 err = drv_post_channel_switch(sdata);
3005 if (err)
3006 return err;
3007
3008 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
3009
cf8767dd
MK
3010 return 0;
3011}
3012
3013static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3014{
3015 if (__ieee80211_csa_finalize(sdata)) {
3016 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3017 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3018 GFP_KERNEL);
3019 }
66e01cf9
LC
3020}
3021
3022void ieee80211_csa_finalize_work(struct work_struct *work)
3023{
3024 struct ieee80211_sub_if_data *sdata =
3025 container_of(work, struct ieee80211_sub_if_data,
3026 csa_finalize_work);
59af6928 3027 struct ieee80211_local *local = sdata->local;
66e01cf9
LC
3028
3029 sdata_lock(sdata);
59af6928 3030 mutex_lock(&local->mtx);
03078de4 3031 mutex_lock(&local->chanctx_mtx);
59af6928 3032
66e01cf9
LC
3033 /* AP might have been stopped while waiting for the lock. */
3034 if (!sdata->vif.csa_active)
3035 goto unlock;
3036
3037 if (!ieee80211_sdata_running(sdata))
3038 goto unlock;
3039
3040 ieee80211_csa_finalize(sdata);
e487eaeb
SW
3041
3042unlock:
03078de4 3043 mutex_unlock(&local->chanctx_mtx);
59af6928 3044 mutex_unlock(&local->mtx);
e487eaeb 3045 sdata_unlock(sdata);
73da7d5b
SW
3046}
3047
37fa2bdd
MK
3048static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3049 struct cfg80211_csa_settings *params,
3050 u32 *changed)
73da7d5b 3051{
af296bdb 3052 struct ieee80211_csa_settings csa = {};
37fa2bdd 3053 int err;
73da7d5b 3054
73da7d5b
SW
3055 switch (sdata->vif.type) {
3056 case NL80211_IFTYPE_AP:
cd7760e6
SW
3057 sdata->u.ap.next_beacon =
3058 cfg80211_beacon_dup(&params->beacon_after);
3059 if (!sdata->u.ap.next_beacon)
3060 return -ENOMEM;
3061
66e01cf9
LC
3062 /*
3063 * With a count of 0, we don't have to wait for any
3064 * TBTT before switching, so complete the CSA
3065 * immediately. In theory, with a count == 1 we
3066 * should delay the switch until just before the next
3067 * TBTT, but that would complicate things so we switch
3068 * immediately too. If we would delay the switch
3069 * until the next TBTT, we would have to set the probe
3070 * response here.
3071 *
3072 * TODO: A channel switch with count <= 1 without
3073 * sending a CSA action frame is kind of useless,
3074 * because the clients won't know we're changing
3075 * channels. The action frame must be implemented
3076 * either here or in the userspace.
3077 */
3078 if (params->count <= 1)
3079 break;
3080
0d06d9ba
AO
3081 if ((params->n_counter_offsets_beacon >
3082 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
3083 (params->n_counter_offsets_presp >
3084 IEEE80211_MAX_CSA_COUNTERS_NUM))
3085 return -EINVAL;
9a774c78 3086
af296bdb
MK
3087 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3088 csa.counter_offsets_presp = params->counter_offsets_presp;
3089 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3090 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3091 csa.count = params->count;
9a774c78 3092
af296bdb 3093 err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
cd7760e6
SW
3094 if (err < 0) {
3095 kfree(sdata->u.ap.next_beacon);
3096 return err;
3097 }
37fa2bdd 3098 *changed |= err;
66e01cf9 3099
cd7760e6
SW
3100 break;
3101 case NL80211_IFTYPE_ADHOC:
3102 if (!sdata->vif.bss_conf.ibss_joined)
3103 return -EINVAL;
3104
3105 if (params->chandef.width != sdata->u.ibss.chandef.width)
3106 return -EINVAL;
3107
3108 switch (params->chandef.width) {
3109 case NL80211_CHAN_WIDTH_40:
3110 if (cfg80211_get_chandef_type(&params->chandef) !=
3111 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3112 return -EINVAL;
3113 case NL80211_CHAN_WIDTH_5:
3114 case NL80211_CHAN_WIDTH_10:
3115 case NL80211_CHAN_WIDTH_20_NOHT:
3116 case NL80211_CHAN_WIDTH_20:
3117 break;
3118 default:
3119 return -EINVAL;
3120 }
3121
3122 /* changes into another band are not supported */
3123 if (sdata->u.ibss.chandef.chan->band !=
3124 params->chandef.chan->band)
3125 return -EINVAL;
3126
66e01cf9
LC
3127 /* see comments in the NL80211_IFTYPE_AP block */
3128 if (params->count > 1) {
3129 err = ieee80211_ibss_csa_beacon(sdata, params);
3130 if (err < 0)
3131 return err;
37fa2bdd 3132 *changed |= err;
66e01cf9
LC
3133 }
3134
3135 ieee80211_send_action_csa(sdata, params);
3136
73da7d5b 3137 break;
c6da674a 3138#ifdef CONFIG_MAC80211_MESH
37fa2bdd
MK
3139 case NL80211_IFTYPE_MESH_POINT: {
3140 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
c6da674a 3141
c6da674a
CYY
3142 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3143 return -EINVAL;
3144
3145 /* changes into another band are not supported */
3146 if (sdata->vif.bss_conf.chandef.chan->band !=
3147 params->chandef.chan->band)
3148 return -EINVAL;
3149
c782bf8c 3150 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
0cb4d4dc 3151 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
c782bf8c
CYY
3152 if (!ifmsh->pre_value)
3153 ifmsh->pre_value = 1;
3154 else
3155 ifmsh->pre_value++;
3156 }
0cb4d4dc 3157
66e01cf9
LC
3158 /* see comments in the NL80211_IFTYPE_AP block */
3159 if (params->count > 1) {
3160 err = ieee80211_mesh_csa_beacon(sdata, params);
3161 if (err < 0) {
3162 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3163 return err;
3164 }
37fa2bdd 3165 *changed |= err;
3f718fd8 3166 }
66e01cf9
LC
3167
3168 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3169 ieee80211_send_action_csa(sdata, params);
3170
c6da674a 3171 break;
37fa2bdd 3172 }
c6da674a 3173#endif
73da7d5b
SW
3174 default:
3175 return -EOPNOTSUPP;
3176 }
3177
37fa2bdd
MK
3178 return 0;
3179}
3180
f29f58a9
LC
3181static int
3182__ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3183 struct cfg80211_csa_settings *params)
37fa2bdd
MK
3184{
3185 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3186 struct ieee80211_local *local = sdata->local;
6d027bcc 3187 struct ieee80211_channel_switch ch_switch;
2b32713d 3188 struct ieee80211_chanctx_conf *conf;
37fa2bdd 3189 struct ieee80211_chanctx *chanctx;
b08cc24e
JB
3190 u32 changed = 0;
3191 int err;
37fa2bdd
MK
3192
3193 sdata_assert_lock(sdata);
59af6928 3194 lockdep_assert_held(&local->mtx);
37fa2bdd
MK
3195
3196 if (!list_empty(&local->roc_list) || local->scanning)
3197 return -EBUSY;
3198
3199 if (sdata->wdev.cac_started)
3200 return -EBUSY;
3201
3202 if (cfg80211_chandef_identical(&params->chandef,
3203 &sdata->vif.bss_conf.chandef))
3204 return -EINVAL;
3205
03078de4
MK
3206 /* don't allow another channel switch if one is already active. */
3207 if (sdata->vif.csa_active)
3208 return -EBUSY;
3209
2b32713d
MK
3210 mutex_lock(&local->chanctx_mtx);
3211 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3212 lockdep_is_held(&local->chanctx_mtx));
3213 if (!conf) {
03078de4
MK
3214 err = -EBUSY;
3215 goto out;
37fa2bdd
MK
3216 }
3217
2b32713d 3218 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
03078de4
MK
3219 if (!chanctx) {
3220 err = -EBUSY;
3221 goto out;
37fa2bdd 3222 }
37fa2bdd 3223
000baa5d
LC
3224 ch_switch.timestamp = 0;
3225 ch_switch.device_timestamp = 0;
3226 ch_switch.block_tx = params->block_tx;
3227 ch_switch.chandef = params->chandef;
3228 ch_switch.count = params->count;
3229
6d027bcc
LC
3230 err = drv_pre_channel_switch(sdata, &ch_switch);
3231 if (err)
3232 goto out;
3233
03078de4
MK
3234 err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
3235 chanctx->mode,
3236 params->radar_required);
3237 if (err)
3238 goto out;
37fa2bdd 3239
03078de4
MK
3240 /* if reservation is invalid then this will fail */
3241 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3242 if (err) {
3243 ieee80211_vif_unreserve_chanctx(sdata);
3244 goto out;
3245 }
37fa2bdd
MK
3246
3247 err = ieee80211_set_csa_beacon(sdata, params, &changed);
03078de4
MK
3248 if (err) {
3249 ieee80211_vif_unreserve_chanctx(sdata);
3250 goto out;
3251 }
37fa2bdd 3252
33787fc4 3253 sdata->csa_chandef = params->chandef;
59af6928 3254 sdata->csa_block_tx = params->block_tx;
73da7d5b
SW
3255 sdata->vif.csa_active = true;
3256
59af6928 3257 if (sdata->csa_block_tx)
a46992b4
LC
3258 ieee80211_stop_vif_queues(local, sdata,
3259 IEEE80211_QUEUE_STOP_REASON_CSA);
59af6928 3260
2f457293
LC
3261 cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
3262 params->count);
3263
66e01cf9
LC
3264 if (changed) {
3265 ieee80211_bss_info_change_notify(sdata, changed);
3266 drv_channel_switch_beacon(sdata, &params->chandef);
3267 } else {
3268 /* if the beacon didn't change, we can finalize immediately */
3269 ieee80211_csa_finalize(sdata);
3270 }
73da7d5b 3271
03078de4
MK
3272out:
3273 mutex_unlock(&local->chanctx_mtx);
3274 return err;
73da7d5b
SW
3275}
3276
59af6928
MK
3277int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3278 struct cfg80211_csa_settings *params)
3279{
3280 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3281 struct ieee80211_local *local = sdata->local;
3282 int err;
3283
3284 mutex_lock(&local->mtx);
3285 err = __ieee80211_channel_switch(wiphy, dev, params);
3286 mutex_unlock(&local->mtx);
3287
3288 return err;
3289}
3290
71bbc994 3291static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
b176e629
AO
3292 struct cfg80211_mgmt_tx_params *params,
3293 u64 *cookie)
026331c4 3294{
71bbc994 3295 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
9d38d85d
JB
3296 struct ieee80211_local *local = sdata->local;
3297 struct sk_buff *skb;
3298 struct sta_info *sta;
b176e629 3299 const struct ieee80211_mgmt *mgmt = (void *)params->buf;
2eb278e0 3300 bool need_offchan = false;
e247bd90 3301 u32 flags;
2eb278e0 3302 int ret;
387910cc 3303 u8 *data;
f7ca38df 3304
b176e629 3305 if (params->dont_wait_for_ack)
e247bd90
JB
3306 flags = IEEE80211_TX_CTL_NO_ACK;
3307 else
3308 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
3309 IEEE80211_TX_CTL_REQ_TX_STATUS;
3310
b176e629 3311 if (params->no_cck)
aad14ceb
RM
3312 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
3313
9d38d85d
JB
3314 switch (sdata->vif.type) {
3315 case NL80211_IFTYPE_ADHOC:
2eb278e0
JB
3316 if (!sdata->vif.bss_conf.ibss_joined)
3317 need_offchan = true;
3318 /* fall through */
3319#ifdef CONFIG_MAC80211_MESH
3320 case NL80211_IFTYPE_MESH_POINT:
3321 if (ieee80211_vif_is_mesh(&sdata->vif) &&
3322 !sdata->u.mesh.mesh_id_len)
3323 need_offchan = true;
3324 /* fall through */
3325#endif
663fcafd
JB
3326 case NL80211_IFTYPE_AP:
3327 case NL80211_IFTYPE_AP_VLAN:
3328 case NL80211_IFTYPE_P2P_GO:
2eb278e0
JB
3329 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3330 !ieee80211_vif_is_mesh(&sdata->vif) &&
3331 !rcu_access_pointer(sdata->bss->beacon))
3332 need_offchan = true;
663fcafd 3333 if (!ieee80211_is_action(mgmt->frame_control) ||
ac49e1a8 3334 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
cd7760e6
SW
3335 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
3336 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
9d38d85d
JB
3337 break;
3338 rcu_read_lock();
3339 sta = sta_info_get(sdata, mgmt->da);
3340 rcu_read_unlock();
3341 if (!sta)
3342 return -ENOLINK;
3343 break;
3344 case NL80211_IFTYPE_STATION:
663fcafd 3345 case NL80211_IFTYPE_P2P_CLIENT:
b8e69d51
MG
3346 sdata_lock(sdata);
3347 if (!sdata->u.mgd.associated ||
3348 (params->offchan && params->wait &&
3349 local->ops->remain_on_channel &&
3350 memcmp(sdata->u.mgd.associated->bssid,
3351 mgmt->bssid, ETH_ALEN)))
2eb278e0 3352 need_offchan = true;
b8e69d51 3353 sdata_unlock(sdata);
9d38d85d 3354 break;
f142c6b9
JB
3355 case NL80211_IFTYPE_P2P_DEVICE:
3356 need_offchan = true;
3357 break;
9d38d85d
JB
3358 default:
3359 return -EOPNOTSUPP;
3360 }
3361
f7aeb6fb
AQ
3362 /* configurations requiring offchan cannot work if no channel has been
3363 * specified
3364 */
b176e629 3365 if (need_offchan && !params->chan)
f7aeb6fb
AQ
3366 return -EINVAL;
3367
2eb278e0
JB
3368 mutex_lock(&local->mtx);
3369
3370 /* Check if the operating channel is the requested channel */
3371 if (!need_offchan) {
55de908a
JB
3372 struct ieee80211_chanctx_conf *chanctx_conf;
3373
3374 rcu_read_lock();
3375 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3376
f7aeb6fb 3377 if (chanctx_conf) {
b176e629
AO
3378 need_offchan = params->chan &&
3379 (params->chan !=
3380 chanctx_conf->def.chan);
3381 } else if (!params->chan) {
f7aeb6fb
AQ
3382 ret = -EINVAL;
3383 rcu_read_unlock();
3384 goto out_unlock;
3385 } else {
2eb278e0 3386 need_offchan = true;
f7aeb6fb 3387 }
55de908a 3388 rcu_read_unlock();
2eb278e0
JB
3389 }
3390
b176e629 3391 if (need_offchan && !params->offchan) {
2eb278e0
JB
3392 ret = -EBUSY;
3393 goto out_unlock;
3394 }
3395
b176e629 3396 skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
2eb278e0
JB
3397 if (!skb) {
3398 ret = -ENOMEM;
3399 goto out_unlock;
3400 }
9d38d85d
JB
3401 skb_reserve(skb, local->hw.extra_tx_headroom);
3402
387910cc
AO
3403 data = skb_put(skb, params->len);
3404 memcpy(data, params->buf, params->len);
3405
3406 /* Update CSA counters */
3407 if (sdata->vif.csa_active &&
3408 (sdata->vif.type == NL80211_IFTYPE_AP ||
3409 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
3410 params->n_csa_offsets) {
3411 int i;
af296bdb 3412 struct beacon_data *beacon = NULL;
387910cc 3413
af296bdb
MK
3414 rcu_read_lock();
3415
3416 if (sdata->vif.type == NL80211_IFTYPE_AP)
3417 beacon = rcu_dereference(sdata->u.ap.beacon);
3418 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3419 beacon = rcu_dereference(sdata->u.ibss.presp);
3420 else if (ieee80211_vif_is_mesh(&sdata->vif))
3421 beacon = rcu_dereference(sdata->u.mesh.beacon);
3422
3423 if (beacon)
3424 for (i = 0; i < params->n_csa_offsets; i++)
3425 data[params->csa_offsets[i]] =
3426 beacon->csa_current_counter;
3427
3428 rcu_read_unlock();
387910cc 3429 }
9d38d85d
JB
3430
3431 IEEE80211_SKB_CB(skb)->flags = flags;
3432
3433 skb->dev = sdata->dev;
9d38d85d 3434
2eb278e0 3435 if (!need_offchan) {
7f9f78ab 3436 *cookie = (unsigned long) skb;
f30221e4 3437 ieee80211_tx_skb(sdata, skb);
2eb278e0
JB
3438 ret = 0;
3439 goto out_unlock;
f30221e4
JB
3440 }
3441
6c17b77b
SF
3442 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
3443 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
2eb278e0
JB
3444 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
3445 IEEE80211_SKB_CB(skb)->hw_queue =
3446 local->hw.offchannel_tx_hw_queue;
f30221e4 3447
2eb278e0 3448 /* This will handle all kinds of coalescing and immediate TX */
b176e629
AO
3449 ret = ieee80211_start_roc_work(local, sdata, params->chan,
3450 params->wait, cookie, skb,
d339d5ca 3451 IEEE80211_ROC_TYPE_MGMT_TX);
2eb278e0
JB
3452 if (ret)
3453 kfree_skb(skb);
3454 out_unlock:
3455 mutex_unlock(&local->mtx);
3456 return ret;
026331c4
JM
3457}
3458
f30221e4 3459static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
71bbc994 3460 struct wireless_dev *wdev,
f30221e4
JB
3461 u64 cookie)
3462{
71bbc994 3463 struct ieee80211_local *local = wiphy_priv(wiphy);
f30221e4 3464
2eb278e0 3465 return ieee80211_cancel_roc(local, cookie, true);
f30221e4
JB
3466}
3467
7be5086d 3468static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
71bbc994 3469 struct wireless_dev *wdev,
7be5086d
JB
3470 u16 frame_type, bool reg)
3471{
3472 struct ieee80211_local *local = wiphy_priv(wiphy);
3473
6abe0563 3474 switch (frame_type) {
6abe0563
WH
3475 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3476 if (reg)
3477 local->probe_req_reg++;
3478 else
3479 local->probe_req_reg--;
7be5086d 3480
35f5149e
FF
3481 if (!local->open_count)
3482 break;
3483
6abe0563
WH
3484 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
3485 break;
3486 default:
3487 break;
3488 }
7be5086d
JB
3489}
3490
15d96753
BR
3491static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3492{
3493 struct ieee80211_local *local = wiphy_priv(wiphy);
3494
3495 if (local->started)
3496 return -EOPNOTSUPP;
3497
3498 return drv_set_antenna(local, tx_ant, rx_ant);
3499}
3500
3501static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3502{
3503 struct ieee80211_local *local = wiphy_priv(wiphy);
3504
3505 return drv_get_antenna(local, tx_ant, rx_ant);
3506}
3507
c68f4b89
JB
3508static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3509 struct net_device *dev,
3510 struct cfg80211_gtk_rekey_data *data)
3511{
3512 struct ieee80211_local *local = wiphy_priv(wiphy);
3513 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3514
3515 if (!local->ops->set_rekey_data)
3516 return -EOPNOTSUPP;
3517
3518 drv_set_rekey_data(local, sdata, data);
3519
3520 return 0;
3521}
3522
06500736
JB
3523static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3524 const u8 *peer, u64 *cookie)
3525{
3526 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3527 struct ieee80211_local *local = sdata->local;
3528 struct ieee80211_qos_hdr *nullfunc;
3529 struct sk_buff *skb;
3530 int size = sizeof(*nullfunc);
3531 __le16 fc;
3532 bool qos;
3533 struct ieee80211_tx_info *info;
3534 struct sta_info *sta;
55de908a
JB
3535 struct ieee80211_chanctx_conf *chanctx_conf;
3536 enum ieee80211_band band;
06500736
JB
3537
3538 rcu_read_lock();
55de908a
JB
3539 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3540 if (WARN_ON(!chanctx_conf)) {
3541 rcu_read_unlock();
3542 return -EINVAL;
3543 }
4bf88530 3544 band = chanctx_conf->def.chan->band;
03bb7f42 3545 sta = sta_info_get_bss(sdata, peer);
b4487c2d 3546 if (sta) {
a74a8c84 3547 qos = sta->sta.wme;
b4487c2d
JB
3548 } else {
3549 rcu_read_unlock();
06500736 3550 return -ENOLINK;
b4487c2d 3551 }
06500736
JB
3552
3553 if (qos) {
3554 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3555 IEEE80211_STYPE_QOS_NULLFUNC |
3556 IEEE80211_FCTL_FROMDS);
3557 } else {
3558 size -= 2;
3559 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3560 IEEE80211_STYPE_NULLFUNC |
3561 IEEE80211_FCTL_FROMDS);
3562 }
3563
3564 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
55de908a
JB
3565 if (!skb) {
3566 rcu_read_unlock();
06500736 3567 return -ENOMEM;
55de908a 3568 }
06500736
JB
3569
3570 skb->dev = dev;
3571
3572 skb_reserve(skb, local->hw.extra_tx_headroom);
3573
3574 nullfunc = (void *) skb_put(skb, size);
3575 nullfunc->frame_control = fc;
3576 nullfunc->duration_id = 0;
3577 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3578 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3579 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3580 nullfunc->seq_ctrl = 0;
3581
3582 info = IEEE80211_SKB_CB(skb);
3583
3584 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3585 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
73c4e195 3586 info->band = band;
06500736
JB
3587
3588 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3589 skb->priority = 7;
3590 if (qos)
3591 nullfunc->qos_ctrl = cpu_to_le16(7);
3592
3593 local_bh_disable();
7c10770f 3594 ieee80211_xmit(sdata, sta, skb);
06500736 3595 local_bh_enable();
55de908a 3596 rcu_read_unlock();
06500736
JB
3597
3598 *cookie = (unsigned long) skb;
3599 return 0;
3600}
3601
683b6d3b
JB
3602static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3603 struct wireless_dev *wdev,
3604 struct cfg80211_chan_def *chandef)
5b7ccaf3 3605{
55de908a 3606 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
cb601ffa 3607 struct ieee80211_local *local = wiphy_priv(wiphy);
55de908a 3608 struct ieee80211_chanctx_conf *chanctx_conf;
683b6d3b 3609 int ret = -ENODATA;
55de908a
JB
3610
3611 rcu_read_lock();
feda3027
JB
3612 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3613 if (chanctx_conf) {
c12bc488 3614 *chandef = sdata->vif.bss_conf.chandef;
feda3027
JB
3615 ret = 0;
3616 } else if (local->open_count > 0 &&
3617 local->open_count == local->monitors &&
3618 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3619 if (local->use_chanctx)
3620 *chandef = local->monitor_chandef;
3621 else
675a0b04 3622 *chandef = local->_oper_chandef;
683b6d3b 3623 ret = 0;
55de908a
JB
3624 }
3625 rcu_read_unlock();
5b7ccaf3 3626
683b6d3b 3627 return ret;
5b7ccaf3
JB
3628}
3629
6d52563f
JB
3630#ifdef CONFIG_PM
3631static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3632{
3633 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3634}
3635#endif
3636
32db6b54
KP
3637static int ieee80211_set_qos_map(struct wiphy *wiphy,
3638 struct net_device *dev,
3639 struct cfg80211_qos_map *qos_map)
3640{
3641 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3642 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3643
3644 if (qos_map) {
3645 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3646 if (!new_qos_map)
3647 return -ENOMEM;
3648 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3649 } else {
3650 /* A NULL qos_map was passed to disable QoS mapping */
3651 new_qos_map = NULL;
3652 }
3653
194ff52d 3654 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
32db6b54
KP
3655 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3656 if (old_qos_map)
3657 kfree_rcu(old_qos_map, rcu_head);
3658
3659 return 0;
3660}
3661
3b1700bd
JM
3662static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3663 struct net_device *dev,
3664 struct cfg80211_chan_def *chandef)
3665{
3666 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3667 int ret;
3668 u32 changed = 0;
3669
3670 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3671 if (ret == 0)
3672 ieee80211_bss_info_change_notify(sdata, changed);
3673
3674 return ret;
3675}
3676
02219b3a
JB
3677static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3678 u8 tsid, const u8 *peer, u8 up,
3679 u16 admitted_time)
3680{
3681 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3682 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3683 int ac = ieee802_1d_to_ac[up];
3684
3685 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3686 return -EOPNOTSUPP;
3687
3688 if (!(sdata->wmm_acm & BIT(up)))
3689 return -EINVAL;
3690
3691 if (ifmgd->tx_tspec[ac].admitted_time)
3692 return -EBUSY;
3693
3694 if (admitted_time) {
3695 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3696 ifmgd->tx_tspec[ac].tsid = tsid;
3697 ifmgd->tx_tspec[ac].up = up;
3698 }
3699
3700 return 0;
3701}
3702
3703static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3704 u8 tsid, const u8 *peer)
3705{
3706 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3707 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3708 struct ieee80211_local *local = wiphy_priv(wiphy);
3709 int ac;
3710
3711 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3712 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3713
3714 /* skip unused entries */
3715 if (!tx_tspec->admitted_time)
3716 continue;
3717
3718 if (tx_tspec->tsid != tsid)
3719 continue;
3720
3721 /* due to this new packets will be reassigned to non-ACM ACs */
3722 tx_tspec->up = -1;
3723
3724 /* Make sure that all packets have been sent to avoid to
3725 * restore the QoS params on packets that are still on the
3726 * queues.
3727 */
3728 synchronize_net();
3b24f4c6 3729 ieee80211_flush_queues(local, sdata, false);
02219b3a
JB
3730
3731 /* restore the normal QoS parameters
3732 * (unconditionally to avoid races)
3733 */
3734 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3735 tx_tspec->downgraded = false;
3736 ieee80211_sta_handle_tspec_ac_params(sdata);
3737
3738 /* finally clear all the data */
3739 memset(tx_tspec, 0, sizeof(*tx_tspec));
3740
3741 return 0;
3742 }
3743
3744 return -ENOENT;
3745}
3746
8a47cea7 3747const struct cfg80211_ops mac80211_config_ops = {
f0706e82
JB
3748 .add_virtual_intf = ieee80211_add_iface,
3749 .del_virtual_intf = ieee80211_del_iface,
42613db7 3750 .change_virtual_intf = ieee80211_change_iface,
f142c6b9
JB
3751 .start_p2p_device = ieee80211_start_p2p_device,
3752 .stop_p2p_device = ieee80211_stop_p2p_device,
e8cbb4cb
JB
3753 .add_key = ieee80211_add_key,
3754 .del_key = ieee80211_del_key,
62da92fb 3755 .get_key = ieee80211_get_key,
e8cbb4cb 3756 .set_default_key = ieee80211_config_default_key,
3cfcf6ac 3757 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
8860020e
JB
3758 .start_ap = ieee80211_start_ap,
3759 .change_beacon = ieee80211_change_beacon,
3760 .stop_ap = ieee80211_stop_ap,
4fd6931e
JB
3761 .add_station = ieee80211_add_station,
3762 .del_station = ieee80211_del_station,
3763 .change_station = ieee80211_change_station,
7bbdd2d9 3764 .get_station = ieee80211_get_station,
c5dd9c2b 3765 .dump_station = ieee80211_dump_station,
1289723e 3766 .dump_survey = ieee80211_dump_survey,
c5dd9c2b
LCC
3767#ifdef CONFIG_MAC80211_MESH
3768 .add_mpath = ieee80211_add_mpath,
3769 .del_mpath = ieee80211_del_mpath,
3770 .change_mpath = ieee80211_change_mpath,
3771 .get_mpath = ieee80211_get_mpath,
3772 .dump_mpath = ieee80211_dump_mpath,
a2db2ed3
HR
3773 .get_mpp = ieee80211_get_mpp,
3774 .dump_mpp = ieee80211_dump_mpp,
24bdd9f4
JC
3775 .update_mesh_config = ieee80211_update_mesh_config,
3776 .get_mesh_config = ieee80211_get_mesh_config,
29cbe68c
JB
3777 .join_mesh = ieee80211_join_mesh,
3778 .leave_mesh = ieee80211_leave_mesh,
c5dd9c2b 3779#endif
239281f8
RL
3780 .join_ocb = ieee80211_join_ocb,
3781 .leave_ocb = ieee80211_leave_ocb,
9f1ba906 3782 .change_bss = ieee80211_change_bss,
31888487 3783 .set_txq_params = ieee80211_set_txq_params,
e8c9bd5b 3784 .set_monitor_channel = ieee80211_set_monitor_channel,
665af4fc
BC
3785 .suspend = ieee80211_suspend,
3786 .resume = ieee80211_resume,
2a519311 3787 .scan = ieee80211_scan,
79f460ca
LC
3788 .sched_scan_start = ieee80211_sched_scan_start,
3789 .sched_scan_stop = ieee80211_sched_scan_stop,
636a5d36
JM
3790 .auth = ieee80211_auth,
3791 .assoc = ieee80211_assoc,
3792 .deauth = ieee80211_deauth,
3793 .disassoc = ieee80211_disassoc,
af8cdcd8
JB
3794 .join_ibss = ieee80211_join_ibss,
3795 .leave_ibss = ieee80211_leave_ibss,
391e53e3 3796 .set_mcast_rate = ieee80211_set_mcast_rate,
b9a5f8ca 3797 .set_wiphy_params = ieee80211_set_wiphy_params,
7643a2c3
JB
3798 .set_tx_power = ieee80211_set_tx_power,
3799 .get_tx_power = ieee80211_get_tx_power,
ab737a4f 3800 .set_wds_peer = ieee80211_set_wds_peer,
1f87f7d3 3801 .rfkill_poll = ieee80211_rfkill_poll,
aff89a9b 3802 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
71063f0e 3803 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
bc92afd9 3804 .set_power_mgmt = ieee80211_set_power_mgmt,
9930380f 3805 .set_bitrate_mask = ieee80211_set_bitrate_mask,
b8bc4b0a
JB
3806 .remain_on_channel = ieee80211_remain_on_channel,
3807 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
2e161f78 3808 .mgmt_tx = ieee80211_mgmt_tx,
f30221e4 3809 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
a97c13c3 3810 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
7be5086d 3811 .mgmt_frame_register = ieee80211_mgmt_frame_register,
15d96753
BR
3812 .set_antenna = ieee80211_set_antenna,
3813 .get_antenna = ieee80211_get_antenna,
c68f4b89 3814 .set_rekey_data = ieee80211_set_rekey_data,
dfe018bf
AN
3815 .tdls_oper = ieee80211_tdls_oper,
3816 .tdls_mgmt = ieee80211_tdls_mgmt,
a7a6bdd0
AN
3817 .tdls_channel_switch = ieee80211_tdls_channel_switch,
3818 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
06500736 3819 .probe_client = ieee80211_probe_client,
b53be792 3820 .set_noack_map = ieee80211_set_noack_map,
6d52563f
JB
3821#ifdef CONFIG_PM
3822 .set_wakeup = ieee80211_set_wakeup,
3823#endif
5b7ccaf3 3824 .get_channel = ieee80211_cfg_get_channel,
164eb02d 3825 .start_radar_detection = ieee80211_start_radar_detection,
73da7d5b 3826 .channel_switch = ieee80211_channel_switch,
32db6b54 3827 .set_qos_map = ieee80211_set_qos_map,
3b1700bd 3828 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
02219b3a
JB
3829 .add_tx_ts = ieee80211_add_tx_ts,
3830 .del_tx_ts = ieee80211_del_tx_ts,
f0706e82 3831};