nl80211: refactor mesh parameter parsing
[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>
f0706e82
JB
15#include <net/cfg80211.h>
16#include "ieee80211_i.h"
24487981 17#include "driver-ops.h"
e0eb6859 18#include "cfg.h"
2c8dccc7 19#include "rate.h"
c5dd9c2b 20#include "mesh.h"
c5dd9c2b 21
f9e10ce4
JB
22static struct net_device *ieee80211_add_iface(struct wiphy *wiphy, char *name,
23 enum nl80211_iftype type,
24 u32 *flags,
25 struct vif_params *params)
f0706e82
JB
26{
27 struct ieee80211_local *local = wiphy_priv(wiphy);
8cc9a739
MW
28 struct net_device *dev;
29 struct ieee80211_sub_if_data *sdata;
30 int err;
f0706e82 31
05c914fe 32 err = ieee80211_if_add(local, name, &dev, type, params);
f9e10ce4
JB
33 if (err)
34 return ERR_PTR(err);
8cc9a739 35
f9e10ce4
JB
36 if (type == NL80211_IFTYPE_MONITOR && flags) {
37 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
38 sdata->u.mntr_flags = *flags;
39 }
40
41 return dev;
f0706e82
JB
42}
43
463d0183 44static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
f0706e82 45{
463d0183 46 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
f0706e82 47
75636525 48 return 0;
f0706e82
JB
49}
50
e36d56b6
JB
51static int ieee80211_change_iface(struct wiphy *wiphy,
52 struct net_device *dev,
2ec600d6
LCC
53 enum nl80211_iftype type, u32 *flags,
54 struct vif_params *params)
42613db7 55{
9607e6b6 56 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
f3947e2d 57 int ret;
42613db7 58
05c914fe 59 ret = ieee80211_if_change_type(sdata, type);
f3947e2d
JB
60 if (ret)
61 return ret;
42613db7 62
902acc78 63 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
472dbc45
JB
64 ieee80211_sdata_set_mesh_id(sdata,
65 params->mesh_id_len,
66 params->mesh_id);
c5dd9c2b 67
9bc383de
JB
68 if (type == NL80211_IFTYPE_AP_VLAN &&
69 params && params->use_4addr == 0)
70 rcu_assign_pointer(sdata->u.vlan.sta, NULL);
71 else if (type == NL80211_IFTYPE_STATION &&
72 params && params->use_4addr >= 0)
73 sdata->u.mgd.use_4addr = params->use_4addr;
74
85416a4f
CL
75 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
76 struct ieee80211_local *local = sdata->local;
77
78 if (ieee80211_sdata_running(sdata)) {
79 /*
80 * Prohibit MONITOR_FLAG_COOK_FRAMES to be
81 * changed while the interface is up.
82 * Else we would need to add a lot of cruft
83 * to update everything:
84 * cooked_mntrs, monitor and all fif_* counters
85 * reconfigure hardware
86 */
87 if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
88 (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
89 return -EBUSY;
90
91 ieee80211_adjust_monitor_flags(sdata, -1);
92 sdata->u.mntr_flags = *flags;
93 ieee80211_adjust_monitor_flags(sdata, 1);
94
95 ieee80211_configure_filter(local);
96 } else {
97 /*
98 * Because the interface is down, ieee80211_do_stop
99 * and ieee80211_do_open take care of "everything"
100 * mentioned in the comment above.
101 */
102 sdata->u.mntr_flags = *flags;
103 }
104 }
f7917af9 105
42613db7
JB
106 return 0;
107}
108
e8cbb4cb 109static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
e31b8213 110 u8 key_idx, bool pairwise, const u8 *mac_addr,
e8cbb4cb
JB
111 struct key_params *params)
112{
26a58456 113 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
e8cbb4cb 114 struct sta_info *sta = NULL;
db4d1169 115 struct ieee80211_key *key;
3b96766f 116 int err;
e8cbb4cb 117
26a58456 118 if (!ieee80211_sdata_running(sdata))
ad0e2b5a
JB
119 return -ENETDOWN;
120
97359d12 121 /* reject WEP and TKIP keys if WEP failed to initialize */
e8cbb4cb
JB
122 switch (params->cipher) {
123 case WLAN_CIPHER_SUITE_WEP40:
e8cbb4cb 124 case WLAN_CIPHER_SUITE_TKIP:
97359d12
JB
125 case WLAN_CIPHER_SUITE_WEP104:
126 if (IS_ERR(sdata->local->wep_tx_tfm))
127 return -EINVAL;
3cfcf6ac 128 break;
e8cbb4cb 129 default:
97359d12 130 break;
e8cbb4cb
JB
131 }
132
97359d12
JB
133 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
134 params->key, params->seq_len, params->seq);
1ac62ba7
BH
135 if (IS_ERR(key))
136 return PTR_ERR(key);
db4d1169 137
e31b8213
JB
138 if (pairwise)
139 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
140
ad0e2b5a 141 mutex_lock(&sdata->local->sta_mtx);
3b96766f 142
e8cbb4cb 143 if (mac_addr) {
0e5ded5a 144 sta = sta_info_get_bss(sdata, mac_addr);
db4d1169 145 if (!sta) {
32162a4d 146 ieee80211_key_free(sdata->local, key);
3b96766f
JB
147 err = -ENOENT;
148 goto out_unlock;
db4d1169 149 }
e8cbb4cb
JB
150 }
151
3ffc2a90
JB
152 err = ieee80211_key_link(key, sdata, sta);
153 if (err)
154 ieee80211_key_free(sdata->local, key);
db4d1169 155
3b96766f 156 out_unlock:
ad0e2b5a 157 mutex_unlock(&sdata->local->sta_mtx);
3b96766f
JB
158
159 return err;
e8cbb4cb
JB
160}
161
162static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
e31b8213 163 u8 key_idx, bool pairwise, const u8 *mac_addr)
e8cbb4cb
JB
164{
165 struct ieee80211_sub_if_data *sdata;
166 struct sta_info *sta;
167 int ret;
168
169 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
170
ad0e2b5a 171 mutex_lock(&sdata->local->sta_mtx);
3b96766f 172
e8cbb4cb 173 if (mac_addr) {
3b96766f
JB
174 ret = -ENOENT;
175
0e5ded5a 176 sta = sta_info_get_bss(sdata, mac_addr);
e8cbb4cb 177 if (!sta)
3b96766f 178 goto out_unlock;
e8cbb4cb 179
e31b8213
JB
180 if (pairwise) {
181 if (sta->ptk) {
182 ieee80211_key_free(sdata->local, sta->ptk);
183 ret = 0;
184 }
185 } else {
186 if (sta->gtk[key_idx]) {
187 ieee80211_key_free(sdata->local,
188 sta->gtk[key_idx]);
189 ret = 0;
190 }
3b96766f 191 }
e8cbb4cb 192
3b96766f 193 goto out_unlock;
e8cbb4cb
JB
194 }
195
3b96766f
JB
196 if (!sdata->keys[key_idx]) {
197 ret = -ENOENT;
198 goto out_unlock;
199 }
e8cbb4cb 200
32162a4d 201 ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
db4d1169 202 WARN_ON(sdata->keys[key_idx]);
e8cbb4cb 203
3b96766f
JB
204 ret = 0;
205 out_unlock:
ad0e2b5a 206 mutex_unlock(&sdata->local->sta_mtx);
3b96766f
JB
207
208 return ret;
e8cbb4cb
JB
209}
210
62da92fb 211static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
e31b8213
JB
212 u8 key_idx, bool pairwise, const u8 *mac_addr,
213 void *cookie,
62da92fb
JB
214 void (*callback)(void *cookie,
215 struct key_params *params))
216{
14db74bc 217 struct ieee80211_sub_if_data *sdata;
62da92fb
JB
218 struct sta_info *sta = NULL;
219 u8 seq[6] = {0};
220 struct key_params params;
e31b8213 221 struct ieee80211_key *key = NULL;
62da92fb
JB
222 u32 iv32;
223 u16 iv16;
224 int err = -ENOENT;
225
14db74bc
JB
226 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
227
3b96766f
JB
228 rcu_read_lock();
229
62da92fb 230 if (mac_addr) {
0e5ded5a 231 sta = sta_info_get_bss(sdata, mac_addr);
62da92fb
JB
232 if (!sta)
233 goto out;
234
e31b8213
JB
235 if (pairwise)
236 key = sta->ptk;
237 else if (key_idx < NUM_DEFAULT_KEYS)
238 key = sta->gtk[key_idx];
62da92fb
JB
239 } else
240 key = sdata->keys[key_idx];
241
242 if (!key)
243 goto out;
244
245 memset(&params, 0, sizeof(params));
246
97359d12 247 params.cipher = key->conf.cipher;
62da92fb 248
97359d12
JB
249 switch (key->conf.cipher) {
250 case WLAN_CIPHER_SUITE_TKIP:
b0f76b33
HH
251 iv32 = key->u.tkip.tx.iv32;
252 iv16 = key->u.tkip.tx.iv16;
62da92fb 253
24487981
JB
254 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
255 drv_get_tkip_seq(sdata->local,
256 key->conf.hw_key_idx,
257 &iv32, &iv16);
62da92fb
JB
258
259 seq[0] = iv16 & 0xff;
260 seq[1] = (iv16 >> 8) & 0xff;
261 seq[2] = iv32 & 0xff;
262 seq[3] = (iv32 >> 8) & 0xff;
263 seq[4] = (iv32 >> 16) & 0xff;
264 seq[5] = (iv32 >> 24) & 0xff;
265 params.seq = seq;
266 params.seq_len = 6;
267 break;
97359d12 268 case WLAN_CIPHER_SUITE_CCMP:
62da92fb
JB
269 seq[0] = key->u.ccmp.tx_pn[5];
270 seq[1] = key->u.ccmp.tx_pn[4];
271 seq[2] = key->u.ccmp.tx_pn[3];
272 seq[3] = key->u.ccmp.tx_pn[2];
273 seq[4] = key->u.ccmp.tx_pn[1];
274 seq[5] = key->u.ccmp.tx_pn[0];
275 params.seq = seq;
276 params.seq_len = 6;
277 break;
97359d12 278 case WLAN_CIPHER_SUITE_AES_CMAC:
3cfcf6ac
JM
279 seq[0] = key->u.aes_cmac.tx_pn[5];
280 seq[1] = key->u.aes_cmac.tx_pn[4];
281 seq[2] = key->u.aes_cmac.tx_pn[3];
282 seq[3] = key->u.aes_cmac.tx_pn[2];
283 seq[4] = key->u.aes_cmac.tx_pn[1];
284 seq[5] = key->u.aes_cmac.tx_pn[0];
285 params.seq = seq;
286 params.seq_len = 6;
287 break;
62da92fb
JB
288 }
289
290 params.key = key->conf.key;
291 params.key_len = key->conf.keylen;
292
293 callback(cookie, &params);
294 err = 0;
295
296 out:
3b96766f 297 rcu_read_unlock();
62da92fb
JB
298 return err;
299}
300
e8cbb4cb
JB
301static int ieee80211_config_default_key(struct wiphy *wiphy,
302 struct net_device *dev,
303 u8 key_idx)
304{
ad0e2b5a 305 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3b96766f 306
e8cbb4cb
JB
307 ieee80211_set_default_key(sdata, key_idx);
308
309 return 0;
310}
311
3cfcf6ac
JM
312static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
313 struct net_device *dev,
314 u8 key_idx)
315{
66c52421 316 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3cfcf6ac 317
3cfcf6ac
JM
318 ieee80211_set_default_mgmt_key(sdata, key_idx);
319
3cfcf6ac
JM
320 return 0;
321}
322
c5dd9c2b
LCC
323static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
324{
d0709a65 325 struct ieee80211_sub_if_data *sdata = sta->sdata;
c5dd9c2b 326
f5ea9120
JB
327 sinfo->generation = sdata->local->sta_generation;
328
c5dd9c2b
LCC
329 sinfo->filled = STATION_INFO_INACTIVE_TIME |
330 STATION_INFO_RX_BYTES |
420e7fab 331 STATION_INFO_TX_BYTES |
98c8a60a
JM
332 STATION_INFO_RX_PACKETS |
333 STATION_INFO_TX_PACKETS |
b206b4ef
BR
334 STATION_INFO_TX_RETRIES |
335 STATION_INFO_TX_FAILED |
5a5c731a
BG
336 STATION_INFO_TX_BITRATE |
337 STATION_INFO_RX_DROP_MISC;
c5dd9c2b
LCC
338
339 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
340 sinfo->rx_bytes = sta->rx_bytes;
341 sinfo->tx_bytes = sta->tx_bytes;
98c8a60a
JM
342 sinfo->rx_packets = sta->rx_packets;
343 sinfo->tx_packets = sta->tx_packets;
b206b4ef
BR
344 sinfo->tx_retries = sta->tx_retry_count;
345 sinfo->tx_failed = sta->tx_retry_failed;
5a5c731a 346 sinfo->rx_dropped_misc = sta->rx_dropped;
c5dd9c2b 347
19deffbe
JL
348 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
349 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
ccb14354 350 sinfo->filled |= STATION_INFO_SIGNAL;
420e7fab
HR
351 sinfo->signal = (s8)sta->last_signal;
352 }
353
354 sinfo->txrate.flags = 0;
355 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
356 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
357 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
358 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
359 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
360 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
361
362 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
363 struct ieee80211_supported_band *sband;
364 sband = sta->local->hw.wiphy->bands[
365 sta->local->hw.conf.channel->band];
366 sinfo->txrate.legacy =
367 sband->bitrates[sta->last_tx_rate.idx].bitrate;
368 } else
369 sinfo->txrate.mcs = sta->last_tx_rate.idx;
370
902acc78 371 if (ieee80211_vif_is_mesh(&sdata->vif)) {
c5dd9c2b 372#ifdef CONFIG_MAC80211_MESH
c5dd9c2b
LCC
373 sinfo->filled |= STATION_INFO_LLID |
374 STATION_INFO_PLID |
375 STATION_INFO_PLINK_STATE;
376
377 sinfo->llid = le16_to_cpu(sta->llid);
378 sinfo->plid = le16_to_cpu(sta->plid);
379 sinfo->plink_state = sta->plink_state;
c5dd9c2b 380#endif
902acc78 381 }
c5dd9c2b
LCC
382}
383
384
385static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
386 int idx, u8 *mac, struct station_info *sinfo)
387{
3b53fde8 388 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
c5dd9c2b 389 struct sta_info *sta;
d0709a65
JB
390 int ret = -ENOENT;
391
392 rcu_read_lock();
c5dd9c2b 393
3b53fde8 394 sta = sta_info_get_by_idx(sdata, idx);
d0709a65
JB
395 if (sta) {
396 ret = 0;
17741cdc 397 memcpy(mac, sta->sta.addr, ETH_ALEN);
d0709a65
JB
398 sta_set_sinfo(sta, sinfo);
399 }
c5dd9c2b 400
d0709a65 401 rcu_read_unlock();
c5dd9c2b 402
d0709a65 403 return ret;
c5dd9c2b
LCC
404}
405
1289723e
HS
406static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
407 int idx, struct survey_info *survey)
408{
409 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
410
1289723e
HS
411 return drv_get_survey(local, idx, survey);
412}
413
7bbdd2d9 414static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
2ec600d6 415 u8 *mac, struct station_info *sinfo)
7bbdd2d9 416{
abe60632 417 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
7bbdd2d9 418 struct sta_info *sta;
d0709a65 419 int ret = -ENOENT;
7bbdd2d9 420
d0709a65 421 rcu_read_lock();
7bbdd2d9 422
0e5ded5a 423 sta = sta_info_get_bss(sdata, mac);
d0709a65
JB
424 if (sta) {
425 ret = 0;
426 sta_set_sinfo(sta, sinfo);
427 }
428
429 rcu_read_unlock();
430
431 return ret;
7bbdd2d9
JB
432}
433
5dfdaf58
JB
434/*
435 * This handles both adding a beacon and setting new beacon info
436 */
437static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
438 struct beacon_parameters *params)
439{
440 struct beacon_data *new, *old;
441 int new_head_len, new_tail_len;
442 int size;
443 int err = -EINVAL;
444
445 old = sdata->u.ap.beacon;
446
447 /* head must not be zero-length */
448 if (params->head && !params->head_len)
449 return -EINVAL;
450
451 /*
452 * This is a kludge. beacon interval should really be part
453 * of the beacon information.
454 */
57c4d7b4
JB
455 if (params->interval &&
456 (sdata->vif.bss_conf.beacon_int != params->interval)) {
457 sdata->vif.bss_conf.beacon_int = params->interval;
458 ieee80211_bss_info_change_notify(sdata,
459 BSS_CHANGED_BEACON_INT);
5dfdaf58
JB
460 }
461
462 /* Need to have a beacon head if we don't have one yet */
463 if (!params->head && !old)
464 return err;
465
466 /* sorry, no way to start beaconing without dtim period */
467 if (!params->dtim_period && !old)
468 return err;
469
470 /* new or old head? */
471 if (params->head)
472 new_head_len = params->head_len;
473 else
474 new_head_len = old->head_len;
475
476 /* new or old tail? */
477 if (params->tail || !old)
478 /* params->tail_len will be zero for !params->tail */
479 new_tail_len = params->tail_len;
480 else
481 new_tail_len = old->tail_len;
482
483 size = sizeof(*new) + new_head_len + new_tail_len;
484
485 new = kzalloc(size, GFP_KERNEL);
486 if (!new)
487 return -ENOMEM;
488
489 /* start filling the new info now */
490
491 /* new or old dtim period? */
492 if (params->dtim_period)
493 new->dtim_period = params->dtim_period;
494 else
495 new->dtim_period = old->dtim_period;
496
497 /*
498 * pointers go into the block we allocated,
499 * memory is | beacon_data | head | tail |
500 */
501 new->head = ((u8 *) new) + sizeof(*new);
502 new->tail = new->head + new_head_len;
503 new->head_len = new_head_len;
504 new->tail_len = new_tail_len;
505
506 /* copy in head */
507 if (params->head)
508 memcpy(new->head, params->head, new_head_len);
509 else
510 memcpy(new->head, old->head, new_head_len);
511
512 /* copy in optional tail */
513 if (params->tail)
514 memcpy(new->tail, params->tail, new_tail_len);
515 else
516 if (old)
517 memcpy(new->tail, old->tail, new_tail_len);
518
19885c4f
JB
519 sdata->vif.bss_conf.dtim_period = new->dtim_period;
520
5dfdaf58
JB
521 rcu_assign_pointer(sdata->u.ap.beacon, new);
522
523 synchronize_rcu();
524
525 kfree(old);
526
2d0ddec5
JB
527 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
528 BSS_CHANGED_BEACON);
529 return 0;
5dfdaf58
JB
530}
531
532static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
533 struct beacon_parameters *params)
534{
14db74bc 535 struct ieee80211_sub_if_data *sdata;
5dfdaf58
JB
536 struct beacon_data *old;
537
14db74bc
JB
538 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
539
5dfdaf58
JB
540 old = sdata->u.ap.beacon;
541
542 if (old)
543 return -EALREADY;
544
545 return ieee80211_config_beacon(sdata, params);
546}
547
548static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
549 struct beacon_parameters *params)
550{
14db74bc 551 struct ieee80211_sub_if_data *sdata;
5dfdaf58
JB
552 struct beacon_data *old;
553
14db74bc
JB
554 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
555
5dfdaf58
JB
556 old = sdata->u.ap.beacon;
557
558 if (!old)
559 return -ENOENT;
560
561 return ieee80211_config_beacon(sdata, params);
562}
563
564static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
565{
14db74bc 566 struct ieee80211_sub_if_data *sdata;
5dfdaf58
JB
567 struct beacon_data *old;
568
14db74bc
JB
569 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
570
5dfdaf58
JB
571 old = sdata->u.ap.beacon;
572
573 if (!old)
574 return -ENOENT;
575
576 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
577 synchronize_rcu();
578 kfree(old);
579
2d0ddec5
JB
580 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
581 return 0;
5dfdaf58
JB
582}
583
4fd6931e
JB
584/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
585struct iapp_layer2_update {
586 u8 da[ETH_ALEN]; /* broadcast */
587 u8 sa[ETH_ALEN]; /* STA addr */
588 __be16 len; /* 6 */
589 u8 dsap; /* 0 */
590 u8 ssap; /* 0 */
591 u8 control;
592 u8 xid_info[3];
bc10502d 593} __packed;
4fd6931e
JB
594
595static void ieee80211_send_layer2_update(struct sta_info *sta)
596{
597 struct iapp_layer2_update *msg;
598 struct sk_buff *skb;
599
600 /* Send Level 2 Update Frame to update forwarding tables in layer 2
601 * bridge devices */
602
603 skb = dev_alloc_skb(sizeof(*msg));
604 if (!skb)
605 return;
606 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
607
608 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
609 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
610
611 memset(msg->da, 0xff, ETH_ALEN);
17741cdc 612 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
4fd6931e
JB
613 msg->len = htons(6);
614 msg->dsap = 0;
615 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
616 msg->control = 0xaf; /* XID response lsb.1111F101.
617 * F=0 (no poll command; unsolicited frame) */
618 msg->xid_info[0] = 0x81; /* XID format identifier */
619 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
620 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
621
d0709a65
JB
622 skb->dev = sta->sdata->dev;
623 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
4fd6931e 624 memset(skb->cb, 0, sizeof(skb->cb));
06ee1c26 625 netif_rx_ni(skb);
4fd6931e
JB
626}
627
628static void sta_apply_parameters(struct ieee80211_local *local,
629 struct sta_info *sta,
630 struct station_parameters *params)
631{
f5521b13 632 unsigned long flags;
4fd6931e
JB
633 u32 rates;
634 int i, j;
8318d78a 635 struct ieee80211_supported_band *sband;
d0709a65 636 struct ieee80211_sub_if_data *sdata = sta->sdata;
eccb8e8f 637 u32 mask, set;
4fd6931e 638
ae5eb026
JB
639 sband = local->hw.wiphy->bands[local->oper_channel->band];
640
f5521b13 641 spin_lock_irqsave(&sta->flaglock, flags);
eccb8e8f
JB
642 mask = params->sta_flags_mask;
643 set = params->sta_flags_set;
73651ee6 644
eccb8e8f 645 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
4fd6931e 646 sta->flags &= ~WLAN_STA_AUTHORIZED;
eccb8e8f 647 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
4fd6931e 648 sta->flags |= WLAN_STA_AUTHORIZED;
eccb8e8f 649 }
4fd6931e 650
eccb8e8f 651 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
4fd6931e 652 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
eccb8e8f 653 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
4fd6931e 654 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
eccb8e8f 655 }
4fd6931e 656
eccb8e8f 657 if (mask & BIT(NL80211_STA_FLAG_WME)) {
4fd6931e 658 sta->flags &= ~WLAN_STA_WME;
eccb8e8f 659 if (set & BIT(NL80211_STA_FLAG_WME))
4fd6931e 660 sta->flags |= WLAN_STA_WME;
eccb8e8f 661 }
5394af4d 662
eccb8e8f 663 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
5394af4d 664 sta->flags &= ~WLAN_STA_MFP;
eccb8e8f 665 if (set & BIT(NL80211_STA_FLAG_MFP))
5394af4d 666 sta->flags |= WLAN_STA_MFP;
4fd6931e 667 }
f5521b13 668 spin_unlock_irqrestore(&sta->flaglock, flags);
4fd6931e 669
51b50fbe
JB
670 /*
671 * cfg80211 validates this (1-2007) and allows setting the AID
672 * only when creating a new station entry
673 */
674 if (params->aid)
675 sta->sta.aid = params->aid;
676
73651ee6
JB
677 /*
678 * FIXME: updating the following information is racy when this
679 * function is called from ieee80211_change_station().
680 * However, all this information should be static so
681 * maybe we should just reject attemps to change it.
682 */
683
4fd6931e
JB
684 if (params->listen_interval >= 0)
685 sta->listen_interval = params->listen_interval;
686
687 if (params->supported_rates) {
688 rates = 0;
8318d78a 689
4fd6931e
JB
690 for (i = 0; i < params->supported_rates_len; i++) {
691 int rate = (params->supported_rates[i] & 0x7f) * 5;
8318d78a
JB
692 for (j = 0; j < sband->n_bitrates; j++) {
693 if (sband->bitrates[j].bitrate == rate)
4fd6931e
JB
694 rates |= BIT(j);
695 }
696 }
323ce79a 697 sta->sta.supp_rates[local->oper_channel->band] = rates;
4fd6931e 698 }
c5dd9c2b 699
d9fe60de 700 if (params->ht_capa)
ae5eb026
JB
701 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
702 params->ht_capa,
d9fe60de 703 &sta->sta.ht_cap);
36aedc90 704
902acc78 705 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
c5dd9c2b
LCC
706 switch (params->plink_action) {
707 case PLINK_ACTION_OPEN:
708 mesh_plink_open(sta);
709 break;
710 case PLINK_ACTION_BLOCK:
711 mesh_plink_block(sta);
712 break;
713 }
902acc78 714 }
4fd6931e
JB
715}
716
717static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
718 u8 *mac, struct station_parameters *params)
719{
14db74bc 720 struct ieee80211_local *local = wiphy_priv(wiphy);
4fd6931e
JB
721 struct sta_info *sta;
722 struct ieee80211_sub_if_data *sdata;
73651ee6 723 int err;
b8d476c8 724 int layer2_update;
4fd6931e 725
4fd6931e
JB
726 if (params->vlan) {
727 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
728
05c914fe
JB
729 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
730 sdata->vif.type != NL80211_IFTYPE_AP)
4fd6931e
JB
731 return -EINVAL;
732 } else
733 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
734
47846c9b 735 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
03e4497e
JB
736 return -EINVAL;
737
738 if (is_multicast_ether_addr(mac))
739 return -EINVAL;
740
741 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
73651ee6
JB
742 if (!sta)
743 return -ENOMEM;
4fd6931e
JB
744
745 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
746
747 sta_apply_parameters(local, sta, params);
748
4b7679a5 749 rate_control_rate_init(sta);
4fd6931e 750
b8d476c8
JM
751 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
752 sdata->vif.type == NL80211_IFTYPE_AP;
753
34e89507 754 err = sta_info_insert_rcu(sta);
73651ee6 755 if (err) {
73651ee6
JB
756 rcu_read_unlock();
757 return err;
758 }
759
b8d476c8 760 if (layer2_update)
73651ee6
JB
761 ieee80211_send_layer2_update(sta);
762
763 rcu_read_unlock();
764
4fd6931e
JB
765 return 0;
766}
767
768static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
769 u8 *mac)
770{
14db74bc
JB
771 struct ieee80211_local *local = wiphy_priv(wiphy);
772 struct ieee80211_sub_if_data *sdata;
4fd6931e 773
14db74bc
JB
774 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
775
34e89507
JB
776 if (mac)
777 return sta_info_destroy_addr_bss(sdata, mac);
4fd6931e 778
34e89507 779 sta_info_flush(local, sdata);
4fd6931e
JB
780 return 0;
781}
782
783static int ieee80211_change_station(struct wiphy *wiphy,
784 struct net_device *dev,
785 u8 *mac,
786 struct station_parameters *params)
787{
abe60632 788 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
14db74bc 789 struct ieee80211_local *local = wiphy_priv(wiphy);
4fd6931e
JB
790 struct sta_info *sta;
791 struct ieee80211_sub_if_data *vlansdata;
792
98dd6a57
JB
793 rcu_read_lock();
794
0e5ded5a 795 sta = sta_info_get_bss(sdata, mac);
98dd6a57
JB
796 if (!sta) {
797 rcu_read_unlock();
4fd6931e 798 return -ENOENT;
98dd6a57 799 }
4fd6931e 800
d0709a65 801 if (params->vlan && params->vlan != sta->sdata->dev) {
4fd6931e
JB
802 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
803
05c914fe
JB
804 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
805 vlansdata->vif.type != NL80211_IFTYPE_AP) {
98dd6a57 806 rcu_read_unlock();
4fd6931e 807 return -EINVAL;
98dd6a57 808 }
4fd6931e 809
9bc383de 810 if (params->vlan->ieee80211_ptr->use_4addr) {
3305443c
JB
811 if (vlansdata->u.vlan.sta) {
812 rcu_read_unlock();
f14543ee 813 return -EBUSY;
3305443c 814 }
f14543ee
FF
815
816 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
817 }
818
14db74bc 819 sta->sdata = vlansdata;
4fd6931e
JB
820 ieee80211_send_layer2_update(sta);
821 }
822
823 sta_apply_parameters(local, sta, params);
824
98dd6a57
JB
825 rcu_read_unlock();
826
4fd6931e
JB
827 return 0;
828}
829
c5dd9c2b
LCC
830#ifdef CONFIG_MAC80211_MESH
831static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
832 u8 *dst, u8 *next_hop)
833{
14db74bc 834 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
835 struct mesh_path *mpath;
836 struct sta_info *sta;
837 int err;
838
14db74bc
JB
839 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
840
d0709a65 841 rcu_read_lock();
abe60632 842 sta = sta_info_get(sdata, next_hop);
d0709a65
JB
843 if (!sta) {
844 rcu_read_unlock();
c5dd9c2b 845 return -ENOENT;
d0709a65 846 }
c5dd9c2b 847
f698d856 848 err = mesh_path_add(dst, sdata);
d0709a65
JB
849 if (err) {
850 rcu_read_unlock();
c5dd9c2b 851 return err;
d0709a65 852 }
c5dd9c2b 853
f698d856 854 mpath = mesh_path_lookup(dst, sdata);
c5dd9c2b
LCC
855 if (!mpath) {
856 rcu_read_unlock();
c5dd9c2b
LCC
857 return -ENXIO;
858 }
859 mesh_path_fix_nexthop(mpath, sta);
d0709a65 860
c5dd9c2b
LCC
861 rcu_read_unlock();
862 return 0;
863}
864
865static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
866 u8 *dst)
867{
f698d856
JBG
868 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
869
c5dd9c2b 870 if (dst)
f698d856 871 return mesh_path_del(dst, sdata);
c5dd9c2b 872
f698d856 873 mesh_path_flush(sdata);
c5dd9c2b
LCC
874 return 0;
875}
876
877static int ieee80211_change_mpath(struct wiphy *wiphy,
878 struct net_device *dev,
879 u8 *dst, u8 *next_hop)
880{
14db74bc 881 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
882 struct mesh_path *mpath;
883 struct sta_info *sta;
884
14db74bc
JB
885 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
886
d0709a65
JB
887 rcu_read_lock();
888
abe60632 889 sta = sta_info_get(sdata, next_hop);
d0709a65
JB
890 if (!sta) {
891 rcu_read_unlock();
c5dd9c2b 892 return -ENOENT;
d0709a65 893 }
c5dd9c2b 894
f698d856 895 mpath = mesh_path_lookup(dst, sdata);
c5dd9c2b
LCC
896 if (!mpath) {
897 rcu_read_unlock();
c5dd9c2b
LCC
898 return -ENOENT;
899 }
900
901 mesh_path_fix_nexthop(mpath, sta);
d0709a65 902
c5dd9c2b
LCC
903 rcu_read_unlock();
904 return 0;
905}
906
907static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
908 struct mpath_info *pinfo)
909{
910 if (mpath->next_hop)
17741cdc 911 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
c5dd9c2b
LCC
912 else
913 memset(next_hop, 0, ETH_ALEN);
914
f5ea9120
JB
915 pinfo->generation = mesh_paths_generation;
916
c5dd9c2b 917 pinfo->filled = MPATH_INFO_FRAME_QLEN |
d19b3bf6 918 MPATH_INFO_SN |
c5dd9c2b
LCC
919 MPATH_INFO_METRIC |
920 MPATH_INFO_EXPTIME |
921 MPATH_INFO_DISCOVERY_TIMEOUT |
922 MPATH_INFO_DISCOVERY_RETRIES |
923 MPATH_INFO_FLAGS;
924
925 pinfo->frame_qlen = mpath->frame_queue.qlen;
d19b3bf6 926 pinfo->sn = mpath->sn;
c5dd9c2b
LCC
927 pinfo->metric = mpath->metric;
928 if (time_before(jiffies, mpath->exp_time))
929 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
930 pinfo->discovery_timeout =
931 jiffies_to_msecs(mpath->discovery_timeout);
932 pinfo->discovery_retries = mpath->discovery_retries;
933 pinfo->flags = 0;
934 if (mpath->flags & MESH_PATH_ACTIVE)
935 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
936 if (mpath->flags & MESH_PATH_RESOLVING)
937 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
d19b3bf6
RP
938 if (mpath->flags & MESH_PATH_SN_VALID)
939 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
c5dd9c2b
LCC
940 if (mpath->flags & MESH_PATH_FIXED)
941 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
942 if (mpath->flags & MESH_PATH_RESOLVING)
943 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
944
945 pinfo->flags = mpath->flags;
946}
947
948static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
949 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
950
951{
14db74bc 952 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
953 struct mesh_path *mpath;
954
14db74bc
JB
955 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
956
c5dd9c2b 957 rcu_read_lock();
f698d856 958 mpath = mesh_path_lookup(dst, sdata);
c5dd9c2b
LCC
959 if (!mpath) {
960 rcu_read_unlock();
961 return -ENOENT;
962 }
963 memcpy(dst, mpath->dst, ETH_ALEN);
964 mpath_set_pinfo(mpath, next_hop, pinfo);
965 rcu_read_unlock();
966 return 0;
967}
968
969static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
970 int idx, u8 *dst, u8 *next_hop,
971 struct mpath_info *pinfo)
972{
14db74bc 973 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
974 struct mesh_path *mpath;
975
14db74bc
JB
976 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
977
c5dd9c2b 978 rcu_read_lock();
f698d856 979 mpath = mesh_path_lookup_by_idx(idx, sdata);
c5dd9c2b
LCC
980 if (!mpath) {
981 rcu_read_unlock();
982 return -ENOENT;
983 }
984 memcpy(dst, mpath->dst, ETH_ALEN);
985 mpath_set_pinfo(mpath, next_hop, pinfo);
986 rcu_read_unlock();
987 return 0;
988}
93da9cc1 989
990static int ieee80211_get_mesh_params(struct wiphy *wiphy,
991 struct net_device *dev,
992 struct mesh_config *conf)
993{
994 struct ieee80211_sub_if_data *sdata;
995 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
996
93da9cc1 997 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
998 return 0;
999}
1000
1001static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1002{
1003 return (mask >> (parm-1)) & 0x1;
1004}
1005
1006static int ieee80211_set_mesh_params(struct wiphy *wiphy,
1007 struct net_device *dev,
1008 const struct mesh_config *nconf, u32 mask)
1009{
1010 struct mesh_config *conf;
1011 struct ieee80211_sub_if_data *sdata;
63c5723b
RP
1012 struct ieee80211_if_mesh *ifmsh;
1013
93da9cc1 1014 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
63c5723b 1015 ifmsh = &sdata->u.mesh;
93da9cc1 1016
93da9cc1 1017 /* Set the config options which we are interested in setting */
1018 conf = &(sdata->u.mesh.mshcfg);
1019 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1020 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1021 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1022 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1023 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1024 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1025 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1026 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1027 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1028 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1029 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1030 conf->dot11MeshTTL = nconf->dot11MeshTTL;
45904f21
JC
1031 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1032 conf->dot11MeshTTL = nconf->element_ttl;
93da9cc1 1033 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1034 conf->auto_open_plinks = nconf->auto_open_plinks;
1035 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1036 conf->dot11MeshHWMPmaxPREQretries =
1037 nconf->dot11MeshHWMPmaxPREQretries;
1038 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1039 conf->path_refresh_time = nconf->path_refresh_time;
1040 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1041 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1042 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1043 conf->dot11MeshHWMPactivePathTimeout =
1044 nconf->dot11MeshHWMPactivePathTimeout;
1045 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1046 conf->dot11MeshHWMPpreqMinInterval =
1047 nconf->dot11MeshHWMPpreqMinInterval;
1048 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1049 mask))
1050 conf->dot11MeshHWMPnetDiameterTraversalTime =
1051 nconf->dot11MeshHWMPnetDiameterTraversalTime;
63c5723b
RP
1052 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1053 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1054 ieee80211_mesh_root_setup(ifmsh);
1055 }
93da9cc1 1056 return 0;
1057}
1058
c5dd9c2b
LCC
1059#endif
1060
9f1ba906
JM
1061static int ieee80211_change_bss(struct wiphy *wiphy,
1062 struct net_device *dev,
1063 struct bss_parameters *params)
1064{
9f1ba906
JM
1065 struct ieee80211_sub_if_data *sdata;
1066 u32 changed = 0;
1067
9f1ba906
JM
1068 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1069
9f1ba906 1070 if (params->use_cts_prot >= 0) {
bda3933a 1071 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
9f1ba906
JM
1072 changed |= BSS_CHANGED_ERP_CTS_PROT;
1073 }
1074 if (params->use_short_preamble >= 0) {
bda3933a 1075 sdata->vif.bss_conf.use_short_preamble =
9f1ba906
JM
1076 params->use_short_preamble;
1077 changed |= BSS_CHANGED_ERP_PREAMBLE;
1078 }
43d35343
FF
1079
1080 if (!sdata->vif.bss_conf.use_short_slot &&
1081 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1082 sdata->vif.bss_conf.use_short_slot = true;
1083 changed |= BSS_CHANGED_ERP_SLOT;
1084 }
1085
9f1ba906 1086 if (params->use_short_slot_time >= 0) {
bda3933a 1087 sdata->vif.bss_conf.use_short_slot =
9f1ba906
JM
1088 params->use_short_slot_time;
1089 changed |= BSS_CHANGED_ERP_SLOT;
1090 }
1091
90c97a04
JM
1092 if (params->basic_rates) {
1093 int i, j;
1094 u32 rates = 0;
1095 struct ieee80211_local *local = wiphy_priv(wiphy);
1096 struct ieee80211_supported_band *sband =
1097 wiphy->bands[local->oper_channel->band];
1098
1099 for (i = 0; i < params->basic_rates_len; i++) {
1100 int rate = (params->basic_rates[i] & 0x7f) * 5;
1101 for (j = 0; j < sband->n_bitrates; j++) {
1102 if (sband->bitrates[j].bitrate == rate)
1103 rates |= BIT(j);
1104 }
1105 }
1106 sdata->vif.bss_conf.basic_rates = rates;
1107 changed |= BSS_CHANGED_BASIC_RATES;
1108 }
1109
7b7b5e56
FF
1110 if (params->ap_isolate >= 0) {
1111 if (params->ap_isolate)
1112 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1113 else
1114 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1115 }
1116
9f1ba906
JM
1117 ieee80211_bss_info_change_notify(sdata, changed);
1118
1119 return 0;
1120}
1121
31888487
JM
1122static int ieee80211_set_txq_params(struct wiphy *wiphy,
1123 struct ieee80211_txq_params *params)
1124{
1125 struct ieee80211_local *local = wiphy_priv(wiphy);
1126 struct ieee80211_tx_queue_params p;
1127
1128 if (!local->ops->conf_tx)
1129 return -EOPNOTSUPP;
1130
1131 memset(&p, 0, sizeof(p));
1132 p.aifs = params->aifs;
1133 p.cw_max = params->cwmax;
1134 p.cw_min = params->cwmin;
1135 p.txop = params->txop;
ab13315a
KV
1136
1137 /*
1138 * Setting tx queue params disables u-apsd because it's only
1139 * called in master mode.
1140 */
1141 p.uapsd = false;
1142
24487981 1143 if (drv_conf_tx(local, params->queue, &p)) {
0fb9a9ec
JP
1144 wiphy_debug(local->hw.wiphy,
1145 "failed to set TX queue parameters for queue %d\n",
1146 params->queue);
31888487
JM
1147 return -EINVAL;
1148 }
1149
1150 return 0;
1151}
1152
72bdcf34 1153static int ieee80211_set_channel(struct wiphy *wiphy,
f444de05 1154 struct net_device *netdev,
72bdcf34 1155 struct ieee80211_channel *chan,
094d05dc 1156 enum nl80211_channel_type channel_type)
72bdcf34
JM
1157{
1158 struct ieee80211_local *local = wiphy_priv(wiphy);
0aaffa9b
JB
1159 struct ieee80211_sub_if_data *sdata = NULL;
1160
1161 if (netdev)
1162 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
72bdcf34 1163
f444de05
JB
1164 switch (ieee80211_get_channel_mode(local, NULL)) {
1165 case CHAN_MODE_HOPPING:
1166 return -EBUSY;
1167 case CHAN_MODE_FIXED:
0aaffa9b
JB
1168 if (local->oper_channel != chan)
1169 return -EBUSY;
1170 if (!sdata && local->_oper_channel_type == channel_type)
f444de05 1171 return 0;
0aaffa9b 1172 break;
f444de05
JB
1173 case CHAN_MODE_UNDEFINED:
1174 break;
1175 }
72bdcf34
JM
1176
1177 local->oper_channel = chan;
72bdcf34 1178
0aaffa9b
JB
1179 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1180 return -EBUSY;
1181
1182 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1183 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR)
1184 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1185
1186 return 0;
72bdcf34
JM
1187}
1188
665af4fc
BC
1189#ifdef CONFIG_PM
1190static int ieee80211_suspend(struct wiphy *wiphy)
1191{
1192 return __ieee80211_suspend(wiphy_priv(wiphy));
1193}
1194
1195static int ieee80211_resume(struct wiphy *wiphy)
1196{
1197 return __ieee80211_resume(wiphy_priv(wiphy));
1198}
1199#else
1200#define ieee80211_suspend NULL
1201#define ieee80211_resume NULL
1202#endif
1203
2a519311
JB
1204static int ieee80211_scan(struct wiphy *wiphy,
1205 struct net_device *dev,
1206 struct cfg80211_scan_request *req)
1207{
2ca27bcf 1208 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2a519311 1209
2ca27bcf
JB
1210 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1211 case NL80211_IFTYPE_STATION:
1212 case NL80211_IFTYPE_ADHOC:
1213 case NL80211_IFTYPE_MESH_POINT:
1214 case NL80211_IFTYPE_P2P_CLIENT:
1215 break;
1216 case NL80211_IFTYPE_P2P_GO:
1217 if (sdata->local->ops->hw_scan)
1218 break;
1219 /* FIXME: implement NoA while scanning in software */
2a519311 1220 return -EOPNOTSUPP;
2ca27bcf
JB
1221 case NL80211_IFTYPE_AP:
1222 if (sdata->u.ap.beacon)
1223 return -EOPNOTSUPP;
1224 break;
1225 default:
1226 return -EOPNOTSUPP;
1227 }
2a519311
JB
1228
1229 return ieee80211_request_scan(sdata, req);
1230}
1231
636a5d36
JM
1232static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1233 struct cfg80211_auth_request *req)
1234{
77fdaa12 1235 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
636a5d36
JM
1236}
1237
1238static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1239 struct cfg80211_assoc_request *req)
1240{
f444de05
JB
1241 struct ieee80211_local *local = wiphy_priv(wiphy);
1242 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1243
1244 switch (ieee80211_get_channel_mode(local, sdata)) {
1245 case CHAN_MODE_HOPPING:
1246 return -EBUSY;
1247 case CHAN_MODE_FIXED:
1248 if (local->oper_channel == req->bss->channel)
1249 break;
1250 return -EBUSY;
1251 case CHAN_MODE_UNDEFINED:
1252 break;
1253 }
1254
77fdaa12 1255 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
636a5d36
JM
1256}
1257
1258static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
667503dd
JB
1259 struct cfg80211_deauth_request *req,
1260 void *cookie)
636a5d36 1261{
667503dd
JB
1262 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1263 req, cookie);
636a5d36
JM
1264}
1265
1266static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
667503dd
JB
1267 struct cfg80211_disassoc_request *req,
1268 void *cookie)
636a5d36 1269{
667503dd
JB
1270 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1271 req, cookie);
636a5d36
JM
1272}
1273
af8cdcd8
JB
1274static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1275 struct cfg80211_ibss_params *params)
1276{
f444de05 1277 struct ieee80211_local *local = wiphy_priv(wiphy);
af8cdcd8
JB
1278 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1279
f444de05
JB
1280 switch (ieee80211_get_channel_mode(local, sdata)) {
1281 case CHAN_MODE_HOPPING:
1282 return -EBUSY;
1283 case CHAN_MODE_FIXED:
1284 if (!params->channel_fixed)
1285 return -EBUSY;
1286 if (local->oper_channel == params->channel)
1287 break;
1288 return -EBUSY;
1289 case CHAN_MODE_UNDEFINED:
1290 break;
1291 }
1292
af8cdcd8
JB
1293 return ieee80211_ibss_join(sdata, params);
1294}
1295
1296static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1297{
1298 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1299
1300 return ieee80211_ibss_leave(sdata);
1301}
1302
b9a5f8ca
JM
1303static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1304{
1305 struct ieee80211_local *local = wiphy_priv(wiphy);
24487981 1306 int err;
b9a5f8ca 1307
f23a4780
AN
1308 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1309 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1310
1311 if (err)
1312 return err;
1313 }
1314
310bc676
LT
1315 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1316 err = drv_set_coverage_class(local, wiphy->coverage_class);
1317
1318 if (err)
1319 return err;
1320 }
1321
b9a5f8ca 1322 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
24487981 1323 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
b9a5f8ca 1324
24487981
JB
1325 if (err)
1326 return err;
b9a5f8ca
JM
1327 }
1328
1329 if (changed & WIPHY_PARAM_RETRY_SHORT)
1330 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1331 if (changed & WIPHY_PARAM_RETRY_LONG)
1332 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1333 if (changed &
1334 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1335 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1336
1337 return 0;
1338}
1339
7643a2c3 1340static int ieee80211_set_tx_power(struct wiphy *wiphy,
fa61cf70 1341 enum nl80211_tx_power_setting type, int mbm)
7643a2c3
JB
1342{
1343 struct ieee80211_local *local = wiphy_priv(wiphy);
1344 struct ieee80211_channel *chan = local->hw.conf.channel;
1345 u32 changes = 0;
7643a2c3
JB
1346
1347 switch (type) {
fa61cf70 1348 case NL80211_TX_POWER_AUTOMATIC:
7643a2c3
JB
1349 local->user_power_level = -1;
1350 break;
fa61cf70
JO
1351 case NL80211_TX_POWER_LIMITED:
1352 if (mbm < 0 || (mbm % 100))
1353 return -EOPNOTSUPP;
1354 local->user_power_level = MBM_TO_DBM(mbm);
7643a2c3 1355 break;
fa61cf70
JO
1356 case NL80211_TX_POWER_FIXED:
1357 if (mbm < 0 || (mbm % 100))
1358 return -EOPNOTSUPP;
7643a2c3 1359 /* TODO: move to cfg80211 when it knows the channel */
fa61cf70 1360 if (MBM_TO_DBM(mbm) > chan->max_power)
7643a2c3 1361 return -EINVAL;
fa61cf70 1362 local->user_power_level = MBM_TO_DBM(mbm);
7643a2c3 1363 break;
7643a2c3
JB
1364 }
1365
1366 ieee80211_hw_config(local, changes);
1367
1368 return 0;
1369}
1370
1371static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1372{
1373 struct ieee80211_local *local = wiphy_priv(wiphy);
1374
1375 *dbm = local->hw.conf.power_level;
1376
7643a2c3
JB
1377 return 0;
1378}
1379
ab737a4f 1380static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
388ac775 1381 const u8 *addr)
ab737a4f
JB
1382{
1383 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1384
1385 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1386
1387 return 0;
1388}
1389
1f87f7d3
JB
1390static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1391{
1392 struct ieee80211_local *local = wiphy_priv(wiphy);
1393
1394 drv_rfkill_poll(local);
1395}
1396
aff89a9b 1397#ifdef CONFIG_NL80211_TESTMODE
99783e2c 1398static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
aff89a9b
JB
1399{
1400 struct ieee80211_local *local = wiphy_priv(wiphy);
1401
1402 if (!local->ops->testmode_cmd)
1403 return -EOPNOTSUPP;
1404
1405 return local->ops->testmode_cmd(&local->hw, data, len);
1406}
1407#endif
1408
0f78231b
JB
1409int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1410 enum ieee80211_smps_mode smps_mode)
1411{
1412 const u8 *ap;
1413 enum ieee80211_smps_mode old_req;
1414 int err;
1415
1416 old_req = sdata->u.mgd.req_smps;
1417 sdata->u.mgd.req_smps = smps_mode;
1418
1419 if (old_req == smps_mode &&
1420 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1421 return 0;
1422
1423 /*
1424 * If not associated, or current association is not an HT
1425 * association, there's no need to send an action frame.
1426 */
1427 if (!sdata->u.mgd.associated ||
0aaffa9b 1428 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
0f78231b 1429 mutex_lock(&sdata->local->iflist_mtx);
025e6be2 1430 ieee80211_recalc_smps(sdata->local);
0f78231b
JB
1431 mutex_unlock(&sdata->local->iflist_mtx);
1432 return 0;
1433 }
1434
0c1ad2ca 1435 ap = sdata->u.mgd.associated->bssid;
0f78231b
JB
1436
1437 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1438 if (sdata->u.mgd.powersave)
1439 smps_mode = IEEE80211_SMPS_DYNAMIC;
1440 else
1441 smps_mode = IEEE80211_SMPS_OFF;
1442 }
1443
1444 /* send SM PS frame to AP */
1445 err = ieee80211_send_smps_action(sdata, smps_mode,
1446 ap, ap);
1447 if (err)
1448 sdata->u.mgd.req_smps = old_req;
1449
1450 return err;
1451}
1452
bc92afd9
JB
1453static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1454 bool enabled, int timeout)
1455{
1456 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1457 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
bc92afd9 1458
e5de30c9
BP
1459 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1460 return -EOPNOTSUPP;
1461
bc92afd9
JB
1462 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1463 return -EOPNOTSUPP;
1464
1465 if (enabled == sdata->u.mgd.powersave &&
ff616381 1466 timeout == local->dynamic_ps_forced_timeout)
bc92afd9
JB
1467 return 0;
1468
1469 sdata->u.mgd.powersave = enabled;
ff616381 1470 local->dynamic_ps_forced_timeout = timeout;
bc92afd9 1471
0f78231b
JB
1472 /* no change, but if automatic follow powersave */
1473 mutex_lock(&sdata->u.mgd.mtx);
1474 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1475 mutex_unlock(&sdata->u.mgd.mtx);
1476
bc92afd9
JB
1477 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1478 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1479
1480 ieee80211_recalc_ps(local, -1);
1481
1482 return 0;
1483}
1484
a97c13c3
JO
1485static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1486 struct net_device *dev,
1487 s32 rssi_thold, u32 rssi_hyst)
1488{
1489 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1490 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1491 struct ieee80211_vif *vif = &sdata->vif;
1492 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1493
a97c13c3
JO
1494 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1495 rssi_hyst == bss_conf->cqm_rssi_hyst)
1496 return 0;
1497
1498 bss_conf->cqm_rssi_thold = rssi_thold;
1499 bss_conf->cqm_rssi_hyst = rssi_hyst;
1500
17e4ec14
JM
1501 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1502 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1503 return -EOPNOTSUPP;
1504 return 0;
1505 }
1506
a97c13c3
JO
1507 /* tell the driver upon association, unless already associated */
1508 if (sdata->u.mgd.associated)
1509 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1510
1511 return 0;
1512}
1513
9930380f
JB
1514static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1515 struct net_device *dev,
1516 const u8 *addr,
1517 const struct cfg80211_bitrate_mask *mask)
1518{
1519 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1520 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2c7e6bc9 1521 int i;
9930380f 1522
2c7e6bc9
JB
1523 /*
1524 * This _could_ be supported by providing a hook for
1525 * drivers for this function, but at this point it
1526 * doesn't seem worth bothering.
1527 */
1528 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
1529 return -EOPNOTSUPP;
1530
9930380f 1531
37eb0b16
JM
1532 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
1533 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
9930380f 1534
37eb0b16 1535 return 0;
9930380f
JB
1536}
1537
b8bc4b0a
JB
1538static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1539 struct net_device *dev,
1540 struct ieee80211_channel *chan,
1541 enum nl80211_channel_type channel_type,
1542 unsigned int duration,
1543 u64 *cookie)
1544{
1545 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1546
1547 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1548 duration, cookie);
1549}
1550
1551static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1552 struct net_device *dev,
1553 u64 cookie)
1554{
1555 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1556
1557 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
1558}
1559
f30221e4
JB
1560static enum work_done_result
1561ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
1562{
1563 /*
1564 * Use the data embedded in the work struct for reporting
1565 * here so if the driver mangled the SKB before dropping
1566 * it (which is the only way we really should get here)
1567 * then we don't report mangled data.
1568 *
1569 * If there was no wait time, then by the time we get here
1570 * the driver will likely not have reported the status yet,
1571 * so in that case userspace will have to deal with it.
1572 */
1573
1574 if (wk->offchan_tx.wait && wk->offchan_tx.frame)
1575 cfg80211_mgmt_tx_status(wk->sdata->dev,
1576 (unsigned long) wk->offchan_tx.frame,
1577 wk->ie, wk->ie_len, false, GFP_KERNEL);
1578
1579 return WORK_DONE_DESTROY;
1580}
1581
2e161f78 1582static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
f7ca38df 1583 struct ieee80211_channel *chan, bool offchan,
2e161f78 1584 enum nl80211_channel_type channel_type,
f7ca38df 1585 bool channel_type_valid, unsigned int wait,
2e161f78 1586 const u8 *buf, size_t len, u64 *cookie)
026331c4 1587{
9d38d85d
JB
1588 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1589 struct ieee80211_local *local = sdata->local;
1590 struct sk_buff *skb;
1591 struct sta_info *sta;
f30221e4 1592 struct ieee80211_work *wk;
9d38d85d
JB
1593 const struct ieee80211_mgmt *mgmt = (void *)buf;
1594 u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
1595 IEEE80211_TX_CTL_REQ_TX_STATUS;
f30221e4 1596 bool is_offchan = false;
f7ca38df 1597
9d38d85d
JB
1598 /* Check that we are on the requested channel for transmission */
1599 if (chan != local->tmp_channel &&
1600 chan != local->oper_channel)
f30221e4 1601 is_offchan = true;
9d38d85d
JB
1602 if (channel_type_valid &&
1603 (channel_type != local->tmp_channel_type &&
1604 channel_type != local->_oper_channel_type))
f30221e4
JB
1605 is_offchan = true;
1606
1607 if (is_offchan && !offchan)
9d38d85d
JB
1608 return -EBUSY;
1609
1610 switch (sdata->vif.type) {
1611 case NL80211_IFTYPE_ADHOC:
663fcafd
JB
1612 case NL80211_IFTYPE_AP:
1613 case NL80211_IFTYPE_AP_VLAN:
1614 case NL80211_IFTYPE_P2P_GO:
1615 if (!ieee80211_is_action(mgmt->frame_control) ||
1616 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
9d38d85d
JB
1617 break;
1618 rcu_read_lock();
1619 sta = sta_info_get(sdata, mgmt->da);
1620 rcu_read_unlock();
1621 if (!sta)
1622 return -ENOLINK;
1623 break;
1624 case NL80211_IFTYPE_STATION:
663fcafd 1625 case NL80211_IFTYPE_P2P_CLIENT:
9d38d85d
JB
1626 break;
1627 default:
1628 return -EOPNOTSUPP;
1629 }
1630
1631 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
1632 if (!skb)
1633 return -ENOMEM;
1634 skb_reserve(skb, local->hw.extra_tx_headroom);
1635
1636 memcpy(skb_put(skb, len), buf, len);
1637
1638 IEEE80211_SKB_CB(skb)->flags = flags;
1639
1640 skb->dev = sdata->dev;
9d38d85d
JB
1641
1642 *cookie = (unsigned long) skb;
f30221e4
JB
1643
1644 /*
1645 * Can transmit right away if the channel was the
1646 * right one and there's no wait involved... If a
1647 * wait is involved, we might otherwise not be on
1648 * the right channel for long enough!
1649 */
1650 if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
1651 ieee80211_tx_skb(sdata, skb);
1652 return 0;
1653 }
1654
1655 wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
1656 if (!wk) {
1657 kfree_skb(skb);
1658 return -ENOMEM;
1659 }
1660
1661 wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
1662 wk->chan = chan;
1663 wk->sdata = sdata;
1664 wk->done = ieee80211_offchan_tx_done;
1665 wk->offchan_tx.frame = skb;
1666 wk->offchan_tx.wait = wait;
1667 wk->ie_len = len;
1668 memcpy(wk->ie, buf, len);
1669
1670 ieee80211_add_work(wk);
9d38d85d 1671 return 0;
026331c4
JM
1672}
1673
f30221e4
JB
1674static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
1675 struct net_device *dev,
1676 u64 cookie)
1677{
1678 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1679 struct ieee80211_local *local = sdata->local;
1680 struct ieee80211_work *wk;
1681 int ret = -ENOENT;
1682
1683 mutex_lock(&local->mtx);
1684 list_for_each_entry(wk, &local->work_list, list) {
1685 if (wk->sdata != sdata)
1686 continue;
1687
1688 if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
1689 continue;
1690
1691 if (cookie != (unsigned long) wk->offchan_tx.frame)
1692 continue;
1693
1694 wk->timeout = jiffies;
1695
1696 ieee80211_queue_work(&local->hw, &local->work_work);
1697 ret = 0;
1698 break;
1699 }
1700 mutex_unlock(&local->mtx);
1701
1702 return ret;
1703}
1704
7be5086d
JB
1705static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
1706 struct net_device *dev,
1707 u16 frame_type, bool reg)
1708{
1709 struct ieee80211_local *local = wiphy_priv(wiphy);
1710
1711 if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
1712 return;
1713
1714 if (reg)
1715 local->probe_req_reg++;
1716 else
1717 local->probe_req_reg--;
1718
1719 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
1720}
1721
15d96753
BR
1722static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
1723{
1724 struct ieee80211_local *local = wiphy_priv(wiphy);
1725
1726 if (local->started)
1727 return -EOPNOTSUPP;
1728
1729 return drv_set_antenna(local, tx_ant, rx_ant);
1730}
1731
1732static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
1733{
1734 struct ieee80211_local *local = wiphy_priv(wiphy);
1735
1736 return drv_get_antenna(local, tx_ant, rx_ant);
1737}
1738
f0706e82
JB
1739struct cfg80211_ops mac80211_config_ops = {
1740 .add_virtual_intf = ieee80211_add_iface,
1741 .del_virtual_intf = ieee80211_del_iface,
42613db7 1742 .change_virtual_intf = ieee80211_change_iface,
e8cbb4cb
JB
1743 .add_key = ieee80211_add_key,
1744 .del_key = ieee80211_del_key,
62da92fb 1745 .get_key = ieee80211_get_key,
e8cbb4cb 1746 .set_default_key = ieee80211_config_default_key,
3cfcf6ac 1747 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
5dfdaf58
JB
1748 .add_beacon = ieee80211_add_beacon,
1749 .set_beacon = ieee80211_set_beacon,
1750 .del_beacon = ieee80211_del_beacon,
4fd6931e
JB
1751 .add_station = ieee80211_add_station,
1752 .del_station = ieee80211_del_station,
1753 .change_station = ieee80211_change_station,
7bbdd2d9 1754 .get_station = ieee80211_get_station,
c5dd9c2b 1755 .dump_station = ieee80211_dump_station,
1289723e 1756 .dump_survey = ieee80211_dump_survey,
c5dd9c2b
LCC
1757#ifdef CONFIG_MAC80211_MESH
1758 .add_mpath = ieee80211_add_mpath,
1759 .del_mpath = ieee80211_del_mpath,
1760 .change_mpath = ieee80211_change_mpath,
1761 .get_mpath = ieee80211_get_mpath,
1762 .dump_mpath = ieee80211_dump_mpath,
93da9cc1 1763 .set_mesh_params = ieee80211_set_mesh_params,
1764 .get_mesh_params = ieee80211_get_mesh_params,
c5dd9c2b 1765#endif
9f1ba906 1766 .change_bss = ieee80211_change_bss,
31888487 1767 .set_txq_params = ieee80211_set_txq_params,
72bdcf34 1768 .set_channel = ieee80211_set_channel,
665af4fc
BC
1769 .suspend = ieee80211_suspend,
1770 .resume = ieee80211_resume,
2a519311 1771 .scan = ieee80211_scan,
636a5d36
JM
1772 .auth = ieee80211_auth,
1773 .assoc = ieee80211_assoc,
1774 .deauth = ieee80211_deauth,
1775 .disassoc = ieee80211_disassoc,
af8cdcd8
JB
1776 .join_ibss = ieee80211_join_ibss,
1777 .leave_ibss = ieee80211_leave_ibss,
b9a5f8ca 1778 .set_wiphy_params = ieee80211_set_wiphy_params,
7643a2c3
JB
1779 .set_tx_power = ieee80211_set_tx_power,
1780 .get_tx_power = ieee80211_get_tx_power,
ab737a4f 1781 .set_wds_peer = ieee80211_set_wds_peer,
1f87f7d3 1782 .rfkill_poll = ieee80211_rfkill_poll,
aff89a9b 1783 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
bc92afd9 1784 .set_power_mgmt = ieee80211_set_power_mgmt,
9930380f 1785 .set_bitrate_mask = ieee80211_set_bitrate_mask,
b8bc4b0a
JB
1786 .remain_on_channel = ieee80211_remain_on_channel,
1787 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
2e161f78 1788 .mgmt_tx = ieee80211_mgmt_tx,
f30221e4 1789 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
a97c13c3 1790 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
7be5086d 1791 .mgmt_frame_register = ieee80211_mgmt_frame_register,
15d96753
BR
1792 .set_antenna = ieee80211_set_antenna,
1793 .get_antenna = ieee80211_get_antenna,
f0706e82 1794};