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