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