mac80211: 802.11w - Add BIP (AES-128-CMAC)
[linux-2.6-block.git] / net / mac80211 / cfg.c
CommitLineData
f0706e82
JB
1/*
2 * mac80211 configuration hooks for cfg80211
3 *
62da92fb 4 * Copyright 2006, 2007 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>
881d966b 12#include <net/net_namespace.h>
5dfdaf58 13#include <linux/rcupdate.h>
f0706e82
JB
14#include <net/cfg80211.h>
15#include "ieee80211_i.h"
e0eb6859 16#include "cfg.h"
2c8dccc7 17#include "rate.h"
c5dd9c2b 18#include "mesh.h"
c5dd9c2b 19
05c914fe 20static bool nl80211_type_check(enum nl80211_iftype type)
42613db7
JB
21{
22 switch (type) {
42613db7 23 case NL80211_IFTYPE_ADHOC:
42613db7 24 case NL80211_IFTYPE_STATION:
42613db7 25 case NL80211_IFTYPE_MONITOR:
c5dd9c2b
LCC
26#ifdef CONFIG_MAC80211_MESH
27 case NL80211_IFTYPE_MESH_POINT:
c5dd9c2b 28#endif
fbf18927
JM
29 case NL80211_IFTYPE_AP:
30 case NL80211_IFTYPE_AP_VLAN:
b454048c 31 case NL80211_IFTYPE_WDS:
05c914fe 32 return true;
42613db7 33 default:
05c914fe 34 return false;
42613db7
JB
35 }
36}
37
f0706e82 38static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
2ec600d6
LCC
39 enum nl80211_iftype type, u32 *flags,
40 struct vif_params *params)
f0706e82
JB
41{
42 struct ieee80211_local *local = wiphy_priv(wiphy);
8cc9a739
MW
43 struct net_device *dev;
44 struct ieee80211_sub_if_data *sdata;
45 int err;
f0706e82 46
05c914fe 47 if (!nl80211_type_check(type))
f0706e82 48 return -EINVAL;
f0706e82 49
05c914fe
JB
50 err = ieee80211_if_add(local, name, &dev, type, params);
51 if (err || type != NL80211_IFTYPE_MONITOR || !flags)
8cc9a739
MW
52 return err;
53
54 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
55 sdata->u.mntr_flags = *flags;
56 return 0;
f0706e82
JB
57}
58
59static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
60{
f0706e82 61 struct net_device *dev;
f698d856 62 struct ieee80211_sub_if_data *sdata;
f0706e82 63
42613db7
JB
64 /* we're under RTNL */
65 dev = __dev_get_by_index(&init_net, ifindex);
f0706e82 66 if (!dev)
75636525 67 return -ENODEV;
f0706e82 68
f698d856
JBG
69 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
70
71 ieee80211_if_remove(sdata);
f0706e82 72
75636525 73 return 0;
f0706e82
JB
74}
75
42613db7 76static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
2ec600d6
LCC
77 enum nl80211_iftype type, u32 *flags,
78 struct vif_params *params)
42613db7 79{
42613db7 80 struct net_device *dev;
42613db7 81 struct ieee80211_sub_if_data *sdata;
f3947e2d 82 int ret;
42613db7 83
42613db7
JB
84 /* we're under RTNL */
85 dev = __dev_get_by_index(&init_net, ifindex);
86 if (!dev)
87 return -ENODEV;
88
05c914fe 89 if (!nl80211_type_check(type))
42613db7
JB
90 return -EINVAL;
91
92 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
93
05c914fe 94 ret = ieee80211_if_change_type(sdata, type);
f3947e2d
JB
95 if (ret)
96 return ret;
42613db7 97
f8b25cda
JB
98 if (netif_running(sdata->dev))
99 return -EBUSY;
100
902acc78 101 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
472dbc45
JB
102 ieee80211_sdata_set_mesh_id(sdata,
103 params->mesh_id_len,
104 params->mesh_id);
c5dd9c2b 105
05c914fe 106 if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
8cc9a739
MW
107 return 0;
108
109 sdata->u.mntr_flags = *flags;
42613db7
JB
110 return 0;
111}
112
e8cbb4cb
JB
113static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
114 u8 key_idx, u8 *mac_addr,
115 struct key_params *params)
116{
117 struct ieee80211_sub_if_data *sdata;
118 struct sta_info *sta = NULL;
119 enum ieee80211_key_alg alg;
db4d1169 120 struct ieee80211_key *key;
3b96766f 121 int err;
e8cbb4cb
JB
122
123 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
124
125 switch (params->cipher) {
126 case WLAN_CIPHER_SUITE_WEP40:
127 case WLAN_CIPHER_SUITE_WEP104:
128 alg = ALG_WEP;
129 break;
130 case WLAN_CIPHER_SUITE_TKIP:
131 alg = ALG_TKIP;
132 break;
133 case WLAN_CIPHER_SUITE_CCMP:
134 alg = ALG_CCMP;
135 break;
136 default:
137 return -EINVAL;
138 }
139
db4d1169
JB
140 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
141 if (!key)
142 return -ENOMEM;
143
3b96766f
JB
144 rcu_read_lock();
145
e8cbb4cb
JB
146 if (mac_addr) {
147 sta = sta_info_get(sdata->local, mac_addr);
db4d1169
JB
148 if (!sta) {
149 ieee80211_key_free(key);
3b96766f
JB
150 err = -ENOENT;
151 goto out_unlock;
db4d1169 152 }
e8cbb4cb
JB
153 }
154
db4d1169
JB
155 ieee80211_key_link(key, sdata, sta);
156
3b96766f
JB
157 err = 0;
158 out_unlock:
159 rcu_read_unlock();
160
161 return err;
e8cbb4cb
JB
162}
163
164static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
165 u8 key_idx, u8 *mac_addr)
166{
167 struct ieee80211_sub_if_data *sdata;
168 struct sta_info *sta;
169 int ret;
170
171 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
172
3b96766f
JB
173 rcu_read_lock();
174
e8cbb4cb 175 if (mac_addr) {
3b96766f
JB
176 ret = -ENOENT;
177
e8cbb4cb
JB
178 sta = sta_info_get(sdata->local, mac_addr);
179 if (!sta)
3b96766f 180 goto out_unlock;
e8cbb4cb 181
db4d1169 182 if (sta->key) {
d0709a65 183 ieee80211_key_free(sta->key);
db4d1169 184 WARN_ON(sta->key);
3b96766f
JB
185 ret = 0;
186 }
e8cbb4cb 187
3b96766f 188 goto out_unlock;
e8cbb4cb
JB
189 }
190
3b96766f
JB
191 if (!sdata->keys[key_idx]) {
192 ret = -ENOENT;
193 goto out_unlock;
194 }
e8cbb4cb 195
d0709a65 196 ieee80211_key_free(sdata->keys[key_idx]);
db4d1169 197 WARN_ON(sdata->keys[key_idx]);
e8cbb4cb 198
3b96766f
JB
199 ret = 0;
200 out_unlock:
201 rcu_read_unlock();
202
203 return ret;
e8cbb4cb
JB
204}
205
62da92fb
JB
206static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
207 u8 key_idx, u8 *mac_addr, void *cookie,
208 void (*callback)(void *cookie,
209 struct key_params *params))
210{
14db74bc 211 struct ieee80211_sub_if_data *sdata;
62da92fb
JB
212 struct sta_info *sta = NULL;
213 u8 seq[6] = {0};
214 struct key_params params;
215 struct ieee80211_key *key;
216 u32 iv32;
217 u16 iv16;
218 int err = -ENOENT;
219
14db74bc
JB
220 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
221
3b96766f
JB
222 rcu_read_lock();
223
62da92fb
JB
224 if (mac_addr) {
225 sta = sta_info_get(sdata->local, mac_addr);
226 if (!sta)
227 goto out;
228
229 key = sta->key;
230 } else
231 key = sdata->keys[key_idx];
232
233 if (!key)
234 goto out;
235
236 memset(&params, 0, sizeof(params));
237
238 switch (key->conf.alg) {
239 case ALG_TKIP:
240 params.cipher = WLAN_CIPHER_SUITE_TKIP;
241
b0f76b33
HH
242 iv32 = key->u.tkip.tx.iv32;
243 iv16 = key->u.tkip.tx.iv16;
62da92fb
JB
244
245 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
246 sdata->local->ops->get_tkip_seq)
247 sdata->local->ops->get_tkip_seq(
248 local_to_hw(sdata->local),
249 key->conf.hw_key_idx,
250 &iv32, &iv16);
251
252 seq[0] = iv16 & 0xff;
253 seq[1] = (iv16 >> 8) & 0xff;
254 seq[2] = iv32 & 0xff;
255 seq[3] = (iv32 >> 8) & 0xff;
256 seq[4] = (iv32 >> 16) & 0xff;
257 seq[5] = (iv32 >> 24) & 0xff;
258 params.seq = seq;
259 params.seq_len = 6;
260 break;
261 case ALG_CCMP:
262 params.cipher = WLAN_CIPHER_SUITE_CCMP;
263 seq[0] = key->u.ccmp.tx_pn[5];
264 seq[1] = key->u.ccmp.tx_pn[4];
265 seq[2] = key->u.ccmp.tx_pn[3];
266 seq[3] = key->u.ccmp.tx_pn[2];
267 seq[4] = key->u.ccmp.tx_pn[1];
268 seq[5] = key->u.ccmp.tx_pn[0];
269 params.seq = seq;
270 params.seq_len = 6;
271 break;
272 case ALG_WEP:
273 if (key->conf.keylen == 5)
274 params.cipher = WLAN_CIPHER_SUITE_WEP40;
275 else
276 params.cipher = WLAN_CIPHER_SUITE_WEP104;
277 break;
278 }
279
280 params.key = key->conf.key;
281 params.key_len = key->conf.keylen;
282
283 callback(cookie, &params);
284 err = 0;
285
286 out:
3b96766f 287 rcu_read_unlock();
62da92fb
JB
288 return err;
289}
290
e8cbb4cb
JB
291static int ieee80211_config_default_key(struct wiphy *wiphy,
292 struct net_device *dev,
293 u8 key_idx)
294{
295 struct ieee80211_sub_if_data *sdata;
296
3b96766f
JB
297 rcu_read_lock();
298
e8cbb4cb
JB
299 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
300 ieee80211_set_default_key(sdata, key_idx);
301
3b96766f
JB
302 rcu_read_unlock();
303
e8cbb4cb
JB
304 return 0;
305}
306
c5dd9c2b
LCC
307static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
308{
d0709a65 309 struct ieee80211_sub_if_data *sdata = sta->sdata;
c5dd9c2b
LCC
310
311 sinfo->filled = STATION_INFO_INACTIVE_TIME |
312 STATION_INFO_RX_BYTES |
420e7fab
HR
313 STATION_INFO_TX_BYTES |
314 STATION_INFO_TX_BITRATE;
c5dd9c2b
LCC
315
316 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
317 sinfo->rx_bytes = sta->rx_bytes;
318 sinfo->tx_bytes = sta->tx_bytes;
319
420e7fab
HR
320 if (sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
321 sinfo->filled |= STATION_INFO_SIGNAL;
322 sinfo->signal = (s8)sta->last_signal;
323 }
324
325 sinfo->txrate.flags = 0;
326 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
327 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
328 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
329 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
330 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
331 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
332
333 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
334 struct ieee80211_supported_band *sband;
335 sband = sta->local->hw.wiphy->bands[
336 sta->local->hw.conf.channel->band];
337 sinfo->txrate.legacy =
338 sband->bitrates[sta->last_tx_rate.idx].bitrate;
339 } else
340 sinfo->txrate.mcs = sta->last_tx_rate.idx;
341
902acc78 342 if (ieee80211_vif_is_mesh(&sdata->vif)) {
c5dd9c2b 343#ifdef CONFIG_MAC80211_MESH
c5dd9c2b
LCC
344 sinfo->filled |= STATION_INFO_LLID |
345 STATION_INFO_PLID |
346 STATION_INFO_PLINK_STATE;
347
348 sinfo->llid = le16_to_cpu(sta->llid);
349 sinfo->plid = le16_to_cpu(sta->plid);
350 sinfo->plink_state = sta->plink_state;
c5dd9c2b 351#endif
902acc78 352 }
c5dd9c2b
LCC
353}
354
355
356static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
357 int idx, u8 *mac, struct station_info *sinfo)
358{
359 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
360 struct sta_info *sta;
d0709a65
JB
361 int ret = -ENOENT;
362
363 rcu_read_lock();
c5dd9c2b
LCC
364
365 sta = sta_info_get_by_idx(local, idx, dev);
d0709a65
JB
366 if (sta) {
367 ret = 0;
17741cdc 368 memcpy(mac, sta->sta.addr, ETH_ALEN);
d0709a65
JB
369 sta_set_sinfo(sta, sinfo);
370 }
c5dd9c2b 371
d0709a65 372 rcu_read_unlock();
c5dd9c2b 373
d0709a65 374 return ret;
c5dd9c2b
LCC
375}
376
7bbdd2d9 377static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
2ec600d6 378 u8 *mac, struct station_info *sinfo)
7bbdd2d9
JB
379{
380 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
381 struct sta_info *sta;
d0709a65 382 int ret = -ENOENT;
7bbdd2d9 383
d0709a65 384 rcu_read_lock();
7bbdd2d9
JB
385
386 /* XXX: verify sta->dev == dev */
7bbdd2d9 387
d0709a65
JB
388 sta = sta_info_get(local, mac);
389 if (sta) {
390 ret = 0;
391 sta_set_sinfo(sta, sinfo);
392 }
393
394 rcu_read_unlock();
395
396 return ret;
7bbdd2d9
JB
397}
398
5dfdaf58
JB
399/*
400 * This handles both adding a beacon and setting new beacon info
401 */
402static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
403 struct beacon_parameters *params)
404{
405 struct beacon_data *new, *old;
406 int new_head_len, new_tail_len;
407 int size;
408 int err = -EINVAL;
409
410 old = sdata->u.ap.beacon;
411
412 /* head must not be zero-length */
413 if (params->head && !params->head_len)
414 return -EINVAL;
415
416 /*
417 * This is a kludge. beacon interval should really be part
418 * of the beacon information.
419 */
420 if (params->interval) {
421 sdata->local->hw.conf.beacon_int = params->interval;
447107fb
RC
422 err = ieee80211_hw_config(sdata->local,
423 IEEE80211_CONF_CHANGE_BEACON_INTERVAL);
424 if (err < 0)
425 return err;
5dfdaf58
JB
426 /*
427 * We updated some parameter so if below bails out
428 * it's not an error.
429 */
430 err = 0;
431 }
432
433 /* Need to have a beacon head if we don't have one yet */
434 if (!params->head && !old)
435 return err;
436
437 /* sorry, no way to start beaconing without dtim period */
438 if (!params->dtim_period && !old)
439 return err;
440
441 /* new or old head? */
442 if (params->head)
443 new_head_len = params->head_len;
444 else
445 new_head_len = old->head_len;
446
447 /* new or old tail? */
448 if (params->tail || !old)
449 /* params->tail_len will be zero for !params->tail */
450 new_tail_len = params->tail_len;
451 else
452 new_tail_len = old->tail_len;
453
454 size = sizeof(*new) + new_head_len + new_tail_len;
455
456 new = kzalloc(size, GFP_KERNEL);
457 if (!new)
458 return -ENOMEM;
459
460 /* start filling the new info now */
461
462 /* new or old dtim period? */
463 if (params->dtim_period)
464 new->dtim_period = params->dtim_period;
465 else
466 new->dtim_period = old->dtim_period;
467
468 /*
469 * pointers go into the block we allocated,
470 * memory is | beacon_data | head | tail |
471 */
472 new->head = ((u8 *) new) + sizeof(*new);
473 new->tail = new->head + new_head_len;
474 new->head_len = new_head_len;
475 new->tail_len = new_tail_len;
476
477 /* copy in head */
478 if (params->head)
479 memcpy(new->head, params->head, new_head_len);
480 else
481 memcpy(new->head, old->head, new_head_len);
482
483 /* copy in optional tail */
484 if (params->tail)
485 memcpy(new->tail, params->tail, new_tail_len);
486 else
487 if (old)
488 memcpy(new->tail, old->tail, new_tail_len);
489
490 rcu_assign_pointer(sdata->u.ap.beacon, new);
491
492 synchronize_rcu();
493
494 kfree(old);
495
9d139c81 496 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
5dfdaf58
JB
497}
498
499static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
500 struct beacon_parameters *params)
501{
14db74bc 502 struct ieee80211_sub_if_data *sdata;
5dfdaf58
JB
503 struct beacon_data *old;
504
14db74bc
JB
505 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
506
05c914fe 507 if (sdata->vif.type != NL80211_IFTYPE_AP)
5dfdaf58
JB
508 return -EINVAL;
509
510 old = sdata->u.ap.beacon;
511
512 if (old)
513 return -EALREADY;
514
515 return ieee80211_config_beacon(sdata, params);
516}
517
518static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
519 struct beacon_parameters *params)
520{
14db74bc 521 struct ieee80211_sub_if_data *sdata;
5dfdaf58
JB
522 struct beacon_data *old;
523
14db74bc
JB
524 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
525
05c914fe 526 if (sdata->vif.type != NL80211_IFTYPE_AP)
5dfdaf58
JB
527 return -EINVAL;
528
529 old = sdata->u.ap.beacon;
530
531 if (!old)
532 return -ENOENT;
533
534 return ieee80211_config_beacon(sdata, params);
535}
536
537static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
538{
14db74bc 539 struct ieee80211_sub_if_data *sdata;
5dfdaf58
JB
540 struct beacon_data *old;
541
14db74bc
JB
542 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
543
05c914fe 544 if (sdata->vif.type != NL80211_IFTYPE_AP)
5dfdaf58
JB
545 return -EINVAL;
546
547 old = sdata->u.ap.beacon;
548
549 if (!old)
550 return -ENOENT;
551
552 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
553 synchronize_rcu();
554 kfree(old);
555
9d139c81 556 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
5dfdaf58
JB
557}
558
4fd6931e
JB
559/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
560struct iapp_layer2_update {
561 u8 da[ETH_ALEN]; /* broadcast */
562 u8 sa[ETH_ALEN]; /* STA addr */
563 __be16 len; /* 6 */
564 u8 dsap; /* 0 */
565 u8 ssap; /* 0 */
566 u8 control;
567 u8 xid_info[3];
568} __attribute__ ((packed));
569
570static void ieee80211_send_layer2_update(struct sta_info *sta)
571{
572 struct iapp_layer2_update *msg;
573 struct sk_buff *skb;
574
575 /* Send Level 2 Update Frame to update forwarding tables in layer 2
576 * bridge devices */
577
578 skb = dev_alloc_skb(sizeof(*msg));
579 if (!skb)
580 return;
581 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
582
583 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
584 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
585
586 memset(msg->da, 0xff, ETH_ALEN);
17741cdc 587 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
4fd6931e
JB
588 msg->len = htons(6);
589 msg->dsap = 0;
590 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
591 msg->control = 0xaf; /* XID response lsb.1111F101.
592 * F=0 (no poll command; unsolicited frame) */
593 msg->xid_info[0] = 0x81; /* XID format identifier */
594 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
595 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
596
d0709a65
JB
597 skb->dev = sta->sdata->dev;
598 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
4fd6931e
JB
599 memset(skb->cb, 0, sizeof(skb->cb));
600 netif_rx(skb);
601}
602
603static void sta_apply_parameters(struct ieee80211_local *local,
604 struct sta_info *sta,
605 struct station_parameters *params)
606{
607 u32 rates;
608 int i, j;
8318d78a 609 struct ieee80211_supported_band *sband;
d0709a65 610 struct ieee80211_sub_if_data *sdata = sta->sdata;
4fd6931e 611
ae5eb026
JB
612 sband = local->hw.wiphy->bands[local->oper_channel->band];
613
73651ee6
JB
614 /*
615 * FIXME: updating the flags is racy when this function is
616 * called from ieee80211_change_station(), this will
617 * be resolved in a future patch.
618 */
619
4fd6931e 620 if (params->station_flags & STATION_FLAG_CHANGED) {
07346f81 621 spin_lock_bh(&sta->lock);
4fd6931e
JB
622 sta->flags &= ~WLAN_STA_AUTHORIZED;
623 if (params->station_flags & STATION_FLAG_AUTHORIZED)
624 sta->flags |= WLAN_STA_AUTHORIZED;
625
626 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
627 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
628 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
629
630 sta->flags &= ~WLAN_STA_WME;
631 if (params->station_flags & STATION_FLAG_WME)
632 sta->flags |= WLAN_STA_WME;
5394af4d
JM
633
634 sta->flags &= ~WLAN_STA_MFP;
635 if (params->station_flags & STATION_FLAG_MFP)
636 sta->flags |= WLAN_STA_MFP;
07346f81 637 spin_unlock_bh(&sta->lock);
4fd6931e
JB
638 }
639
73651ee6
JB
640 /*
641 * FIXME: updating the following information is racy when this
642 * function is called from ieee80211_change_station().
643 * However, all this information should be static so
644 * maybe we should just reject attemps to change it.
645 */
646
4fd6931e 647 if (params->aid) {
17741cdc
JB
648 sta->sta.aid = params->aid;
649 if (sta->sta.aid > IEEE80211_MAX_AID)
650 sta->sta.aid = 0; /* XXX: should this be an error? */
4fd6931e
JB
651 }
652
653 if (params->listen_interval >= 0)
654 sta->listen_interval = params->listen_interval;
655
656 if (params->supported_rates) {
657 rates = 0;
8318d78a 658
4fd6931e
JB
659 for (i = 0; i < params->supported_rates_len; i++) {
660 int rate = (params->supported_rates[i] & 0x7f) * 5;
8318d78a
JB
661 for (j = 0; j < sband->n_bitrates; j++) {
662 if (sband->bitrates[j].bitrate == rate)
4fd6931e
JB
663 rates |= BIT(j);
664 }
665 }
323ce79a 666 sta->sta.supp_rates[local->oper_channel->band] = rates;
4fd6931e 667 }
c5dd9c2b 668
d9fe60de 669 if (params->ht_capa)
ae5eb026
JB
670 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
671 params->ht_capa,
d9fe60de 672 &sta->sta.ht_cap);
36aedc90 673
902acc78 674 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
c5dd9c2b
LCC
675 switch (params->plink_action) {
676 case PLINK_ACTION_OPEN:
677 mesh_plink_open(sta);
678 break;
679 case PLINK_ACTION_BLOCK:
680 mesh_plink_block(sta);
681 break;
682 }
902acc78 683 }
4fd6931e
JB
684}
685
686static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
687 u8 *mac, struct station_parameters *params)
688{
14db74bc 689 struct ieee80211_local *local = wiphy_priv(wiphy);
4fd6931e
JB
690 struct sta_info *sta;
691 struct ieee80211_sub_if_data *sdata;
73651ee6 692 int err;
b8d476c8 693 int layer2_update;
4fd6931e
JB
694
695 /* Prevent a race with changing the rate control algorithm */
696 if (!netif_running(dev))
697 return -ENETDOWN;
698
4fd6931e
JB
699 if (params->vlan) {
700 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
701
05c914fe
JB
702 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
703 sdata->vif.type != NL80211_IFTYPE_AP)
4fd6931e
JB
704 return -EINVAL;
705 } else
706 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
707
03e4497e
JB
708 if (compare_ether_addr(mac, dev->dev_addr) == 0)
709 return -EINVAL;
710
711 if (is_multicast_ether_addr(mac))
712 return -EINVAL;
713
714 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
73651ee6
JB
715 if (!sta)
716 return -ENOMEM;
4fd6931e
JB
717
718 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
719
720 sta_apply_parameters(local, sta, params);
721
4b7679a5 722 rate_control_rate_init(sta);
4fd6931e 723
b8d476c8
JM
724 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
725 sdata->vif.type == NL80211_IFTYPE_AP;
726
73651ee6
JB
727 rcu_read_lock();
728
729 err = sta_info_insert(sta);
730 if (err) {
93e5deb1 731 /* STA has been freed */
b8d476c8
JM
732 if (err == -EEXIST && layer2_update) {
733 /* Need to update layer 2 devices on reassociation */
734 sta = sta_info_get(local, mac);
735 if (sta)
736 ieee80211_send_layer2_update(sta);
737 }
73651ee6
JB
738 rcu_read_unlock();
739 return err;
740 }
741
b8d476c8 742 if (layer2_update)
73651ee6
JB
743 ieee80211_send_layer2_update(sta);
744
745 rcu_read_unlock();
746
4fd6931e
JB
747 return 0;
748}
749
750static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
751 u8 *mac)
752{
14db74bc
JB
753 struct ieee80211_local *local = wiphy_priv(wiphy);
754 struct ieee80211_sub_if_data *sdata;
4fd6931e
JB
755 struct sta_info *sta;
756
14db74bc
JB
757 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
758
4fd6931e 759 if (mac) {
98dd6a57
JB
760 rcu_read_lock();
761
4fd6931e
JB
762 /* XXX: get sta belonging to dev */
763 sta = sta_info_get(local, mac);
98dd6a57
JB
764 if (!sta) {
765 rcu_read_unlock();
4fd6931e 766 return -ENOENT;
98dd6a57 767 }
4fd6931e 768
d0709a65 769 sta_info_unlink(&sta);
98dd6a57
JB
770 rcu_read_unlock();
771
4f6fab47 772 sta_info_destroy(sta);
4fd6931e 773 } else
d0709a65 774 sta_info_flush(local, sdata);
4fd6931e
JB
775
776 return 0;
777}
778
779static int ieee80211_change_station(struct wiphy *wiphy,
780 struct net_device *dev,
781 u8 *mac,
782 struct station_parameters *params)
783{
14db74bc 784 struct ieee80211_local *local = wiphy_priv(wiphy);
4fd6931e
JB
785 struct sta_info *sta;
786 struct ieee80211_sub_if_data *vlansdata;
787
98dd6a57
JB
788 rcu_read_lock();
789
4fd6931e
JB
790 /* XXX: get sta belonging to dev */
791 sta = sta_info_get(local, mac);
98dd6a57
JB
792 if (!sta) {
793 rcu_read_unlock();
4fd6931e 794 return -ENOENT;
98dd6a57 795 }
4fd6931e 796
d0709a65 797 if (params->vlan && params->vlan != sta->sdata->dev) {
4fd6931e
JB
798 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
799
05c914fe
JB
800 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
801 vlansdata->vif.type != NL80211_IFTYPE_AP) {
98dd6a57 802 rcu_read_unlock();
4fd6931e 803 return -EINVAL;
98dd6a57 804 }
4fd6931e 805
14db74bc 806 sta->sdata = vlansdata;
4fd6931e
JB
807 ieee80211_send_layer2_update(sta);
808 }
809
810 sta_apply_parameters(local, sta, params);
811
98dd6a57
JB
812 rcu_read_unlock();
813
4fd6931e
JB
814 return 0;
815}
816
c5dd9c2b
LCC
817#ifdef CONFIG_MAC80211_MESH
818static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
819 u8 *dst, u8 *next_hop)
820{
14db74bc
JB
821 struct ieee80211_local *local = wiphy_priv(wiphy);
822 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
823 struct mesh_path *mpath;
824 struct sta_info *sta;
825 int err;
826
827 if (!netif_running(dev))
828 return -ENETDOWN;
829
14db74bc
JB
830 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
831
05c914fe 832 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
c5dd9c2b
LCC
833 return -ENOTSUPP;
834
d0709a65 835 rcu_read_lock();
c5dd9c2b 836 sta = sta_info_get(local, next_hop);
d0709a65
JB
837 if (!sta) {
838 rcu_read_unlock();
c5dd9c2b 839 return -ENOENT;
d0709a65 840 }
c5dd9c2b 841
f698d856 842 err = mesh_path_add(dst, sdata);
d0709a65
JB
843 if (err) {
844 rcu_read_unlock();
c5dd9c2b 845 return err;
d0709a65 846 }
c5dd9c2b 847
f698d856 848 mpath = mesh_path_lookup(dst, sdata);
c5dd9c2b
LCC
849 if (!mpath) {
850 rcu_read_unlock();
c5dd9c2b
LCC
851 return -ENXIO;
852 }
853 mesh_path_fix_nexthop(mpath, sta);
d0709a65 854
c5dd9c2b
LCC
855 rcu_read_unlock();
856 return 0;
857}
858
859static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
860 u8 *dst)
861{
f698d856
JBG
862 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
863
c5dd9c2b 864 if (dst)
f698d856 865 return mesh_path_del(dst, sdata);
c5dd9c2b 866
f698d856 867 mesh_path_flush(sdata);
c5dd9c2b
LCC
868 return 0;
869}
870
871static int ieee80211_change_mpath(struct wiphy *wiphy,
872 struct net_device *dev,
873 u8 *dst, u8 *next_hop)
874{
14db74bc
JB
875 struct ieee80211_local *local = wiphy_priv(wiphy);
876 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
877 struct mesh_path *mpath;
878 struct sta_info *sta;
879
880 if (!netif_running(dev))
881 return -ENETDOWN;
882
14db74bc
JB
883 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
884
05c914fe 885 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
c5dd9c2b
LCC
886 return -ENOTSUPP;
887
d0709a65
JB
888 rcu_read_lock();
889
c5dd9c2b 890 sta = sta_info_get(local, next_hop);
d0709a65
JB
891 if (!sta) {
892 rcu_read_unlock();
c5dd9c2b 893 return -ENOENT;
d0709a65 894 }
c5dd9c2b 895
f698d856 896 mpath = mesh_path_lookup(dst, sdata);
c5dd9c2b
LCC
897 if (!mpath) {
898 rcu_read_unlock();
c5dd9c2b
LCC
899 return -ENOENT;
900 }
901
902 mesh_path_fix_nexthop(mpath, sta);
d0709a65 903
c5dd9c2b
LCC
904 rcu_read_unlock();
905 return 0;
906}
907
908static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
909 struct mpath_info *pinfo)
910{
911 if (mpath->next_hop)
17741cdc 912 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
c5dd9c2b
LCC
913 else
914 memset(next_hop, 0, ETH_ALEN);
915
916 pinfo->filled = MPATH_INFO_FRAME_QLEN |
917 MPATH_INFO_DSN |
918 MPATH_INFO_METRIC |
919 MPATH_INFO_EXPTIME |
920 MPATH_INFO_DISCOVERY_TIMEOUT |
921 MPATH_INFO_DISCOVERY_RETRIES |
922 MPATH_INFO_FLAGS;
923
924 pinfo->frame_qlen = mpath->frame_queue.qlen;
925 pinfo->dsn = mpath->dsn;
926 pinfo->metric = mpath->metric;
927 if (time_before(jiffies, mpath->exp_time))
928 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
929 pinfo->discovery_timeout =
930 jiffies_to_msecs(mpath->discovery_timeout);
931 pinfo->discovery_retries = mpath->discovery_retries;
932 pinfo->flags = 0;
933 if (mpath->flags & MESH_PATH_ACTIVE)
934 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
935 if (mpath->flags & MESH_PATH_RESOLVING)
936 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
937 if (mpath->flags & MESH_PATH_DSN_VALID)
938 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
939 if (mpath->flags & MESH_PATH_FIXED)
940 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
941 if (mpath->flags & MESH_PATH_RESOLVING)
942 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
943
944 pinfo->flags = mpath->flags;
945}
946
947static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
948 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
949
950{
14db74bc 951 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
952 struct mesh_path *mpath;
953
14db74bc
JB
954 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
955
05c914fe 956 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
c5dd9c2b
LCC
957 return -ENOTSUPP;
958
959 rcu_read_lock();
f698d856 960 mpath = mesh_path_lookup(dst, sdata);
c5dd9c2b
LCC
961 if (!mpath) {
962 rcu_read_unlock();
963 return -ENOENT;
964 }
965 memcpy(dst, mpath->dst, ETH_ALEN);
966 mpath_set_pinfo(mpath, next_hop, pinfo);
967 rcu_read_unlock();
968 return 0;
969}
970
971static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
972 int idx, u8 *dst, u8 *next_hop,
973 struct mpath_info *pinfo)
974{
14db74bc 975 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
976 struct mesh_path *mpath;
977
14db74bc
JB
978 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
979
05c914fe 980 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
c5dd9c2b
LCC
981 return -ENOTSUPP;
982
983 rcu_read_lock();
f698d856 984 mpath = mesh_path_lookup_by_idx(idx, sdata);
c5dd9c2b
LCC
985 if (!mpath) {
986 rcu_read_unlock();
987 return -ENOENT;
988 }
989 memcpy(dst, mpath->dst, ETH_ALEN);
990 mpath_set_pinfo(mpath, next_hop, pinfo);
991 rcu_read_unlock();
992 return 0;
993}
93da9cc1 994
995static int ieee80211_get_mesh_params(struct wiphy *wiphy,
996 struct net_device *dev,
997 struct mesh_config *conf)
998{
999 struct ieee80211_sub_if_data *sdata;
1000 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1001
1002 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
1003 return -ENOTSUPP;
1004 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1005 return 0;
1006}
1007
1008static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1009{
1010 return (mask >> (parm-1)) & 0x1;
1011}
1012
1013static int ieee80211_set_mesh_params(struct wiphy *wiphy,
1014 struct net_device *dev,
1015 const struct mesh_config *nconf, u32 mask)
1016{
1017 struct mesh_config *conf;
1018 struct ieee80211_sub_if_data *sdata;
1019 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1020
1021 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
1022 return -ENOTSUPP;
1023
1024 /* Set the config options which we are interested in setting */
1025 conf = &(sdata->u.mesh.mshcfg);
1026 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1027 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1028 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1029 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1030 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1031 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1032 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1033 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1034 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1035 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1036 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1037 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1038 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1039 conf->auto_open_plinks = nconf->auto_open_plinks;
1040 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1041 conf->dot11MeshHWMPmaxPREQretries =
1042 nconf->dot11MeshHWMPmaxPREQretries;
1043 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1044 conf->path_refresh_time = nconf->path_refresh_time;
1045 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1046 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1047 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1048 conf->dot11MeshHWMPactivePathTimeout =
1049 nconf->dot11MeshHWMPactivePathTimeout;
1050 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1051 conf->dot11MeshHWMPpreqMinInterval =
1052 nconf->dot11MeshHWMPpreqMinInterval;
1053 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1054 mask))
1055 conf->dot11MeshHWMPnetDiameterTraversalTime =
1056 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1057 return 0;
1058}
1059
c5dd9c2b
LCC
1060#endif
1061
9f1ba906
JM
1062static int ieee80211_change_bss(struct wiphy *wiphy,
1063 struct net_device *dev,
1064 struct bss_parameters *params)
1065{
9f1ba906
JM
1066 struct ieee80211_sub_if_data *sdata;
1067 u32 changed = 0;
1068
9f1ba906
JM
1069 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1070
05c914fe 1071 if (sdata->vif.type != NL80211_IFTYPE_AP)
9f1ba906
JM
1072 return -EINVAL;
1073
1074 if (params->use_cts_prot >= 0) {
bda3933a 1075 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
9f1ba906
JM
1076 changed |= BSS_CHANGED_ERP_CTS_PROT;
1077 }
1078 if (params->use_short_preamble >= 0) {
bda3933a 1079 sdata->vif.bss_conf.use_short_preamble =
9f1ba906
JM
1080 params->use_short_preamble;
1081 changed |= BSS_CHANGED_ERP_PREAMBLE;
1082 }
1083 if (params->use_short_slot_time >= 0) {
bda3933a 1084 sdata->vif.bss_conf.use_short_slot =
9f1ba906
JM
1085 params->use_short_slot_time;
1086 changed |= BSS_CHANGED_ERP_SLOT;
1087 }
1088
90c97a04
JM
1089 if (params->basic_rates) {
1090 int i, j;
1091 u32 rates = 0;
1092 struct ieee80211_local *local = wiphy_priv(wiphy);
1093 struct ieee80211_supported_band *sband =
1094 wiphy->bands[local->oper_channel->band];
1095
1096 for (i = 0; i < params->basic_rates_len; i++) {
1097 int rate = (params->basic_rates[i] & 0x7f) * 5;
1098 for (j = 0; j < sband->n_bitrates; j++) {
1099 if (sband->bitrates[j].bitrate == rate)
1100 rates |= BIT(j);
1101 }
1102 }
1103 sdata->vif.bss_conf.basic_rates = rates;
1104 changed |= BSS_CHANGED_BASIC_RATES;
1105 }
1106
9f1ba906
JM
1107 ieee80211_bss_info_change_notify(sdata, changed);
1108
1109 return 0;
1110}
1111
31888487
JM
1112static int ieee80211_set_txq_params(struct wiphy *wiphy,
1113 struct ieee80211_txq_params *params)
1114{
1115 struct ieee80211_local *local = wiphy_priv(wiphy);
1116 struct ieee80211_tx_queue_params p;
1117
1118 if (!local->ops->conf_tx)
1119 return -EOPNOTSUPP;
1120
1121 memset(&p, 0, sizeof(p));
1122 p.aifs = params->aifs;
1123 p.cw_max = params->cwmax;
1124 p.cw_min = params->cwmin;
1125 p.txop = params->txop;
1126 if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
1127 printk(KERN_DEBUG "%s: failed to set TX queue "
1128 "parameters for queue %d\n", local->mdev->name,
1129 params->queue);
1130 return -EINVAL;
1131 }
1132
1133 return 0;
1134}
1135
72bdcf34
JM
1136static int ieee80211_set_channel(struct wiphy *wiphy,
1137 struct ieee80211_channel *chan,
094d05dc 1138 enum nl80211_channel_type channel_type)
72bdcf34
JM
1139{
1140 struct ieee80211_local *local = wiphy_priv(wiphy);
1141
1142 local->oper_channel = chan;
094d05dc 1143 local->oper_channel_type = channel_type;
72bdcf34
JM
1144
1145 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1146}
1147
f0706e82
JB
1148struct cfg80211_ops mac80211_config_ops = {
1149 .add_virtual_intf = ieee80211_add_iface,
1150 .del_virtual_intf = ieee80211_del_iface,
42613db7 1151 .change_virtual_intf = ieee80211_change_iface,
e8cbb4cb
JB
1152 .add_key = ieee80211_add_key,
1153 .del_key = ieee80211_del_key,
62da92fb 1154 .get_key = ieee80211_get_key,
e8cbb4cb 1155 .set_default_key = ieee80211_config_default_key,
5dfdaf58
JB
1156 .add_beacon = ieee80211_add_beacon,
1157 .set_beacon = ieee80211_set_beacon,
1158 .del_beacon = ieee80211_del_beacon,
4fd6931e
JB
1159 .add_station = ieee80211_add_station,
1160 .del_station = ieee80211_del_station,
1161 .change_station = ieee80211_change_station,
7bbdd2d9 1162 .get_station = ieee80211_get_station,
c5dd9c2b
LCC
1163 .dump_station = ieee80211_dump_station,
1164#ifdef CONFIG_MAC80211_MESH
1165 .add_mpath = ieee80211_add_mpath,
1166 .del_mpath = ieee80211_del_mpath,
1167 .change_mpath = ieee80211_change_mpath,
1168 .get_mpath = ieee80211_get_mpath,
1169 .dump_mpath = ieee80211_dump_mpath,
93da9cc1 1170 .set_mesh_params = ieee80211_set_mesh_params,
1171 .get_mesh_params = ieee80211_get_mesh_params,
c5dd9c2b 1172#endif
9f1ba906 1173 .change_bss = ieee80211_change_bss,
31888487 1174 .set_txq_params = ieee80211_set_txq_params,
72bdcf34 1175 .set_channel = ieee80211_set_channel,
f0706e82 1176};