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