mac80211: clean up mesh code
[linux-2.6/btrfs-unstable.git] / net / mac80211 / cfg.c
blob6ac49231efa9eec5cbde744891e19fb782b603ec
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 "ieee80211_rate.h"
18 #include "mesh.h"
20 #define DEFAULT_RATES 0
22 static enum ieee80211_if_types
23 nl80211_type_to_mac80211_type(enum nl80211_iftype type)
25 switch (type) {
26 case NL80211_IFTYPE_UNSPECIFIED:
27 return IEEE80211_IF_TYPE_STA;
28 case NL80211_IFTYPE_ADHOC:
29 return IEEE80211_IF_TYPE_IBSS;
30 case NL80211_IFTYPE_STATION:
31 return IEEE80211_IF_TYPE_STA;
32 case NL80211_IFTYPE_MONITOR:
33 return IEEE80211_IF_TYPE_MNTR;
34 #ifdef CONFIG_MAC80211_MESH
35 case NL80211_IFTYPE_MESH_POINT:
36 return IEEE80211_IF_TYPE_MESH_POINT;
37 #endif
38 default:
39 return IEEE80211_IF_TYPE_INVALID;
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 enum ieee80211_if_types itype;
49 struct net_device *dev;
50 struct ieee80211_sub_if_data *sdata;
51 int err;
53 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
54 return -ENODEV;
56 itype = nl80211_type_to_mac80211_type(type);
57 if (itype == IEEE80211_IF_TYPE_INVALID)
58 return -EINVAL;
60 err = ieee80211_if_add(local->mdev, name, &dev, itype, params);
61 if (err || itype != IEEE80211_IF_TYPE_MNTR || !flags)
62 return err;
64 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
65 sdata->u.mntr_flags = *flags;
66 return 0;
69 static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
71 struct ieee80211_local *local = wiphy_priv(wiphy);
72 struct net_device *dev;
73 char *name;
75 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
76 return -ENODEV;
78 /* we're under RTNL */
79 dev = __dev_get_by_index(&init_net, ifindex);
80 if (!dev)
81 return 0;
83 name = dev->name;
85 return ieee80211_if_remove(local->mdev, name, -1);
88 static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
89 enum nl80211_iftype type, u32 *flags,
90 struct vif_params *params)
92 struct ieee80211_local *local = wiphy_priv(wiphy);
93 struct net_device *dev;
94 enum ieee80211_if_types itype;
95 struct ieee80211_sub_if_data *sdata;
97 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
98 return -ENODEV;
100 /* we're under RTNL */
101 dev = __dev_get_by_index(&init_net, ifindex);
102 if (!dev)
103 return -ENODEV;
105 if (netif_running(dev))
106 return -EBUSY;
108 itype = nl80211_type_to_mac80211_type(type);
109 if (itype == IEEE80211_IF_TYPE_INVALID)
110 return -EINVAL;
112 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
114 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
115 return -EOPNOTSUPP;
117 ieee80211_if_reinit(dev);
118 ieee80211_if_set_type(dev, itype);
120 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
121 ieee80211_if_sta_set_mesh_id(&sdata->u.sta,
122 params->mesh_id_len,
123 params->mesh_id);
125 if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR || !flags)
126 return 0;
128 sdata->u.mntr_flags = *flags;
129 return 0;
132 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
133 u8 key_idx, u8 *mac_addr,
134 struct key_params *params)
136 struct ieee80211_sub_if_data *sdata;
137 struct sta_info *sta = NULL;
138 enum ieee80211_key_alg alg;
139 int ret;
140 struct ieee80211_key *key;
142 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
144 switch (params->cipher) {
145 case WLAN_CIPHER_SUITE_WEP40:
146 case WLAN_CIPHER_SUITE_WEP104:
147 alg = ALG_WEP;
148 break;
149 case WLAN_CIPHER_SUITE_TKIP:
150 alg = ALG_TKIP;
151 break;
152 case WLAN_CIPHER_SUITE_CCMP:
153 alg = ALG_CCMP;
154 break;
155 default:
156 return -EINVAL;
159 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
160 if (!key)
161 return -ENOMEM;
163 if (mac_addr) {
164 sta = sta_info_get(sdata->local, mac_addr);
165 if (!sta) {
166 ieee80211_key_free(key);
167 return -ENOENT;
171 ieee80211_key_link(key, sdata, sta);
173 ret = 0;
175 if (sta)
176 sta_info_put(sta);
178 return ret;
181 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
182 u8 key_idx, u8 *mac_addr)
184 struct ieee80211_sub_if_data *sdata;
185 struct sta_info *sta;
186 int ret;
187 struct ieee80211_key *key;
189 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
191 if (mac_addr) {
192 sta = sta_info_get(sdata->local, mac_addr);
193 if (!sta)
194 return -ENOENT;
196 ret = 0;
197 if (sta->key) {
198 key = sta->key;
199 ieee80211_key_free(key);
200 WARN_ON(sta->key);
201 } else
202 ret = -ENOENT;
204 sta_info_put(sta);
205 return ret;
208 if (!sdata->keys[key_idx])
209 return -ENOENT;
211 key = sdata->keys[key_idx];
212 ieee80211_key_free(key);
213 WARN_ON(sdata->keys[key_idx]);
215 return 0;
218 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
219 u8 key_idx, u8 *mac_addr, void *cookie,
220 void (*callback)(void *cookie,
221 struct key_params *params))
223 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
224 struct sta_info *sta = NULL;
225 u8 seq[6] = {0};
226 struct key_params params;
227 struct ieee80211_key *key;
228 u32 iv32;
229 u16 iv16;
230 int err = -ENOENT;
232 if (mac_addr) {
233 sta = sta_info_get(sdata->local, mac_addr);
234 if (!sta)
235 goto out;
237 key = sta->key;
238 } else
239 key = sdata->keys[key_idx];
241 if (!key)
242 goto out;
244 memset(&params, 0, sizeof(params));
246 switch (key->conf.alg) {
247 case ALG_TKIP:
248 params.cipher = WLAN_CIPHER_SUITE_TKIP;
250 iv32 = key->u.tkip.iv32;
251 iv16 = key->u.tkip.iv16;
253 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
254 sdata->local->ops->get_tkip_seq)
255 sdata->local->ops->get_tkip_seq(
256 local_to_hw(sdata->local),
257 key->conf.hw_key_idx,
258 &iv32, &iv16);
260 seq[0] = iv16 & 0xff;
261 seq[1] = (iv16 >> 8) & 0xff;
262 seq[2] = iv32 & 0xff;
263 seq[3] = (iv32 >> 8) & 0xff;
264 seq[4] = (iv32 >> 16) & 0xff;
265 seq[5] = (iv32 >> 24) & 0xff;
266 params.seq = seq;
267 params.seq_len = 6;
268 break;
269 case ALG_CCMP:
270 params.cipher = WLAN_CIPHER_SUITE_CCMP;
271 seq[0] = key->u.ccmp.tx_pn[5];
272 seq[1] = key->u.ccmp.tx_pn[4];
273 seq[2] = key->u.ccmp.tx_pn[3];
274 seq[3] = key->u.ccmp.tx_pn[2];
275 seq[4] = key->u.ccmp.tx_pn[1];
276 seq[5] = key->u.ccmp.tx_pn[0];
277 params.seq = seq;
278 params.seq_len = 6;
279 break;
280 case ALG_WEP:
281 if (key->conf.keylen == 5)
282 params.cipher = WLAN_CIPHER_SUITE_WEP40;
283 else
284 params.cipher = WLAN_CIPHER_SUITE_WEP104;
285 break;
288 params.key = key->conf.key;
289 params.key_len = key->conf.keylen;
291 callback(cookie, &params);
292 err = 0;
294 out:
295 if (sta)
296 sta_info_put(sta);
297 return err;
300 static int ieee80211_config_default_key(struct wiphy *wiphy,
301 struct net_device *dev,
302 u8 key_idx)
304 struct ieee80211_sub_if_data *sdata;
306 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
307 ieee80211_set_default_key(sdata, key_idx);
309 return 0;
312 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
314 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
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;
344 sta = sta_info_get_by_idx(local, idx, dev);
345 if (!sta)
346 return -ENOENT;
348 memcpy(mac, sta->addr, ETH_ALEN);
349 sta_set_sinfo(sta, sinfo);
350 sta_info_put(sta);
352 return 0;
355 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
356 u8 *mac, struct station_info *sinfo)
358 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
359 struct sta_info *sta;
361 sta = sta_info_get(local, mac);
362 if (!sta)
363 return -ENOENT;
365 /* XXX: verify sta->dev == dev */
366 sta_set_sinfo(sta, sinfo);
367 sta_info_put(sta);
369 return 0;
373 * This handles both adding a beacon and setting new beacon info
375 static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
376 struct beacon_parameters *params)
378 struct beacon_data *new, *old;
379 int new_head_len, new_tail_len;
380 int size;
381 int err = -EINVAL;
383 old = sdata->u.ap.beacon;
385 /* head must not be zero-length */
386 if (params->head && !params->head_len)
387 return -EINVAL;
390 * This is a kludge. beacon interval should really be part
391 * of the beacon information.
393 if (params->interval) {
394 sdata->local->hw.conf.beacon_int = params->interval;
395 if (ieee80211_hw_config(sdata->local))
396 return -EINVAL;
398 * We updated some parameter so if below bails out
399 * it's not an error.
401 err = 0;
404 /* Need to have a beacon head if we don't have one yet */
405 if (!params->head && !old)
406 return err;
408 /* sorry, no way to start beaconing without dtim period */
409 if (!params->dtim_period && !old)
410 return err;
412 /* new or old head? */
413 if (params->head)
414 new_head_len = params->head_len;
415 else
416 new_head_len = old->head_len;
418 /* new or old tail? */
419 if (params->tail || !old)
420 /* params->tail_len will be zero for !params->tail */
421 new_tail_len = params->tail_len;
422 else
423 new_tail_len = old->tail_len;
425 size = sizeof(*new) + new_head_len + new_tail_len;
427 new = kzalloc(size, GFP_KERNEL);
428 if (!new)
429 return -ENOMEM;
431 /* start filling the new info now */
433 /* new or old dtim period? */
434 if (params->dtim_period)
435 new->dtim_period = params->dtim_period;
436 else
437 new->dtim_period = old->dtim_period;
440 * pointers go into the block we allocated,
441 * memory is | beacon_data | head | tail |
443 new->head = ((u8 *) new) + sizeof(*new);
444 new->tail = new->head + new_head_len;
445 new->head_len = new_head_len;
446 new->tail_len = new_tail_len;
448 /* copy in head */
449 if (params->head)
450 memcpy(new->head, params->head, new_head_len);
451 else
452 memcpy(new->head, old->head, new_head_len);
454 /* copy in optional tail */
455 if (params->tail)
456 memcpy(new->tail, params->tail, new_tail_len);
457 else
458 if (old)
459 memcpy(new->tail, old->tail, new_tail_len);
461 rcu_assign_pointer(sdata->u.ap.beacon, new);
463 synchronize_rcu();
465 kfree(old);
467 return ieee80211_if_config_beacon(sdata->dev);
470 static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
471 struct beacon_parameters *params)
473 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
474 struct beacon_data *old;
476 if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
477 return -EINVAL;
479 old = sdata->u.ap.beacon;
481 if (old)
482 return -EALREADY;
484 return ieee80211_config_beacon(sdata, params);
487 static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
488 struct beacon_parameters *params)
490 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
491 struct beacon_data *old;
493 if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
494 return -EINVAL;
496 old = sdata->u.ap.beacon;
498 if (!old)
499 return -ENOENT;
501 return ieee80211_config_beacon(sdata, params);
504 static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
506 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
507 struct beacon_data *old;
509 if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
510 return -EINVAL;
512 old = sdata->u.ap.beacon;
514 if (!old)
515 return -ENOENT;
517 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
518 synchronize_rcu();
519 kfree(old);
521 return ieee80211_if_config_beacon(dev);
524 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
525 struct iapp_layer2_update {
526 u8 da[ETH_ALEN]; /* broadcast */
527 u8 sa[ETH_ALEN]; /* STA addr */
528 __be16 len; /* 6 */
529 u8 dsap; /* 0 */
530 u8 ssap; /* 0 */
531 u8 control;
532 u8 xid_info[3];
533 } __attribute__ ((packed));
535 static void ieee80211_send_layer2_update(struct sta_info *sta)
537 struct iapp_layer2_update *msg;
538 struct sk_buff *skb;
540 /* Send Level 2 Update Frame to update forwarding tables in layer 2
541 * bridge devices */
543 skb = dev_alloc_skb(sizeof(*msg));
544 if (!skb)
545 return;
546 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
548 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
549 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
551 memset(msg->da, 0xff, ETH_ALEN);
552 memcpy(msg->sa, sta->addr, ETH_ALEN);
553 msg->len = htons(6);
554 msg->dsap = 0;
555 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
556 msg->control = 0xaf; /* XID response lsb.1111F101.
557 * F=0 (no poll command; unsolicited frame) */
558 msg->xid_info[0] = 0x81; /* XID format identifier */
559 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
560 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
562 skb->dev = sta->dev;
563 skb->protocol = eth_type_trans(skb, sta->dev);
564 memset(skb->cb, 0, sizeof(skb->cb));
565 netif_rx(skb);
568 static void sta_apply_parameters(struct ieee80211_local *local,
569 struct sta_info *sta,
570 struct station_parameters *params)
572 u32 rates;
573 int i, j;
574 struct ieee80211_supported_band *sband;
575 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
577 if (params->station_flags & STATION_FLAG_CHANGED) {
578 sta->flags &= ~WLAN_STA_AUTHORIZED;
579 if (params->station_flags & STATION_FLAG_AUTHORIZED)
580 sta->flags |= WLAN_STA_AUTHORIZED;
582 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
583 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
584 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
586 sta->flags &= ~WLAN_STA_WME;
587 if (params->station_flags & STATION_FLAG_WME)
588 sta->flags |= WLAN_STA_WME;
591 if (params->aid) {
592 sta->aid = params->aid;
593 if (sta->aid > IEEE80211_MAX_AID)
594 sta->aid = 0; /* XXX: should this be an error? */
597 if (params->listen_interval >= 0)
598 sta->listen_interval = params->listen_interval;
600 if (params->supported_rates) {
601 rates = 0;
602 sband = local->hw.wiphy->bands[local->oper_channel->band];
604 for (i = 0; i < params->supported_rates_len; i++) {
605 int rate = (params->supported_rates[i] & 0x7f) * 5;
606 for (j = 0; j < sband->n_bitrates; j++) {
607 if (sband->bitrates[j].bitrate == rate)
608 rates |= BIT(j);
611 sta->supp_rates[local->oper_channel->band] = rates;
614 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
615 switch (params->plink_action) {
616 case PLINK_ACTION_OPEN:
617 mesh_plink_open(sta);
618 break;
619 case PLINK_ACTION_BLOCK:
620 mesh_plink_block(sta);
621 break;
626 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
627 u8 *mac, struct station_parameters *params)
629 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
630 struct sta_info *sta;
631 struct ieee80211_sub_if_data *sdata;
633 /* Prevent a race with changing the rate control algorithm */
634 if (!netif_running(dev))
635 return -ENETDOWN;
637 if (params->vlan) {
638 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
640 if (sdata->vif.type != IEEE80211_IF_TYPE_VLAN ||
641 sdata->vif.type != IEEE80211_IF_TYPE_AP)
642 return -EINVAL;
643 } else
644 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
646 if (ieee80211_vif_is_mesh(&sdata->vif))
647 sta = mesh_plink_add(mac, DEFAULT_RATES, dev);
648 else
649 sta = sta_info_add(local, dev, mac, GFP_KERNEL);
651 if (IS_ERR(sta))
652 return PTR_ERR(sta);
654 sta->dev = sdata->dev;
655 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN ||
656 sdata->vif.type == IEEE80211_IF_TYPE_AP)
657 ieee80211_send_layer2_update(sta);
659 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
661 sta_apply_parameters(local, sta, params);
663 rate_control_rate_init(sta, local);
665 sta_info_put(sta);
667 return 0;
670 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
671 u8 *mac)
673 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
674 struct sta_info *sta;
676 if (mac) {
677 /* XXX: get sta belonging to dev */
678 sta = sta_info_get(local, mac);
679 if (!sta)
680 return -ENOENT;
682 sta_info_free(sta);
683 sta_info_put(sta);
684 } else
685 sta_info_flush(local, dev);
687 return 0;
690 static int ieee80211_change_station(struct wiphy *wiphy,
691 struct net_device *dev,
692 u8 *mac,
693 struct station_parameters *params)
695 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
696 struct sta_info *sta;
697 struct ieee80211_sub_if_data *vlansdata;
699 /* XXX: get sta belonging to dev */
700 sta = sta_info_get(local, mac);
701 if (!sta)
702 return -ENOENT;
704 if (params->vlan && params->vlan != sta->dev) {
705 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
707 if (vlansdata->vif.type != IEEE80211_IF_TYPE_VLAN ||
708 vlansdata->vif.type != IEEE80211_IF_TYPE_AP)
709 return -EINVAL;
711 sta->dev = params->vlan;
712 ieee80211_send_layer2_update(sta);
715 sta_apply_parameters(local, sta, params);
717 sta_info_put(sta);
719 return 0;
722 #ifdef CONFIG_MAC80211_MESH
723 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
724 u8 *dst, u8 *next_hop)
726 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
727 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
728 struct mesh_path *mpath;
729 struct sta_info *sta;
730 int err;
732 if (!netif_running(dev))
733 return -ENETDOWN;
735 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
736 return -ENOTSUPP;
738 sta = sta_info_get(local, next_hop);
739 if (!sta)
740 return -ENOENT;
742 err = mesh_path_add(dst, dev);
743 if (err)
744 return err;
746 rcu_read_lock();
747 mpath = mesh_path_lookup(dst, dev);
748 if (!mpath) {
749 rcu_read_unlock();
750 sta_info_put(sta);
751 return -ENXIO;
753 mesh_path_fix_nexthop(mpath, sta);
754 sta_info_put(sta);
755 rcu_read_unlock();
756 return 0;
759 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
760 u8 *dst)
762 if (dst)
763 return mesh_path_del(dst, dev);
765 mesh_path_flush(dev);
766 return 0;
769 static int ieee80211_change_mpath(struct wiphy *wiphy,
770 struct net_device *dev,
771 u8 *dst, u8 *next_hop)
773 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
774 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
775 struct mesh_path *mpath;
776 struct sta_info *sta;
778 if (!netif_running(dev))
779 return -ENETDOWN;
781 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
782 return -ENOTSUPP;
784 sta = sta_info_get(local, next_hop);
785 if (!sta)
786 return -ENOENT;
788 rcu_read_lock();
789 mpath = mesh_path_lookup(dst, dev);
790 if (!mpath) {
791 rcu_read_unlock();
792 sta_info_put(sta);
793 return -ENOENT;
796 mesh_path_fix_nexthop(mpath, sta);
797 sta_info_put(sta);
798 rcu_read_unlock();
799 return 0;
802 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
803 struct mpath_info *pinfo)
805 if (mpath->next_hop)
806 memcpy(next_hop, mpath->next_hop->addr, ETH_ALEN);
807 else
808 memset(next_hop, 0, ETH_ALEN);
810 pinfo->filled = MPATH_INFO_FRAME_QLEN |
811 MPATH_INFO_DSN |
812 MPATH_INFO_METRIC |
813 MPATH_INFO_EXPTIME |
814 MPATH_INFO_DISCOVERY_TIMEOUT |
815 MPATH_INFO_DISCOVERY_RETRIES |
816 MPATH_INFO_FLAGS;
818 pinfo->frame_qlen = mpath->frame_queue.qlen;
819 pinfo->dsn = mpath->dsn;
820 pinfo->metric = mpath->metric;
821 if (time_before(jiffies, mpath->exp_time))
822 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
823 pinfo->discovery_timeout =
824 jiffies_to_msecs(mpath->discovery_timeout);
825 pinfo->discovery_retries = mpath->discovery_retries;
826 pinfo->flags = 0;
827 if (mpath->flags & MESH_PATH_ACTIVE)
828 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
829 if (mpath->flags & MESH_PATH_RESOLVING)
830 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
831 if (mpath->flags & MESH_PATH_DSN_VALID)
832 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
833 if (mpath->flags & MESH_PATH_FIXED)
834 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
835 if (mpath->flags & MESH_PATH_RESOLVING)
836 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
838 pinfo->flags = mpath->flags;
841 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
842 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
845 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
846 struct mesh_path *mpath;
848 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
849 return -ENOTSUPP;
851 rcu_read_lock();
852 mpath = mesh_path_lookup(dst, dev);
853 if (!mpath) {
854 rcu_read_unlock();
855 return -ENOENT;
857 memcpy(dst, mpath->dst, ETH_ALEN);
858 mpath_set_pinfo(mpath, next_hop, pinfo);
859 rcu_read_unlock();
860 return 0;
863 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
864 int idx, u8 *dst, u8 *next_hop,
865 struct mpath_info *pinfo)
867 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
868 struct mesh_path *mpath;
870 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
871 return -ENOTSUPP;
873 rcu_read_lock();
874 mpath = mesh_path_lookup_by_idx(idx, dev);
875 if (!mpath) {
876 rcu_read_unlock();
877 return -ENOENT;
879 memcpy(dst, mpath->dst, ETH_ALEN);
880 mpath_set_pinfo(mpath, next_hop, pinfo);
881 rcu_read_unlock();
882 return 0;
884 #endif
886 struct cfg80211_ops mac80211_config_ops = {
887 .add_virtual_intf = ieee80211_add_iface,
888 .del_virtual_intf = ieee80211_del_iface,
889 .change_virtual_intf = ieee80211_change_iface,
890 .add_key = ieee80211_add_key,
891 .del_key = ieee80211_del_key,
892 .get_key = ieee80211_get_key,
893 .set_default_key = ieee80211_config_default_key,
894 .add_beacon = ieee80211_add_beacon,
895 .set_beacon = ieee80211_set_beacon,
896 .del_beacon = ieee80211_del_beacon,
897 .add_station = ieee80211_add_station,
898 .del_station = ieee80211_del_station,
899 .change_station = ieee80211_change_station,
900 .get_station = ieee80211_get_station,
901 .dump_station = ieee80211_dump_station,
902 #ifdef CONFIG_MAC80211_MESH
903 .add_mpath = ieee80211_add_mpath,
904 .del_mpath = ieee80211_del_mpath,
905 .change_mpath = ieee80211_change_mpath,
906 .get_mpath = ieee80211_get_mpath,
907 .dump_mpath = ieee80211_dump_mpath,
908 #endif