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