ucc_geth: Remove UGETH_FILTERING dead code
[linux-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 |
313 STATION_INFO_TX_BYTES;
314
315 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
316 sinfo->rx_bytes = sta->rx_bytes;
317 sinfo->tx_bytes = sta->tx_bytes;
318
902acc78 319 if (ieee80211_vif_is_mesh(&sdata->vif)) {
c5dd9c2b 320#ifdef CONFIG_MAC80211_MESH
c5dd9c2b
LCC
321 sinfo->filled |= STATION_INFO_LLID |
322 STATION_INFO_PLID |
323 STATION_INFO_PLINK_STATE;
324
325 sinfo->llid = le16_to_cpu(sta->llid);
326 sinfo->plid = le16_to_cpu(sta->plid);
327 sinfo->plink_state = sta->plink_state;
c5dd9c2b 328#endif
902acc78 329 }
c5dd9c2b
LCC
330}
331
332
333static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
334 int idx, u8 *mac, struct station_info *sinfo)
335{
336 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
337 struct sta_info *sta;
d0709a65
JB
338 int ret = -ENOENT;
339
340 rcu_read_lock();
c5dd9c2b
LCC
341
342 sta = sta_info_get_by_idx(local, idx, dev);
d0709a65
JB
343 if (sta) {
344 ret = 0;
17741cdc 345 memcpy(mac, sta->sta.addr, ETH_ALEN);
d0709a65
JB
346 sta_set_sinfo(sta, sinfo);
347 }
c5dd9c2b 348
d0709a65 349 rcu_read_unlock();
c5dd9c2b 350
d0709a65 351 return ret;
c5dd9c2b
LCC
352}
353
7bbdd2d9 354static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
2ec600d6 355 u8 *mac, struct station_info *sinfo)
7bbdd2d9
JB
356{
357 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
358 struct sta_info *sta;
d0709a65 359 int ret = -ENOENT;
7bbdd2d9 360
d0709a65 361 rcu_read_lock();
7bbdd2d9
JB
362
363 /* XXX: verify sta->dev == dev */
7bbdd2d9 364
d0709a65
JB
365 sta = sta_info_get(local, mac);
366 if (sta) {
367 ret = 0;
368 sta_set_sinfo(sta, sinfo);
369 }
370
371 rcu_read_unlock();
372
373 return ret;
7bbdd2d9
JB
374}
375
5dfdaf58
JB
376/*
377 * This handles both adding a beacon and setting new beacon info
378 */
379static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
380 struct beacon_parameters *params)
381{
382 struct beacon_data *new, *old;
383 int new_head_len, new_tail_len;
384 int size;
385 int err = -EINVAL;
386
387 old = sdata->u.ap.beacon;
388
389 /* head must not be zero-length */
390 if (params->head && !params->head_len)
391 return -EINVAL;
392
393 /*
394 * This is a kludge. beacon interval should really be part
395 * of the beacon information.
396 */
397 if (params->interval) {
398 sdata->local->hw.conf.beacon_int = params->interval;
447107fb
RC
399 err = ieee80211_hw_config(sdata->local,
400 IEEE80211_CONF_CHANGE_BEACON_INTERVAL);
401 if (err < 0)
402 return err;
5dfdaf58
JB
403 /*
404 * We updated some parameter so if below bails out
405 * it's not an error.
406 */
407 err = 0;
408 }
409
410 /* Need to have a beacon head if we don't have one yet */
411 if (!params->head && !old)
412 return err;
413
414 /* sorry, no way to start beaconing without dtim period */
415 if (!params->dtim_period && !old)
416 return err;
417
418 /* new or old head? */
419 if (params->head)
420 new_head_len = params->head_len;
421 else
422 new_head_len = old->head_len;
423
424 /* new or old tail? */
425 if (params->tail || !old)
426 /* params->tail_len will be zero for !params->tail */
427 new_tail_len = params->tail_len;
428 else
429 new_tail_len = old->tail_len;
430
431 size = sizeof(*new) + new_head_len + new_tail_len;
432
433 new = kzalloc(size, GFP_KERNEL);
434 if (!new)
435 return -ENOMEM;
436
437 /* start filling the new info now */
438
439 /* new or old dtim period? */
440 if (params->dtim_period)
441 new->dtim_period = params->dtim_period;
442 else
443 new->dtim_period = old->dtim_period;
444
445 /*
446 * pointers go into the block we allocated,
447 * memory is | beacon_data | head | tail |
448 */
449 new->head = ((u8 *) new) + sizeof(*new);
450 new->tail = new->head + new_head_len;
451 new->head_len = new_head_len;
452 new->tail_len = new_tail_len;
453
454 /* copy in head */
455 if (params->head)
456 memcpy(new->head, params->head, new_head_len);
457 else
458 memcpy(new->head, old->head, new_head_len);
459
460 /* copy in optional tail */
461 if (params->tail)
462 memcpy(new->tail, params->tail, new_tail_len);
463 else
464 if (old)
465 memcpy(new->tail, old->tail, new_tail_len);
466
467 rcu_assign_pointer(sdata->u.ap.beacon, new);
468
469 synchronize_rcu();
470
471 kfree(old);
472
9d139c81 473 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
5dfdaf58
JB
474}
475
476static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
477 struct beacon_parameters *params)
478{
14db74bc 479 struct ieee80211_sub_if_data *sdata;
5dfdaf58
JB
480 struct beacon_data *old;
481
14db74bc
JB
482 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
483
05c914fe 484 if (sdata->vif.type != NL80211_IFTYPE_AP)
5dfdaf58
JB
485 return -EINVAL;
486
487 old = sdata->u.ap.beacon;
488
489 if (old)
490 return -EALREADY;
491
492 return ieee80211_config_beacon(sdata, params);
493}
494
495static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
496 struct beacon_parameters *params)
497{
14db74bc 498 struct ieee80211_sub_if_data *sdata;
5dfdaf58
JB
499 struct beacon_data *old;
500
14db74bc
JB
501 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
502
05c914fe 503 if (sdata->vif.type != NL80211_IFTYPE_AP)
5dfdaf58
JB
504 return -EINVAL;
505
506 old = sdata->u.ap.beacon;
507
508 if (!old)
509 return -ENOENT;
510
511 return ieee80211_config_beacon(sdata, params);
512}
513
514static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
515{
14db74bc 516 struct ieee80211_sub_if_data *sdata;
5dfdaf58
JB
517 struct beacon_data *old;
518
14db74bc
JB
519 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
520
05c914fe 521 if (sdata->vif.type != NL80211_IFTYPE_AP)
5dfdaf58
JB
522 return -EINVAL;
523
524 old = sdata->u.ap.beacon;
525
526 if (!old)
527 return -ENOENT;
528
529 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
530 synchronize_rcu();
531 kfree(old);
532
9d139c81 533 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
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];
545} __attribute__ ((packed));
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
JB
576 memset(skb->cb, 0, sizeof(skb->cb));
577 netif_rx(skb);
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;
4fd6931e 588
ae5eb026
JB
589 sband = local->hw.wiphy->bands[local->oper_channel->band];
590
73651ee6
JB
591 /*
592 * FIXME: updating the flags is racy when this function is
593 * called from ieee80211_change_station(), this will
594 * be resolved in a future patch.
595 */
596
4fd6931e 597 if (params->station_flags & STATION_FLAG_CHANGED) {
07346f81 598 spin_lock_bh(&sta->lock);
4fd6931e
JB
599 sta->flags &= ~WLAN_STA_AUTHORIZED;
600 if (params->station_flags & STATION_FLAG_AUTHORIZED)
601 sta->flags |= WLAN_STA_AUTHORIZED;
602
603 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
604 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
605 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
606
607 sta->flags &= ~WLAN_STA_WME;
608 if (params->station_flags & STATION_FLAG_WME)
609 sta->flags |= WLAN_STA_WME;
07346f81 610 spin_unlock_bh(&sta->lock);
4fd6931e
JB
611 }
612
73651ee6
JB
613 /*
614 * FIXME: updating the following information is racy when this
615 * function is called from ieee80211_change_station().
616 * However, all this information should be static so
617 * maybe we should just reject attemps to change it.
618 */
619
4fd6931e 620 if (params->aid) {
17741cdc
JB
621 sta->sta.aid = params->aid;
622 if (sta->sta.aid > IEEE80211_MAX_AID)
623 sta->sta.aid = 0; /* XXX: should this be an error? */
4fd6931e
JB
624 }
625
626 if (params->listen_interval >= 0)
627 sta->listen_interval = params->listen_interval;
628
629 if (params->supported_rates) {
630 rates = 0;
8318d78a 631
4fd6931e
JB
632 for (i = 0; i < params->supported_rates_len; i++) {
633 int rate = (params->supported_rates[i] & 0x7f) * 5;
8318d78a
JB
634 for (j = 0; j < sband->n_bitrates; j++) {
635 if (sband->bitrates[j].bitrate == rate)
4fd6931e
JB
636 rates |= BIT(j);
637 }
638 }
323ce79a 639 sta->sta.supp_rates[local->oper_channel->band] = rates;
4fd6931e 640 }
c5dd9c2b 641
d9fe60de 642 if (params->ht_capa)
ae5eb026
JB
643 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
644 params->ht_capa,
d9fe60de 645 &sta->sta.ht_cap);
36aedc90 646
902acc78 647 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
c5dd9c2b
LCC
648 switch (params->plink_action) {
649 case PLINK_ACTION_OPEN:
650 mesh_plink_open(sta);
651 break;
652 case PLINK_ACTION_BLOCK:
653 mesh_plink_block(sta);
654 break;
655 }
902acc78 656 }
4fd6931e
JB
657}
658
659static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
660 u8 *mac, struct station_parameters *params)
661{
14db74bc 662 struct ieee80211_local *local = wiphy_priv(wiphy);
4fd6931e
JB
663 struct sta_info *sta;
664 struct ieee80211_sub_if_data *sdata;
73651ee6 665 int err;
4fd6931e
JB
666
667 /* Prevent a race with changing the rate control algorithm */
668 if (!netif_running(dev))
669 return -ENETDOWN;
670
4fd6931e
JB
671 if (params->vlan) {
672 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
673
05c914fe
JB
674 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
675 sdata->vif.type != NL80211_IFTYPE_AP)
4fd6931e
JB
676 return -EINVAL;
677 } else
678 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
679
03e4497e
JB
680 if (compare_ether_addr(mac, dev->dev_addr) == 0)
681 return -EINVAL;
682
683 if (is_multicast_ether_addr(mac))
684 return -EINVAL;
685
686 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
73651ee6
JB
687 if (!sta)
688 return -ENOMEM;
4fd6931e
JB
689
690 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
691
692 sta_apply_parameters(local, sta, params);
693
4b7679a5 694 rate_control_rate_init(sta);
4fd6931e 695
73651ee6
JB
696 rcu_read_lock();
697
698 err = sta_info_insert(sta);
699 if (err) {
93e5deb1 700 /* STA has been freed */
73651ee6
JB
701 rcu_read_unlock();
702 return err;
703 }
704
05c914fe
JB
705 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
706 sdata->vif.type == NL80211_IFTYPE_AP)
73651ee6
JB
707 ieee80211_send_layer2_update(sta);
708
709 rcu_read_unlock();
710
4fd6931e
JB
711 return 0;
712}
713
714static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
715 u8 *mac)
716{
14db74bc
JB
717 struct ieee80211_local *local = wiphy_priv(wiphy);
718 struct ieee80211_sub_if_data *sdata;
4fd6931e
JB
719 struct sta_info *sta;
720
14db74bc
JB
721 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
722
4fd6931e 723 if (mac) {
98dd6a57
JB
724 rcu_read_lock();
725
4fd6931e
JB
726 /* XXX: get sta belonging to dev */
727 sta = sta_info_get(local, mac);
98dd6a57
JB
728 if (!sta) {
729 rcu_read_unlock();
4fd6931e 730 return -ENOENT;
98dd6a57 731 }
4fd6931e 732
d0709a65 733 sta_info_unlink(&sta);
98dd6a57
JB
734 rcu_read_unlock();
735
4f6fab47 736 sta_info_destroy(sta);
4fd6931e 737 } else
d0709a65 738 sta_info_flush(local, sdata);
4fd6931e
JB
739
740 return 0;
741}
742
743static int ieee80211_change_station(struct wiphy *wiphy,
744 struct net_device *dev,
745 u8 *mac,
746 struct station_parameters *params)
747{
14db74bc 748 struct ieee80211_local *local = wiphy_priv(wiphy);
4fd6931e
JB
749 struct sta_info *sta;
750 struct ieee80211_sub_if_data *vlansdata;
751
98dd6a57
JB
752 rcu_read_lock();
753
4fd6931e
JB
754 /* XXX: get sta belonging to dev */
755 sta = sta_info_get(local, mac);
98dd6a57
JB
756 if (!sta) {
757 rcu_read_unlock();
4fd6931e 758 return -ENOENT;
98dd6a57 759 }
4fd6931e 760
d0709a65 761 if (params->vlan && params->vlan != sta->sdata->dev) {
4fd6931e
JB
762 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
763
05c914fe
JB
764 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
765 vlansdata->vif.type != NL80211_IFTYPE_AP) {
98dd6a57 766 rcu_read_unlock();
4fd6931e 767 return -EINVAL;
98dd6a57 768 }
4fd6931e 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
JB
785 struct ieee80211_local *local = wiphy_priv(wiphy);
786 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
787 struct mesh_path *mpath;
788 struct sta_info *sta;
789 int err;
790
791 if (!netif_running(dev))
792 return -ENETDOWN;
793
14db74bc
JB
794 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
795
05c914fe 796 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
c5dd9c2b
LCC
797 return -ENOTSUPP;
798
d0709a65 799 rcu_read_lock();
c5dd9c2b 800 sta = sta_info_get(local, next_hop);
d0709a65
JB
801 if (!sta) {
802 rcu_read_unlock();
c5dd9c2b 803 return -ENOENT;
d0709a65 804 }
c5dd9c2b 805
f698d856 806 err = mesh_path_add(dst, sdata);
d0709a65
JB
807 if (err) {
808 rcu_read_unlock();
c5dd9c2b 809 return err;
d0709a65 810 }
c5dd9c2b 811
f698d856 812 mpath = mesh_path_lookup(dst, sdata);
c5dd9c2b
LCC
813 if (!mpath) {
814 rcu_read_unlock();
c5dd9c2b
LCC
815 return -ENXIO;
816 }
817 mesh_path_fix_nexthop(mpath, sta);
d0709a65 818
c5dd9c2b
LCC
819 rcu_read_unlock();
820 return 0;
821}
822
823static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
824 u8 *dst)
825{
f698d856
JBG
826 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
827
c5dd9c2b 828 if (dst)
f698d856 829 return mesh_path_del(dst, sdata);
c5dd9c2b 830
f698d856 831 mesh_path_flush(sdata);
c5dd9c2b
LCC
832 return 0;
833}
834
835static int ieee80211_change_mpath(struct wiphy *wiphy,
836 struct net_device *dev,
837 u8 *dst, u8 *next_hop)
838{
14db74bc
JB
839 struct ieee80211_local *local = wiphy_priv(wiphy);
840 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
841 struct mesh_path *mpath;
842 struct sta_info *sta;
843
844 if (!netif_running(dev))
845 return -ENETDOWN;
846
14db74bc
JB
847 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
848
05c914fe 849 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
c5dd9c2b
LCC
850 return -ENOTSUPP;
851
d0709a65
JB
852 rcu_read_lock();
853
c5dd9c2b 854 sta = sta_info_get(local, next_hop);
d0709a65
JB
855 if (!sta) {
856 rcu_read_unlock();
c5dd9c2b 857 return -ENOENT;
d0709a65 858 }
c5dd9c2b 859
f698d856 860 mpath = mesh_path_lookup(dst, sdata);
c5dd9c2b
LCC
861 if (!mpath) {
862 rcu_read_unlock();
c5dd9c2b
LCC
863 return -ENOENT;
864 }
865
866 mesh_path_fix_nexthop(mpath, sta);
d0709a65 867
c5dd9c2b
LCC
868 rcu_read_unlock();
869 return 0;
870}
871
872static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
873 struct mpath_info *pinfo)
874{
875 if (mpath->next_hop)
17741cdc 876 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
c5dd9c2b
LCC
877 else
878 memset(next_hop, 0, ETH_ALEN);
879
880 pinfo->filled = MPATH_INFO_FRAME_QLEN |
881 MPATH_INFO_DSN |
882 MPATH_INFO_METRIC |
883 MPATH_INFO_EXPTIME |
884 MPATH_INFO_DISCOVERY_TIMEOUT |
885 MPATH_INFO_DISCOVERY_RETRIES |
886 MPATH_INFO_FLAGS;
887
888 pinfo->frame_qlen = mpath->frame_queue.qlen;
889 pinfo->dsn = mpath->dsn;
890 pinfo->metric = mpath->metric;
891 if (time_before(jiffies, mpath->exp_time))
892 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
893 pinfo->discovery_timeout =
894 jiffies_to_msecs(mpath->discovery_timeout);
895 pinfo->discovery_retries = mpath->discovery_retries;
896 pinfo->flags = 0;
897 if (mpath->flags & MESH_PATH_ACTIVE)
898 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
899 if (mpath->flags & MESH_PATH_RESOLVING)
900 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
901 if (mpath->flags & MESH_PATH_DSN_VALID)
902 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
903 if (mpath->flags & MESH_PATH_FIXED)
904 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
905 if (mpath->flags & MESH_PATH_RESOLVING)
906 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
907
908 pinfo->flags = mpath->flags;
909}
910
911static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
912 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
913
914{
14db74bc 915 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
916 struct mesh_path *mpath;
917
14db74bc
JB
918 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
919
05c914fe 920 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
c5dd9c2b
LCC
921 return -ENOTSUPP;
922
923 rcu_read_lock();
f698d856 924 mpath = mesh_path_lookup(dst, sdata);
c5dd9c2b
LCC
925 if (!mpath) {
926 rcu_read_unlock();
927 return -ENOENT;
928 }
929 memcpy(dst, mpath->dst, ETH_ALEN);
930 mpath_set_pinfo(mpath, next_hop, pinfo);
931 rcu_read_unlock();
932 return 0;
933}
934
935static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
936 int idx, u8 *dst, u8 *next_hop,
937 struct mpath_info *pinfo)
938{
14db74bc 939 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
940 struct mesh_path *mpath;
941
14db74bc
JB
942 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
943
05c914fe 944 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
c5dd9c2b
LCC
945 return -ENOTSUPP;
946
947 rcu_read_lock();
f698d856 948 mpath = mesh_path_lookup_by_idx(idx, sdata);
c5dd9c2b
LCC
949 if (!mpath) {
950 rcu_read_unlock();
951 return -ENOENT;
952 }
953 memcpy(dst, mpath->dst, ETH_ALEN);
954 mpath_set_pinfo(mpath, next_hop, pinfo);
955 rcu_read_unlock();
956 return 0;
957}
93da9cc1 958
959static int ieee80211_get_mesh_params(struct wiphy *wiphy,
960 struct net_device *dev,
961 struct mesh_config *conf)
962{
963 struct ieee80211_sub_if_data *sdata;
964 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
965
966 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
967 return -ENOTSUPP;
968 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
969 return 0;
970}
971
972static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
973{
974 return (mask >> (parm-1)) & 0x1;
975}
976
977static int ieee80211_set_mesh_params(struct wiphy *wiphy,
978 struct net_device *dev,
979 const struct mesh_config *nconf, u32 mask)
980{
981 struct mesh_config *conf;
982 struct ieee80211_sub_if_data *sdata;
983 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
984
985 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
986 return -ENOTSUPP;
987
988 /* Set the config options which we are interested in setting */
989 conf = &(sdata->u.mesh.mshcfg);
990 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
991 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
992 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
993 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
994 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
995 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
996 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
997 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
998 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
999 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1000 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1001 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1002 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1003 conf->auto_open_plinks = nconf->auto_open_plinks;
1004 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1005 conf->dot11MeshHWMPmaxPREQretries =
1006 nconf->dot11MeshHWMPmaxPREQretries;
1007 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1008 conf->path_refresh_time = nconf->path_refresh_time;
1009 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1010 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1011 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1012 conf->dot11MeshHWMPactivePathTimeout =
1013 nconf->dot11MeshHWMPactivePathTimeout;
1014 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1015 conf->dot11MeshHWMPpreqMinInterval =
1016 nconf->dot11MeshHWMPpreqMinInterval;
1017 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1018 mask))
1019 conf->dot11MeshHWMPnetDiameterTraversalTime =
1020 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1021 return 0;
1022}
1023
c5dd9c2b
LCC
1024#endif
1025
9f1ba906
JM
1026static int ieee80211_change_bss(struct wiphy *wiphy,
1027 struct net_device *dev,
1028 struct bss_parameters *params)
1029{
9f1ba906
JM
1030 struct ieee80211_sub_if_data *sdata;
1031 u32 changed = 0;
1032
9f1ba906
JM
1033 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1034
05c914fe 1035 if (sdata->vif.type != NL80211_IFTYPE_AP)
9f1ba906
JM
1036 return -EINVAL;
1037
1038 if (params->use_cts_prot >= 0) {
bda3933a 1039 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
9f1ba906
JM
1040 changed |= BSS_CHANGED_ERP_CTS_PROT;
1041 }
1042 if (params->use_short_preamble >= 0) {
bda3933a 1043 sdata->vif.bss_conf.use_short_preamble =
9f1ba906
JM
1044 params->use_short_preamble;
1045 changed |= BSS_CHANGED_ERP_PREAMBLE;
1046 }
1047 if (params->use_short_slot_time >= 0) {
bda3933a 1048 sdata->vif.bss_conf.use_short_slot =
9f1ba906
JM
1049 params->use_short_slot_time;
1050 changed |= BSS_CHANGED_ERP_SLOT;
1051 }
1052
90c97a04
JM
1053 if (params->basic_rates) {
1054 int i, j;
1055 u32 rates = 0;
1056 struct ieee80211_local *local = wiphy_priv(wiphy);
1057 struct ieee80211_supported_band *sband =
1058 wiphy->bands[local->oper_channel->band];
1059
1060 for (i = 0; i < params->basic_rates_len; i++) {
1061 int rate = (params->basic_rates[i] & 0x7f) * 5;
1062 for (j = 0; j < sband->n_bitrates; j++) {
1063 if (sband->bitrates[j].bitrate == rate)
1064 rates |= BIT(j);
1065 }
1066 }
1067 sdata->vif.bss_conf.basic_rates = rates;
1068 changed |= BSS_CHANGED_BASIC_RATES;
1069 }
1070
9f1ba906
JM
1071 ieee80211_bss_info_change_notify(sdata, changed);
1072
1073 return 0;
1074}
1075
31888487
JM
1076static int ieee80211_set_txq_params(struct wiphy *wiphy,
1077 struct ieee80211_txq_params *params)
1078{
1079 struct ieee80211_local *local = wiphy_priv(wiphy);
1080 struct ieee80211_tx_queue_params p;
1081
1082 if (!local->ops->conf_tx)
1083 return -EOPNOTSUPP;
1084
1085 memset(&p, 0, sizeof(p));
1086 p.aifs = params->aifs;
1087 p.cw_max = params->cwmax;
1088 p.cw_min = params->cwmin;
1089 p.txop = params->txop;
1090 if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
1091 printk(KERN_DEBUG "%s: failed to set TX queue "
1092 "parameters for queue %d\n", local->mdev->name,
1093 params->queue);
1094 return -EINVAL;
1095 }
1096
1097 return 0;
1098}
1099
72bdcf34
JM
1100static int ieee80211_set_channel(struct wiphy *wiphy,
1101 struct ieee80211_channel *chan,
1102 enum nl80211_sec_chan_offset sec_chan_offset)
1103{
1104 struct ieee80211_local *local = wiphy_priv(wiphy);
1105
1106 local->oper_channel = chan;
1107 local->oper_sec_chan_offset = sec_chan_offset;
1108
1109 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1110}
1111
f0706e82
JB
1112struct cfg80211_ops mac80211_config_ops = {
1113 .add_virtual_intf = ieee80211_add_iface,
1114 .del_virtual_intf = ieee80211_del_iface,
42613db7 1115 .change_virtual_intf = ieee80211_change_iface,
e8cbb4cb
JB
1116 .add_key = ieee80211_add_key,
1117 .del_key = ieee80211_del_key,
62da92fb 1118 .get_key = ieee80211_get_key,
e8cbb4cb 1119 .set_default_key = ieee80211_config_default_key,
5dfdaf58
JB
1120 .add_beacon = ieee80211_add_beacon,
1121 .set_beacon = ieee80211_set_beacon,
1122 .del_beacon = ieee80211_del_beacon,
4fd6931e
JB
1123 .add_station = ieee80211_add_station,
1124 .del_station = ieee80211_del_station,
1125 .change_station = ieee80211_change_station,
7bbdd2d9 1126 .get_station = ieee80211_get_station,
c5dd9c2b
LCC
1127 .dump_station = ieee80211_dump_station,
1128#ifdef CONFIG_MAC80211_MESH
1129 .add_mpath = ieee80211_add_mpath,
1130 .del_mpath = ieee80211_del_mpath,
1131 .change_mpath = ieee80211_change_mpath,
1132 .get_mpath = ieee80211_get_mpath,
1133 .dump_mpath = ieee80211_dump_mpath,
93da9cc1 1134 .set_mesh_params = ieee80211_set_mesh_params,
1135 .get_mesh_params = ieee80211_get_mesh_params,
c5dd9c2b 1136#endif
9f1ba906 1137 .change_bss = ieee80211_change_bss,
31888487 1138 .set_txq_params = ieee80211_set_txq_params,
72bdcf34 1139 .set_channel = ieee80211_set_channel,
f0706e82 1140};