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