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