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