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