mac80211: share STA information with driver
[deliverable/linux.git] / net / mac80211 / cfg.c
1 /*
2 * mac80211 configuration hooks for cfg80211
3 *
4 * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
5 *
6 * This file is GPLv2 as found in COPYING.
7 */
8
9 #include <linux/ieee80211.h>
10 #include <linux/nl80211.h>
11 #include <linux/rtnetlink.h>
12 #include <net/net_namespace.h>
13 #include <linux/rcupdate.h>
14 #include <net/cfg80211.h>
15 #include "ieee80211_i.h"
16 #include "cfg.h"
17 #include "rate.h"
18 #include "mesh.h"
19
20 struct ieee80211_hw *wiphy_to_hw(struct wiphy *wiphy)
21 {
22 struct ieee80211_local *local = wiphy_priv(wiphy);
23 return &local->hw;
24 }
25 EXPORT_SYMBOL(wiphy_to_hw);
26
27 static bool nl80211_type_check(enum nl80211_iftype type)
28 {
29 switch (type) {
30 case NL80211_IFTYPE_ADHOC:
31 case NL80211_IFTYPE_STATION:
32 case NL80211_IFTYPE_MONITOR:
33 #ifdef CONFIG_MAC80211_MESH
34 case NL80211_IFTYPE_MESH_POINT:
35 #endif
36 case NL80211_IFTYPE_WDS:
37 return true;
38 default:
39 return false;
40 }
41 }
42
43 static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
44 enum nl80211_iftype type, u32 *flags,
45 struct vif_params *params)
46 {
47 struct ieee80211_local *local = wiphy_priv(wiphy);
48 struct net_device *dev;
49 struct ieee80211_sub_if_data *sdata;
50 int err;
51
52 if (!nl80211_type_check(type))
53 return -EINVAL;
54
55 err = ieee80211_if_add(local, name, &dev, type, params);
56 if (err || type != NL80211_IFTYPE_MONITOR || !flags)
57 return err;
58
59 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
60 sdata->u.mntr_flags = *flags;
61 return 0;
62 }
63
64 static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
65 {
66 struct net_device *dev;
67 struct ieee80211_sub_if_data *sdata;
68
69 /* we're under RTNL */
70 dev = __dev_get_by_index(&init_net, ifindex);
71 if (!dev)
72 return -ENODEV;
73
74 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
75
76 ieee80211_if_remove(sdata);
77
78 return 0;
79 }
80
81 static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
82 enum nl80211_iftype type, u32 *flags,
83 struct vif_params *params)
84 {
85 struct ieee80211_local *local = wiphy_priv(wiphy);
86 struct net_device *dev;
87 struct ieee80211_sub_if_data *sdata;
88 int ret;
89
90 /* we're under RTNL */
91 dev = __dev_get_by_index(&init_net, ifindex);
92 if (!dev)
93 return -ENODEV;
94
95 if (!nl80211_type_check(type))
96 return -EINVAL;
97
98 if (dev == local->mdev)
99 return -EOPNOTSUPP;
100
101 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
102
103 ret = ieee80211_if_change_type(sdata, type);
104 if (ret)
105 return ret;
106
107 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
108 ieee80211_sdata_set_mesh_id(sdata,
109 params->mesh_id_len,
110 params->mesh_id);
111
112 if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
113 return 0;
114
115 sdata->u.mntr_flags = *flags;
116 return 0;
117 }
118
119 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
120 u8 key_idx, u8 *mac_addr,
121 struct key_params *params)
122 {
123 struct ieee80211_local *local = wiphy_priv(wiphy);
124 struct ieee80211_sub_if_data *sdata;
125 struct sta_info *sta = NULL;
126 enum ieee80211_key_alg alg;
127 struct ieee80211_key *key;
128 int err;
129
130 if (dev == local->mdev)
131 return -EOPNOTSUPP;
132
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
150 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
151 if (!key)
152 return -ENOMEM;
153
154 rcu_read_lock();
155
156 if (mac_addr) {
157 sta = sta_info_get(sdata->local, mac_addr);
158 if (!sta) {
159 ieee80211_key_free(key);
160 err = -ENOENT;
161 goto out_unlock;
162 }
163 }
164
165 ieee80211_key_link(key, sdata, sta);
166
167 err = 0;
168 out_unlock:
169 rcu_read_unlock();
170
171 return err;
172 }
173
174 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
175 u8 key_idx, u8 *mac_addr)
176 {
177 struct ieee80211_local *local = wiphy_priv(wiphy);
178 struct ieee80211_sub_if_data *sdata;
179 struct sta_info *sta;
180 int ret;
181
182 if (dev == local->mdev)
183 return -EOPNOTSUPP;
184
185 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
186
187 rcu_read_lock();
188
189 if (mac_addr) {
190 ret = -ENOENT;
191
192 sta = sta_info_get(sdata->local, mac_addr);
193 if (!sta)
194 goto out_unlock;
195
196 if (sta->key) {
197 ieee80211_key_free(sta->key);
198 WARN_ON(sta->key);
199 ret = 0;
200 }
201
202 goto out_unlock;
203 }
204
205 if (!sdata->keys[key_idx]) {
206 ret = -ENOENT;
207 goto out_unlock;
208 }
209
210 ieee80211_key_free(sdata->keys[key_idx]);
211 WARN_ON(sdata->keys[key_idx]);
212
213 ret = 0;
214 out_unlock:
215 rcu_read_unlock();
216
217 return ret;
218 }
219
220 static 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 {
225 struct ieee80211_local *local = wiphy_priv(wiphy);
226 struct ieee80211_sub_if_data *sdata;
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
235 if (dev == local->mdev)
236 return -EOPNOTSUPP;
237
238 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
239
240 rcu_read_lock();
241
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
260 iv32 = key->u.tkip.tx.iv32;
261 iv16 = key->u.tkip.tx.iv16;
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:
305 rcu_read_unlock();
306 return err;
307 }
308
309 static int ieee80211_config_default_key(struct wiphy *wiphy,
310 struct net_device *dev,
311 u8 key_idx)
312 {
313 struct ieee80211_local *local = wiphy_priv(wiphy);
314 struct ieee80211_sub_if_data *sdata;
315
316 if (dev == local->mdev)
317 return -EOPNOTSUPP;
318
319 rcu_read_lock();
320
321 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
322 ieee80211_set_default_key(sdata, key_idx);
323
324 rcu_read_unlock();
325
326 return 0;
327 }
328
329 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
330 {
331 struct ieee80211_sub_if_data *sdata = sta->sdata;
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
341 if (ieee80211_vif_is_mesh(&sdata->vif)) {
342 #ifdef CONFIG_MAC80211_MESH
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;
350 #endif
351 }
352 }
353
354
355 static 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;
360 int ret = -ENOENT;
361
362 rcu_read_lock();
363
364 sta = sta_info_get_by_idx(local, idx, dev);
365 if (sta) {
366 ret = 0;
367 memcpy(mac, sta->sta.addr, ETH_ALEN);
368 sta_set_sinfo(sta, sinfo);
369 }
370
371 rcu_read_unlock();
372
373 return ret;
374 }
375
376 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
377 u8 *mac, struct station_info *sinfo)
378 {
379 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
380 struct sta_info *sta;
381 int ret = -ENOENT;
382
383 rcu_read_lock();
384
385 /* XXX: verify sta->dev == dev */
386
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;
396 }
397
398 /*
399 * This handles both adding a beacon and setting new beacon info
400 */
401 static 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
493 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
494 }
495
496 static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
497 struct beacon_parameters *params)
498 {
499 struct ieee80211_local *local = wiphy_priv(wiphy);
500 struct ieee80211_sub_if_data *sdata;
501 struct beacon_data *old;
502
503 if (dev == local->mdev)
504 return -EOPNOTSUPP;
505
506 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
507
508 if (sdata->vif.type != NL80211_IFTYPE_AP)
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
519 static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
520 struct beacon_parameters *params)
521 {
522 struct ieee80211_local *local = wiphy_priv(wiphy);
523 struct ieee80211_sub_if_data *sdata;
524 struct beacon_data *old;
525
526 if (dev == local->mdev)
527 return -EOPNOTSUPP;
528
529 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
530
531 if (sdata->vif.type != NL80211_IFTYPE_AP)
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
542 static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
543 {
544 struct ieee80211_local *local = wiphy_priv(wiphy);
545 struct ieee80211_sub_if_data *sdata;
546 struct beacon_data *old;
547
548 if (dev == local->mdev)
549 return -EOPNOTSUPP;
550
551 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
552
553 if (sdata->vif.type != NL80211_IFTYPE_AP)
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
565 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
566 }
567
568 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
569 struct 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
579 static 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);
596 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
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
606 skb->dev = sta->sdata->dev;
607 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
608 memset(skb->cb, 0, sizeof(skb->cb));
609 netif_rx(skb);
610 }
611
612 static 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;
618 struct ieee80211_supported_band *sband;
619 struct ieee80211_sub_if_data *sdata = sta->sdata;
620
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
627 if (params->station_flags & STATION_FLAG_CHANGED) {
628 spin_lock_bh(&sta->lock);
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;
640 spin_unlock_bh(&sta->lock);
641 }
642
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
650 if (params->aid) {
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? */
654 }
655
656 if (params->listen_interval >= 0)
657 sta->listen_interval = params->listen_interval;
658
659 if (params->supported_rates) {
660 rates = 0;
661 sband = local->hw.wiphy->bands[local->oper_channel->band];
662
663 for (i = 0; i < params->supported_rates_len; i++) {
664 int rate = (params->supported_rates[i] & 0x7f) * 5;
665 for (j = 0; j < sband->n_bitrates; j++) {
666 if (sband->bitrates[j].bitrate == rate)
667 rates |= BIT(j);
668 }
669 }
670 sta->supp_rates[local->oper_channel->band] = rates;
671 }
672
673 if (params->ht_capa) {
674 ieee80211_ht_cap_ie_to_ht_info(params->ht_capa,
675 &sta->ht_info);
676 }
677
678 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
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 }
687 }
688 }
689
690 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
691 u8 *mac, struct station_parameters *params)
692 {
693 struct ieee80211_local *local = wiphy_priv(wiphy);
694 struct sta_info *sta;
695 struct ieee80211_sub_if_data *sdata;
696 int err;
697
698 if (dev == local->mdev || params->vlan == local->mdev)
699 return -EOPNOTSUPP;
700
701 /* Prevent a race with changing the rate control algorithm */
702 if (!netif_running(dev))
703 return -ENETDOWN;
704
705 if (params->vlan) {
706 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
707
708 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
709 sdata->vif.type != NL80211_IFTYPE_AP)
710 return -EINVAL;
711 } else
712 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
713
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);
721 if (!sta)
722 return -ENOMEM;
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
730 rcu_read_lock();
731
732 err = sta_info_insert(sta);
733 if (err) {
734 /* STA has been freed */
735 rcu_read_unlock();
736 return err;
737 }
738
739 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
740 sdata->vif.type == NL80211_IFTYPE_AP)
741 ieee80211_send_layer2_update(sta);
742
743 rcu_read_unlock();
744
745 return 0;
746 }
747
748 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
749 u8 *mac)
750 {
751 struct ieee80211_local *local = wiphy_priv(wiphy);
752 struct ieee80211_sub_if_data *sdata;
753 struct sta_info *sta;
754
755 if (dev == local->mdev)
756 return -EOPNOTSUPP;
757
758 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
759
760 if (mac) {
761 rcu_read_lock();
762
763 /* XXX: get sta belonging to dev */
764 sta = sta_info_get(local, mac);
765 if (!sta) {
766 rcu_read_unlock();
767 return -ENOENT;
768 }
769
770 sta_info_unlink(&sta);
771 rcu_read_unlock();
772
773 sta_info_destroy(sta);
774 } else
775 sta_info_flush(local, sdata);
776
777 return 0;
778 }
779
780 static int ieee80211_change_station(struct wiphy *wiphy,
781 struct net_device *dev,
782 u8 *mac,
783 struct station_parameters *params)
784 {
785 struct ieee80211_local *local = wiphy_priv(wiphy);
786 struct sta_info *sta;
787 struct ieee80211_sub_if_data *vlansdata;
788
789 if (dev == local->mdev || params->vlan == local->mdev)
790 return -EOPNOTSUPP;
791
792 rcu_read_lock();
793
794 /* XXX: get sta belonging to dev */
795 sta = sta_info_get(local, mac);
796 if (!sta) {
797 rcu_read_unlock();
798 return -ENOENT;
799 }
800
801 if (params->vlan && params->vlan != sta->sdata->dev) {
802 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
803
804 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
805 vlansdata->vif.type != NL80211_IFTYPE_AP) {
806 rcu_read_unlock();
807 return -EINVAL;
808 }
809
810 sta->sdata = vlansdata;
811 ieee80211_send_layer2_update(sta);
812 }
813
814 sta_apply_parameters(local, sta, params);
815
816 rcu_read_unlock();
817
818 return 0;
819 }
820
821 #ifdef CONFIG_MAC80211_MESH
822 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
823 u8 *dst, u8 *next_hop)
824 {
825 struct ieee80211_local *local = wiphy_priv(wiphy);
826 struct ieee80211_sub_if_data *sdata;
827 struct mesh_path *mpath;
828 struct sta_info *sta;
829 int err;
830
831 if (dev == local->mdev)
832 return -EOPNOTSUPP;
833
834 if (!netif_running(dev))
835 return -ENETDOWN;
836
837 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
838
839 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
840 return -ENOTSUPP;
841
842 rcu_read_lock();
843 sta = sta_info_get(local, next_hop);
844 if (!sta) {
845 rcu_read_unlock();
846 return -ENOENT;
847 }
848
849 err = mesh_path_add(dst, sdata);
850 if (err) {
851 rcu_read_unlock();
852 return err;
853 }
854
855 mpath = mesh_path_lookup(dst, sdata);
856 if (!mpath) {
857 rcu_read_unlock();
858 return -ENXIO;
859 }
860 mesh_path_fix_nexthop(mpath, sta);
861
862 rcu_read_unlock();
863 return 0;
864 }
865
866 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
867 u8 *dst)
868 {
869 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
870
871 if (dst)
872 return mesh_path_del(dst, sdata);
873
874 mesh_path_flush(sdata);
875 return 0;
876 }
877
878 static int ieee80211_change_mpath(struct wiphy *wiphy,
879 struct net_device *dev,
880 u8 *dst, u8 *next_hop)
881 {
882 struct ieee80211_local *local = wiphy_priv(wiphy);
883 struct ieee80211_sub_if_data *sdata;
884 struct mesh_path *mpath;
885 struct sta_info *sta;
886
887 if (dev == local->mdev)
888 return -EOPNOTSUPP;
889
890 if (!netif_running(dev))
891 return -ENETDOWN;
892
893 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
894
895 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
896 return -ENOTSUPP;
897
898 rcu_read_lock();
899
900 sta = sta_info_get(local, next_hop);
901 if (!sta) {
902 rcu_read_unlock();
903 return -ENOENT;
904 }
905
906 mpath = mesh_path_lookup(dst, sdata);
907 if (!mpath) {
908 rcu_read_unlock();
909 return -ENOENT;
910 }
911
912 mesh_path_fix_nexthop(mpath, sta);
913
914 rcu_read_unlock();
915 return 0;
916 }
917
918 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
919 struct mpath_info *pinfo)
920 {
921 if (mpath->next_hop)
922 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
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
957 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
958 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
959
960 {
961 struct ieee80211_local *local = wiphy_priv(wiphy);
962 struct ieee80211_sub_if_data *sdata;
963 struct mesh_path *mpath;
964
965 if (dev == local->mdev)
966 return -EOPNOTSUPP;
967
968 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
969
970 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
971 return -ENOTSUPP;
972
973 rcu_read_lock();
974 mpath = mesh_path_lookup(dst, sdata);
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
985 static 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 {
989 struct ieee80211_local *local = wiphy_priv(wiphy);
990 struct ieee80211_sub_if_data *sdata;
991 struct mesh_path *mpath;
992
993 if (dev == local->mdev)
994 return -EOPNOTSUPP;
995
996 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
997
998 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
999 return -ENOTSUPP;
1000
1001 rcu_read_lock();
1002 mpath = mesh_path_lookup_by_idx(idx, sdata);
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
1014 static 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
1027 if (sdata->vif.type != NL80211_IFTYPE_AP)
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
1050 struct cfg80211_ops mac80211_config_ops = {
1051 .add_virtual_intf = ieee80211_add_iface,
1052 .del_virtual_intf = ieee80211_del_iface,
1053 .change_virtual_intf = ieee80211_change_iface,
1054 .add_key = ieee80211_add_key,
1055 .del_key = ieee80211_del_key,
1056 .get_key = ieee80211_get_key,
1057 .set_default_key = ieee80211_config_default_key,
1058 .add_beacon = ieee80211_add_beacon,
1059 .set_beacon = ieee80211_set_beacon,
1060 .del_beacon = ieee80211_del_beacon,
1061 .add_station = ieee80211_add_station,
1062 .del_station = ieee80211_del_station,
1063 .change_station = ieee80211_change_station,
1064 .get_station = ieee80211_get_station,
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
1073 .change_bss = ieee80211_change_bss,
1074 };
This page took 0.0821 seconds and 5 git commands to generate.