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