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