rtc: rtc-ds1286 and rtc-m48t35 need <linux/io.h>
[linux-2.6/verdex.git] / net / mac80211 / cfg.c
blob855126a3039daa16ae64ca60c8087e0439a0d61f
1 /*
2 * mac80211 configuration hooks for cfg80211
4 * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
6 * This file is GPLv2 as found in COPYING.
7 */
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"
20 struct ieee80211_hw *wiphy_to_hw(struct wiphy *wiphy)
22 struct ieee80211_local *local = wiphy_priv(wiphy);
23 return &local->hw;
25 EXPORT_SYMBOL(wiphy_to_hw);
27 static bool nl80211_type_check(enum nl80211_iftype type)
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;
43 static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
44 enum nl80211_iftype type, u32 *flags,
45 struct vif_params *params)
47 struct ieee80211_local *local = wiphy_priv(wiphy);
48 struct net_device *dev;
49 struct ieee80211_sub_if_data *sdata;
50 int err;
52 if (!nl80211_type_check(type))
53 return -EINVAL;
55 err = ieee80211_if_add(local, name, &dev, type, params);
56 if (err || type != NL80211_IFTYPE_MONITOR || !flags)
57 return err;
59 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
60 sdata->u.mntr_flags = *flags;
61 return 0;
64 static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
66 struct net_device *dev;
67 struct ieee80211_sub_if_data *sdata;
69 /* we're under RTNL */
70 dev = __dev_get_by_index(&init_net, ifindex);
71 if (!dev)
72 return -ENODEV;
74 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
76 ieee80211_if_remove(sdata);
78 return 0;
81 static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
82 enum nl80211_iftype type, u32 *flags,
83 struct vif_params *params)
85 struct net_device *dev;
86 struct ieee80211_sub_if_data *sdata;
87 int ret;
89 /* we're under RTNL */
90 dev = __dev_get_by_index(&init_net, ifindex);
91 if (!dev)
92 return -ENODEV;
94 if (!nl80211_type_check(type))
95 return -EINVAL;
97 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
99 ret = ieee80211_if_change_type(sdata, type);
100 if (ret)
101 return ret;
103 if (netif_running(sdata->dev))
104 return -EBUSY;
106 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
107 ieee80211_sdata_set_mesh_id(sdata,
108 params->mesh_id_len,
109 params->mesh_id);
111 if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
112 return 0;
114 sdata->u.mntr_flags = *flags;
115 return 0;
118 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
119 u8 key_idx, u8 *mac_addr,
120 struct key_params *params)
122 struct ieee80211_sub_if_data *sdata;
123 struct sta_info *sta = NULL;
124 enum ieee80211_key_alg alg;
125 struct ieee80211_key *key;
126 int err;
128 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
130 switch (params->cipher) {
131 case WLAN_CIPHER_SUITE_WEP40:
132 case WLAN_CIPHER_SUITE_WEP104:
133 alg = ALG_WEP;
134 break;
135 case WLAN_CIPHER_SUITE_TKIP:
136 alg = ALG_TKIP;
137 break;
138 case WLAN_CIPHER_SUITE_CCMP:
139 alg = ALG_CCMP;
140 break;
141 default:
142 return -EINVAL;
145 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
146 if (!key)
147 return -ENOMEM;
149 rcu_read_lock();
151 if (mac_addr) {
152 sta = sta_info_get(sdata->local, mac_addr);
153 if (!sta) {
154 ieee80211_key_free(key);
155 err = -ENOENT;
156 goto out_unlock;
160 ieee80211_key_link(key, sdata, sta);
162 err = 0;
163 out_unlock:
164 rcu_read_unlock();
166 return err;
169 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
170 u8 key_idx, u8 *mac_addr)
172 struct ieee80211_sub_if_data *sdata;
173 struct sta_info *sta;
174 int ret;
176 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
178 rcu_read_lock();
180 if (mac_addr) {
181 ret = -ENOENT;
183 sta = sta_info_get(sdata->local, mac_addr);
184 if (!sta)
185 goto out_unlock;
187 if (sta->key) {
188 ieee80211_key_free(sta->key);
189 WARN_ON(sta->key);
190 ret = 0;
193 goto out_unlock;
196 if (!sdata->keys[key_idx]) {
197 ret = -ENOENT;
198 goto out_unlock;
201 ieee80211_key_free(sdata->keys[key_idx]);
202 WARN_ON(sdata->keys[key_idx]);
204 ret = 0;
205 out_unlock:
206 rcu_read_unlock();
208 return ret;
211 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
212 u8 key_idx, u8 *mac_addr, void *cookie,
213 void (*callback)(void *cookie,
214 struct key_params *params))
216 struct ieee80211_sub_if_data *sdata;
217 struct sta_info *sta = NULL;
218 u8 seq[6] = {0};
219 struct key_params params;
220 struct ieee80211_key *key;
221 u32 iv32;
222 u16 iv16;
223 int err = -ENOENT;
225 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
227 rcu_read_lock();
229 if (mac_addr) {
230 sta = sta_info_get(sdata->local, mac_addr);
231 if (!sta)
232 goto out;
234 key = sta->key;
235 } else
236 key = sdata->keys[key_idx];
238 if (!key)
239 goto out;
241 memset(&params, 0, sizeof(params));
243 switch (key->conf.alg) {
244 case ALG_TKIP:
245 params.cipher = WLAN_CIPHER_SUITE_TKIP;
247 iv32 = key->u.tkip.tx.iv32;
248 iv16 = key->u.tkip.tx.iv16;
250 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
251 sdata->local->ops->get_tkip_seq)
252 sdata->local->ops->get_tkip_seq(
253 local_to_hw(sdata->local),
254 key->conf.hw_key_idx,
255 &iv32, &iv16);
257 seq[0] = iv16 & 0xff;
258 seq[1] = (iv16 >> 8) & 0xff;
259 seq[2] = iv32 & 0xff;
260 seq[3] = (iv32 >> 8) & 0xff;
261 seq[4] = (iv32 >> 16) & 0xff;
262 seq[5] = (iv32 >> 24) & 0xff;
263 params.seq = seq;
264 params.seq_len = 6;
265 break;
266 case ALG_CCMP:
267 params.cipher = WLAN_CIPHER_SUITE_CCMP;
268 seq[0] = key->u.ccmp.tx_pn[5];
269 seq[1] = key->u.ccmp.tx_pn[4];
270 seq[2] = key->u.ccmp.tx_pn[3];
271 seq[3] = key->u.ccmp.tx_pn[2];
272 seq[4] = key->u.ccmp.tx_pn[1];
273 seq[5] = key->u.ccmp.tx_pn[0];
274 params.seq = seq;
275 params.seq_len = 6;
276 break;
277 case ALG_WEP:
278 if (key->conf.keylen == 5)
279 params.cipher = WLAN_CIPHER_SUITE_WEP40;
280 else
281 params.cipher = WLAN_CIPHER_SUITE_WEP104;
282 break;
285 params.key = key->conf.key;
286 params.key_len = key->conf.keylen;
288 callback(cookie, &params);
289 err = 0;
291 out:
292 rcu_read_unlock();
293 return err;
296 static int ieee80211_config_default_key(struct wiphy *wiphy,
297 struct net_device *dev,
298 u8 key_idx)
300 struct ieee80211_sub_if_data *sdata;
302 rcu_read_lock();
304 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
305 ieee80211_set_default_key(sdata, key_idx);
307 rcu_read_unlock();
309 return 0;
312 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
314 struct ieee80211_sub_if_data *sdata = sta->sdata;
316 sinfo->filled = STATION_INFO_INACTIVE_TIME |
317 STATION_INFO_RX_BYTES |
318 STATION_INFO_TX_BYTES;
320 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
321 sinfo->rx_bytes = sta->rx_bytes;
322 sinfo->tx_bytes = sta->tx_bytes;
324 if (ieee80211_vif_is_mesh(&sdata->vif)) {
325 #ifdef CONFIG_MAC80211_MESH
326 sinfo->filled |= STATION_INFO_LLID |
327 STATION_INFO_PLID |
328 STATION_INFO_PLINK_STATE;
330 sinfo->llid = le16_to_cpu(sta->llid);
331 sinfo->plid = le16_to_cpu(sta->plid);
332 sinfo->plink_state = sta->plink_state;
333 #endif
338 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
339 int idx, u8 *mac, struct station_info *sinfo)
341 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
342 struct sta_info *sta;
343 int ret = -ENOENT;
345 rcu_read_lock();
347 sta = sta_info_get_by_idx(local, idx, dev);
348 if (sta) {
349 ret = 0;
350 memcpy(mac, sta->sta.addr, ETH_ALEN);
351 sta_set_sinfo(sta, sinfo);
354 rcu_read_unlock();
356 return ret;
359 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
360 u8 *mac, struct station_info *sinfo)
362 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
363 struct sta_info *sta;
364 int ret = -ENOENT;
366 rcu_read_lock();
368 /* XXX: verify sta->dev == dev */
370 sta = sta_info_get(local, mac);
371 if (sta) {
372 ret = 0;
373 sta_set_sinfo(sta, sinfo);
376 rcu_read_unlock();
378 return ret;
382 * This handles both adding a beacon and setting new beacon info
384 static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
385 struct beacon_parameters *params)
387 struct beacon_data *new, *old;
388 int new_head_len, new_tail_len;
389 int size;
390 int err = -EINVAL;
392 old = sdata->u.ap.beacon;
394 /* head must not be zero-length */
395 if (params->head && !params->head_len)
396 return -EINVAL;
399 * This is a kludge. beacon interval should really be part
400 * of the beacon information.
402 if (params->interval) {
403 sdata->local->hw.conf.beacon_int = params->interval;
404 if (ieee80211_hw_config(sdata->local))
405 return -EINVAL;
407 * We updated some parameter so if below bails out
408 * it's not an error.
410 err = 0;
413 /* Need to have a beacon head if we don't have one yet */
414 if (!params->head && !old)
415 return err;
417 /* sorry, no way to start beaconing without dtim period */
418 if (!params->dtim_period && !old)
419 return err;
421 /* new or old head? */
422 if (params->head)
423 new_head_len = params->head_len;
424 else
425 new_head_len = old->head_len;
427 /* new or old tail? */
428 if (params->tail || !old)
429 /* params->tail_len will be zero for !params->tail */
430 new_tail_len = params->tail_len;
431 else
432 new_tail_len = old->tail_len;
434 size = sizeof(*new) + new_head_len + new_tail_len;
436 new = kzalloc(size, GFP_KERNEL);
437 if (!new)
438 return -ENOMEM;
440 /* start filling the new info now */
442 /* new or old dtim period? */
443 if (params->dtim_period)
444 new->dtim_period = params->dtim_period;
445 else
446 new->dtim_period = old->dtim_period;
449 * pointers go into the block we allocated,
450 * memory is | beacon_data | head | tail |
452 new->head = ((u8 *) new) + sizeof(*new);
453 new->tail = new->head + new_head_len;
454 new->head_len = new_head_len;
455 new->tail_len = new_tail_len;
457 /* copy in head */
458 if (params->head)
459 memcpy(new->head, params->head, new_head_len);
460 else
461 memcpy(new->head, old->head, new_head_len);
463 /* copy in optional tail */
464 if (params->tail)
465 memcpy(new->tail, params->tail, new_tail_len);
466 else
467 if (old)
468 memcpy(new->tail, old->tail, new_tail_len);
470 rcu_assign_pointer(sdata->u.ap.beacon, new);
472 synchronize_rcu();
474 kfree(old);
476 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
479 static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
480 struct beacon_parameters *params)
482 struct ieee80211_sub_if_data *sdata;
483 struct beacon_data *old;
485 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
487 if (sdata->vif.type != NL80211_IFTYPE_AP)
488 return -EINVAL;
490 old = sdata->u.ap.beacon;
492 if (old)
493 return -EALREADY;
495 return ieee80211_config_beacon(sdata, params);
498 static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
499 struct beacon_parameters *params)
501 struct ieee80211_sub_if_data *sdata;
502 struct beacon_data *old;
504 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
506 if (sdata->vif.type != NL80211_IFTYPE_AP)
507 return -EINVAL;
509 old = sdata->u.ap.beacon;
511 if (!old)
512 return -ENOENT;
514 return ieee80211_config_beacon(sdata, params);
517 static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
519 struct ieee80211_sub_if_data *sdata;
520 struct beacon_data *old;
522 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
524 if (sdata->vif.type != NL80211_IFTYPE_AP)
525 return -EINVAL;
527 old = sdata->u.ap.beacon;
529 if (!old)
530 return -ENOENT;
532 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
533 synchronize_rcu();
534 kfree(old);
536 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
539 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
540 struct iapp_layer2_update {
541 u8 da[ETH_ALEN]; /* broadcast */
542 u8 sa[ETH_ALEN]; /* STA addr */
543 __be16 len; /* 6 */
544 u8 dsap; /* 0 */
545 u8 ssap; /* 0 */
546 u8 control;
547 u8 xid_info[3];
548 } __attribute__ ((packed));
550 static void ieee80211_send_layer2_update(struct sta_info *sta)
552 struct iapp_layer2_update *msg;
553 struct sk_buff *skb;
555 /* Send Level 2 Update Frame to update forwarding tables in layer 2
556 * bridge devices */
558 skb = dev_alloc_skb(sizeof(*msg));
559 if (!skb)
560 return;
561 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
563 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
564 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
566 memset(msg->da, 0xff, ETH_ALEN);
567 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
568 msg->len = htons(6);
569 msg->dsap = 0;
570 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
571 msg->control = 0xaf; /* XID response lsb.1111F101.
572 * F=0 (no poll command; unsolicited frame) */
573 msg->xid_info[0] = 0x81; /* XID format identifier */
574 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
575 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
577 skb->dev = sta->sdata->dev;
578 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
579 memset(skb->cb, 0, sizeof(skb->cb));
580 netif_rx(skb);
583 static void sta_apply_parameters(struct ieee80211_local *local,
584 struct sta_info *sta,
585 struct station_parameters *params)
587 u32 rates;
588 int i, j;
589 struct ieee80211_supported_band *sband;
590 struct ieee80211_sub_if_data *sdata = sta->sdata;
593 * FIXME: updating the flags is racy when this function is
594 * called from ieee80211_change_station(), this will
595 * be resolved in a future patch.
598 if (params->station_flags & STATION_FLAG_CHANGED) {
599 spin_lock_bh(&sta->lock);
600 sta->flags &= ~WLAN_STA_AUTHORIZED;
601 if (params->station_flags & STATION_FLAG_AUTHORIZED)
602 sta->flags |= WLAN_STA_AUTHORIZED;
604 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
605 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
606 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
608 sta->flags &= ~WLAN_STA_WME;
609 if (params->station_flags & STATION_FLAG_WME)
610 sta->flags |= WLAN_STA_WME;
611 spin_unlock_bh(&sta->lock);
615 * FIXME: updating the following information is racy when this
616 * function is called from ieee80211_change_station().
617 * However, all this information should be static so
618 * maybe we should just reject attemps to change it.
621 if (params->aid) {
622 sta->sta.aid = params->aid;
623 if (sta->sta.aid > IEEE80211_MAX_AID)
624 sta->sta.aid = 0; /* XXX: should this be an error? */
627 if (params->listen_interval >= 0)
628 sta->listen_interval = params->listen_interval;
630 if (params->supported_rates) {
631 rates = 0;
632 sband = local->hw.wiphy->bands[local->oper_channel->band];
634 for (i = 0; i < params->supported_rates_len; i++) {
635 int rate = (params->supported_rates[i] & 0x7f) * 5;
636 for (j = 0; j < sband->n_bitrates; j++) {
637 if (sband->bitrates[j].bitrate == rate)
638 rates |= BIT(j);
641 sta->sta.supp_rates[local->oper_channel->band] = rates;
644 if (params->ht_capa) {
645 ieee80211_ht_cap_ie_to_ht_info(params->ht_capa,
646 &sta->sta.ht_info);
649 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
650 switch (params->plink_action) {
651 case PLINK_ACTION_OPEN:
652 mesh_plink_open(sta);
653 break;
654 case PLINK_ACTION_BLOCK:
655 mesh_plink_block(sta);
656 break;
661 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
662 u8 *mac, struct station_parameters *params)
664 struct ieee80211_local *local = wiphy_priv(wiphy);
665 struct sta_info *sta;
666 struct ieee80211_sub_if_data *sdata;
667 int err;
669 /* Prevent a race with changing the rate control algorithm */
670 if (!netif_running(dev))
671 return -ENETDOWN;
673 if (params->vlan) {
674 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
676 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
677 sdata->vif.type != NL80211_IFTYPE_AP)
678 return -EINVAL;
679 } else
680 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
682 if (compare_ether_addr(mac, dev->dev_addr) == 0)
683 return -EINVAL;
685 if (is_multicast_ether_addr(mac))
686 return -EINVAL;
688 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
689 if (!sta)
690 return -ENOMEM;
692 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
694 sta_apply_parameters(local, sta, params);
696 rate_control_rate_init(sta);
698 rcu_read_lock();
700 err = sta_info_insert(sta);
701 if (err) {
702 /* STA has been freed */
703 rcu_read_unlock();
704 return err;
707 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
708 sdata->vif.type == NL80211_IFTYPE_AP)
709 ieee80211_send_layer2_update(sta);
711 rcu_read_unlock();
713 return 0;
716 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
717 u8 *mac)
719 struct ieee80211_local *local = wiphy_priv(wiphy);
720 struct ieee80211_sub_if_data *sdata;
721 struct sta_info *sta;
723 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
725 if (mac) {
726 rcu_read_lock();
728 /* XXX: get sta belonging to dev */
729 sta = sta_info_get(local, mac);
730 if (!sta) {
731 rcu_read_unlock();
732 return -ENOENT;
735 sta_info_unlink(&sta);
736 rcu_read_unlock();
738 sta_info_destroy(sta);
739 } else
740 sta_info_flush(local, sdata);
742 return 0;
745 static int ieee80211_change_station(struct wiphy *wiphy,
746 struct net_device *dev,
747 u8 *mac,
748 struct station_parameters *params)
750 struct ieee80211_local *local = wiphy_priv(wiphy);
751 struct sta_info *sta;
752 struct ieee80211_sub_if_data *vlansdata;
754 rcu_read_lock();
756 /* XXX: get sta belonging to dev */
757 sta = sta_info_get(local, mac);
758 if (!sta) {
759 rcu_read_unlock();
760 return -ENOENT;
763 if (params->vlan && params->vlan != sta->sdata->dev) {
764 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
766 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
767 vlansdata->vif.type != NL80211_IFTYPE_AP) {
768 rcu_read_unlock();
769 return -EINVAL;
772 sta->sdata = vlansdata;
773 ieee80211_send_layer2_update(sta);
776 sta_apply_parameters(local, sta, params);
778 rcu_read_unlock();
780 return 0;
783 #ifdef CONFIG_MAC80211_MESH
784 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
785 u8 *dst, u8 *next_hop)
787 struct ieee80211_local *local = wiphy_priv(wiphy);
788 struct ieee80211_sub_if_data *sdata;
789 struct mesh_path *mpath;
790 struct sta_info *sta;
791 int err;
793 if (!netif_running(dev))
794 return -ENETDOWN;
796 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
798 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
799 return -ENOTSUPP;
801 rcu_read_lock();
802 sta = sta_info_get(local, next_hop);
803 if (!sta) {
804 rcu_read_unlock();
805 return -ENOENT;
808 err = mesh_path_add(dst, sdata);
809 if (err) {
810 rcu_read_unlock();
811 return err;
814 mpath = mesh_path_lookup(dst, sdata);
815 if (!mpath) {
816 rcu_read_unlock();
817 return -ENXIO;
819 mesh_path_fix_nexthop(mpath, sta);
821 rcu_read_unlock();
822 return 0;
825 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
826 u8 *dst)
828 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
830 if (dst)
831 return mesh_path_del(dst, sdata);
833 mesh_path_flush(sdata);
834 return 0;
837 static int ieee80211_change_mpath(struct wiphy *wiphy,
838 struct net_device *dev,
839 u8 *dst, u8 *next_hop)
841 struct ieee80211_local *local = wiphy_priv(wiphy);
842 struct ieee80211_sub_if_data *sdata;
843 struct mesh_path *mpath;
844 struct sta_info *sta;
846 if (!netif_running(dev))
847 return -ENETDOWN;
849 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
851 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
852 return -ENOTSUPP;
854 rcu_read_lock();
856 sta = sta_info_get(local, next_hop);
857 if (!sta) {
858 rcu_read_unlock();
859 return -ENOENT;
862 mpath = mesh_path_lookup(dst, sdata);
863 if (!mpath) {
864 rcu_read_unlock();
865 return -ENOENT;
868 mesh_path_fix_nexthop(mpath, sta);
870 rcu_read_unlock();
871 return 0;
874 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
875 struct mpath_info *pinfo)
877 if (mpath->next_hop)
878 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
879 else
880 memset(next_hop, 0, ETH_ALEN);
882 pinfo->filled = MPATH_INFO_FRAME_QLEN |
883 MPATH_INFO_DSN |
884 MPATH_INFO_METRIC |
885 MPATH_INFO_EXPTIME |
886 MPATH_INFO_DISCOVERY_TIMEOUT |
887 MPATH_INFO_DISCOVERY_RETRIES |
888 MPATH_INFO_FLAGS;
890 pinfo->frame_qlen = mpath->frame_queue.qlen;
891 pinfo->dsn = mpath->dsn;
892 pinfo->metric = mpath->metric;
893 if (time_before(jiffies, mpath->exp_time))
894 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
895 pinfo->discovery_timeout =
896 jiffies_to_msecs(mpath->discovery_timeout);
897 pinfo->discovery_retries = mpath->discovery_retries;
898 pinfo->flags = 0;
899 if (mpath->flags & MESH_PATH_ACTIVE)
900 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
901 if (mpath->flags & MESH_PATH_RESOLVING)
902 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
903 if (mpath->flags & MESH_PATH_DSN_VALID)
904 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
905 if (mpath->flags & MESH_PATH_FIXED)
906 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
907 if (mpath->flags & MESH_PATH_RESOLVING)
908 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
910 pinfo->flags = mpath->flags;
913 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
914 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
917 struct ieee80211_sub_if_data *sdata;
918 struct mesh_path *mpath;
920 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
922 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
923 return -ENOTSUPP;
925 rcu_read_lock();
926 mpath = mesh_path_lookup(dst, sdata);
927 if (!mpath) {
928 rcu_read_unlock();
929 return -ENOENT;
931 memcpy(dst, mpath->dst, ETH_ALEN);
932 mpath_set_pinfo(mpath, next_hop, pinfo);
933 rcu_read_unlock();
934 return 0;
937 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
938 int idx, u8 *dst, u8 *next_hop,
939 struct mpath_info *pinfo)
941 struct ieee80211_sub_if_data *sdata;
942 struct mesh_path *mpath;
944 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
946 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
947 return -ENOTSUPP;
949 rcu_read_lock();
950 mpath = mesh_path_lookup_by_idx(idx, sdata);
951 if (!mpath) {
952 rcu_read_unlock();
953 return -ENOENT;
955 memcpy(dst, mpath->dst, ETH_ALEN);
956 mpath_set_pinfo(mpath, next_hop, pinfo);
957 rcu_read_unlock();
958 return 0;
960 #endif
962 static int ieee80211_change_bss(struct wiphy *wiphy,
963 struct net_device *dev,
964 struct bss_parameters *params)
966 struct ieee80211_sub_if_data *sdata;
967 u32 changed = 0;
969 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
971 if (sdata->vif.type != NL80211_IFTYPE_AP)
972 return -EINVAL;
974 if (params->use_cts_prot >= 0) {
975 sdata->bss_conf.use_cts_prot = params->use_cts_prot;
976 changed |= BSS_CHANGED_ERP_CTS_PROT;
978 if (params->use_short_preamble >= 0) {
979 sdata->bss_conf.use_short_preamble =
980 params->use_short_preamble;
981 changed |= BSS_CHANGED_ERP_PREAMBLE;
983 if (params->use_short_slot_time >= 0) {
984 sdata->bss_conf.use_short_slot =
985 params->use_short_slot_time;
986 changed |= BSS_CHANGED_ERP_SLOT;
989 ieee80211_bss_info_change_notify(sdata, changed);
991 return 0;
994 struct cfg80211_ops mac80211_config_ops = {
995 .add_virtual_intf = ieee80211_add_iface,
996 .del_virtual_intf = ieee80211_del_iface,
997 .change_virtual_intf = ieee80211_change_iface,
998 .add_key = ieee80211_add_key,
999 .del_key = ieee80211_del_key,
1000 .get_key = ieee80211_get_key,
1001 .set_default_key = ieee80211_config_default_key,
1002 .add_beacon = ieee80211_add_beacon,
1003 .set_beacon = ieee80211_set_beacon,
1004 .del_beacon = ieee80211_del_beacon,
1005 .add_station = ieee80211_add_station,
1006 .del_station = ieee80211_del_station,
1007 .change_station = ieee80211_change_station,
1008 .get_station = ieee80211_get_station,
1009 .dump_station = ieee80211_dump_station,
1010 #ifdef CONFIG_MAC80211_MESH
1011 .add_mpath = ieee80211_add_mpath,
1012 .del_mpath = ieee80211_del_mpath,
1013 .change_mpath = ieee80211_change_mpath,
1014 .get_mpath = ieee80211_get_mpath,
1015 .dump_mpath = ieee80211_dump_mpath,
1016 #endif
1017 .change_bss = ieee80211_change_bss,