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