aboutsummaryrefslogtreecommitdiffstats
path: root/net/wireless/nl80211.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/wireless/nl80211.c')
-rw-r--r--net/wireless/nl80211.c1335
1 files changed, 1209 insertions, 126 deletions
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 1e728fff474e..353e1a4ece83 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -7,13 +7,13 @@
7#include <linux/if.h> 7#include <linux/if.h>
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/err.h> 9#include <linux/err.h>
10#include <linux/mutex.h>
11#include <linux/list.h> 10#include <linux/list.h>
12#include <linux/if_ether.h> 11#include <linux/if_ether.h>
13#include <linux/ieee80211.h> 12#include <linux/ieee80211.h>
14#include <linux/nl80211.h> 13#include <linux/nl80211.h>
15#include <linux/rtnetlink.h> 14#include <linux/rtnetlink.h>
16#include <linux/netlink.h> 15#include <linux/netlink.h>
16#include <linux/etherdevice.h>
17#include <net/genetlink.h> 17#include <net/genetlink.h>
18#include <net/cfg80211.h> 18#include <net/cfg80211.h>
19#include "core.h" 19#include "core.h"
@@ -105,6 +105,17 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
105 105
106 [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, 106 [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY,
107 .len = NL80211_HT_CAPABILITY_LEN }, 107 .len = NL80211_HT_CAPABILITY_LEN },
108
109 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
110 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
111 .len = IEEE80211_MAX_DATA_LEN },
112 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
113 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
114
115 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
116 .len = IEEE80211_MAX_SSID_LEN },
117 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
118 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
108}; 119};
109 120
110/* message building helper */ 121/* message building helper */
@@ -125,6 +136,7 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
125 struct nlattr *nl_freqs, *nl_freq; 136 struct nlattr *nl_freqs, *nl_freq;
126 struct nlattr *nl_rates, *nl_rate; 137 struct nlattr *nl_rates, *nl_rate;
127 struct nlattr *nl_modes; 138 struct nlattr *nl_modes;
139 struct nlattr *nl_cmds;
128 enum ieee80211_band band; 140 enum ieee80211_band band;
129 struct ieee80211_channel *chan; 141 struct ieee80211_channel *chan;
130 struct ieee80211_rate *rate; 142 struct ieee80211_rate *rate;
@@ -135,8 +147,10 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
135 if (!hdr) 147 if (!hdr)
136 return -1; 148 return -1;
137 149
138 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->idx); 150 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
139 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); 151 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
152 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
153 dev->wiphy.max_scan_ssids);
140 154
141 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); 155 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES);
142 if (!nl_modes) 156 if (!nl_modes)
@@ -234,6 +248,35 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
234 } 248 }
235 nla_nest_end(msg, nl_bands); 249 nla_nest_end(msg, nl_bands);
236 250
251 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
252 if (!nl_cmds)
253 goto nla_put_failure;
254
255 i = 0;
256#define CMD(op, n) \
257 do { \
258 if (dev->ops->op) { \
259 i++; \
260 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
261 } \
262 } while (0)
263
264 CMD(add_virtual_intf, NEW_INTERFACE);
265 CMD(change_virtual_intf, SET_INTERFACE);
266 CMD(add_key, NEW_KEY);
267 CMD(add_beacon, NEW_BEACON);
268 CMD(add_station, NEW_STATION);
269 CMD(add_mpath, NEW_MPATH);
270 CMD(set_mesh_params, SET_MESH_PARAMS);
271 CMD(change_bss, SET_BSS);
272 CMD(auth, AUTHENTICATE);
273 CMD(assoc, ASSOCIATE);
274 CMD(deauth, DEAUTHENTICATE);
275 CMD(disassoc, DISASSOCIATE);
276
277#undef CMD
278 nla_nest_end(msg, nl_cmds);
279
237 return genlmsg_end(msg, hdr); 280 return genlmsg_end(msg, hdr);
238 281
239 nla_put_failure: 282 nla_put_failure:
@@ -247,7 +290,7 @@ static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
247 int start = cb->args[0]; 290 int start = cb->args[0];
248 struct cfg80211_registered_device *dev; 291 struct cfg80211_registered_device *dev;
249 292
250 mutex_lock(&cfg80211_drv_mutex); 293 mutex_lock(&cfg80211_mutex);
251 list_for_each_entry(dev, &cfg80211_drv_list, list) { 294 list_for_each_entry(dev, &cfg80211_drv_list, list) {
252 if (++idx <= start) 295 if (++idx <= start)
253 continue; 296 continue;
@@ -258,7 +301,7 @@ static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
258 break; 301 break;
259 } 302 }
260 } 303 }
261 mutex_unlock(&cfg80211_drv_mutex); 304 mutex_unlock(&cfg80211_mutex);
262 305
263 cb->args[0] = idx; 306 cb->args[0] = idx;
264 307
@@ -323,16 +366,26 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
323 int result = 0, rem_txq_params = 0; 366 int result = 0, rem_txq_params = 0;
324 struct nlattr *nl_txq_params; 367 struct nlattr *nl_txq_params;
325 368
326 rdev = cfg80211_get_dev_from_info(info); 369 rtnl_lock();
327 if (IS_ERR(rdev)) 370
328 return PTR_ERR(rdev); 371 mutex_lock(&cfg80211_mutex);
372
373 rdev = __cfg80211_drv_from_info(info);
374 if (IS_ERR(rdev)) {
375 result = PTR_ERR(rdev);
376 goto unlock;
377 }
378
379 mutex_lock(&rdev->mtx);
329 380
330 if (info->attrs[NL80211_ATTR_WIPHY_NAME]) { 381 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
331 result = cfg80211_dev_rename( 382 result = cfg80211_dev_rename(
332 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); 383 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
333 if (result) 384
334 goto bad_res; 385 mutex_unlock(&cfg80211_mutex);
335 } 386
387 if (result)
388 goto bad_res;
336 389
337 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { 390 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
338 struct ieee80211_txq_params txq_params; 391 struct ieee80211_txq_params txq_params;
@@ -428,7 +481,9 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
428 481
429 482
430 bad_res: 483 bad_res:
431 cfg80211_put_dev(rdev); 484 mutex_unlock(&rdev->mtx);
485 unlock:
486 rtnl_unlock();
432 return result; 487 return result;
433} 488}
434 489
@@ -461,7 +516,7 @@ static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *
461 struct cfg80211_registered_device *dev; 516 struct cfg80211_registered_device *dev;
462 struct wireless_dev *wdev; 517 struct wireless_dev *wdev;
463 518
464 mutex_lock(&cfg80211_drv_mutex); 519 mutex_lock(&cfg80211_mutex);
465 list_for_each_entry(dev, &cfg80211_drv_list, list) { 520 list_for_each_entry(dev, &cfg80211_drv_list, list) {
466 if (wp_idx < wp_start) { 521 if (wp_idx < wp_start) {
467 wp_idx++; 522 wp_idx++;
@@ -488,7 +543,7 @@ static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *
488 wp_idx++; 543 wp_idx++;
489 } 544 }
490 out: 545 out:
491 mutex_unlock(&cfg80211_drv_mutex); 546 mutex_unlock(&cfg80211_mutex);
492 547
493 cb->args[0] = wp_idx; 548 cb->args[0] = wp_idx;
494 cb->args[1] = if_idx; 549 cb->args[1] = if_idx;
@@ -564,21 +619,31 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
564 enum nl80211_iftype type; 619 enum nl80211_iftype type;
565 struct net_device *dev; 620 struct net_device *dev;
566 u32 _flags, *flags = NULL; 621 u32 _flags, *flags = NULL;
622 bool change = false;
567 623
568 memset(&params, 0, sizeof(params)); 624 memset(&params, 0, sizeof(params));
569 625
626 rtnl_lock();
627
570 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 628 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
571 if (err) 629 if (err)
572 return err; 630 goto unlock_rtnl;
631
573 ifindex = dev->ifindex; 632 ifindex = dev->ifindex;
574 type = dev->ieee80211_ptr->iftype; 633 type = dev->ieee80211_ptr->iftype;
575 dev_put(dev); 634 dev_put(dev);
576 635
577 err = -EINVAL;
578 if (info->attrs[NL80211_ATTR_IFTYPE]) { 636 if (info->attrs[NL80211_ATTR_IFTYPE]) {
579 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 637 enum nl80211_iftype ntype;
580 if (type > NL80211_IFTYPE_MAX) 638
639 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
640 if (type != ntype)
641 change = true;
642 type = ntype;
643 if (type > NL80211_IFTYPE_MAX) {
644 err = -EINVAL;
581 goto unlock; 645 goto unlock;
646 }
582 } 647 }
583 648
584 if (!drv->ops->change_virtual_intf || 649 if (!drv->ops->change_virtual_intf ||
@@ -594,6 +659,7 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
594 } 659 }
595 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); 660 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
596 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 661 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
662 change = true;
597 } 663 }
598 664
599 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { 665 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
@@ -603,20 +669,26 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
603 } 669 }
604 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], 670 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
605 &_flags); 671 &_flags);
606 if (!err) 672 if (err)
607 flags = &_flags; 673 goto unlock;
674
675 flags = &_flags;
676 change = true;
608 } 677 }
609 rtnl_lock(); 678
610 err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex, 679 if (change)
611 type, flags, &params); 680 err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex,
681 type, flags, &params);
682 else
683 err = 0;
612 684
613 dev = __dev_get_by_index(&init_net, ifindex); 685 dev = __dev_get_by_index(&init_net, ifindex);
614 WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != type)); 686 WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != type));
615 687
616 rtnl_unlock();
617
618 unlock: 688 unlock:
619 cfg80211_put_dev(drv); 689 cfg80211_put_dev(drv);
690 unlock_rtnl:
691 rtnl_unlock();
620 return err; 692 return err;
621} 693}
622 694
@@ -639,9 +711,13 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
639 return -EINVAL; 711 return -EINVAL;
640 } 712 }
641 713
714 rtnl_lock();
715
642 drv = cfg80211_get_dev_from_info(info); 716 drv = cfg80211_get_dev_from_info(info);
643 if (IS_ERR(drv)) 717 if (IS_ERR(drv)) {
644 return PTR_ERR(drv); 718 err = PTR_ERR(drv);
719 goto unlock_rtnl;
720 }
645 721
646 if (!drv->ops->add_virtual_intf || 722 if (!drv->ops->add_virtual_intf ||
647 !(drv->wiphy.interface_modes & (1 << type))) { 723 !(drv->wiphy.interface_modes & (1 << type))) {
@@ -655,18 +731,17 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
655 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 731 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
656 } 732 }
657 733
658 rtnl_lock();
659 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? 734 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
660 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, 735 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
661 &flags); 736 &flags);
662 err = drv->ops->add_virtual_intf(&drv->wiphy, 737 err = drv->ops->add_virtual_intf(&drv->wiphy,
663 nla_data(info->attrs[NL80211_ATTR_IFNAME]), 738 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
664 type, err ? NULL : &flags, &params); 739 type, err ? NULL : &flags, &params);
665 rtnl_unlock();
666
667 740
668 unlock: 741 unlock:
669 cfg80211_put_dev(drv); 742 cfg80211_put_dev(drv);
743 unlock_rtnl:
744 rtnl_unlock();
670 return err; 745 return err;
671} 746}
672 747
@@ -676,9 +751,11 @@ static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
676 int ifindex, err; 751 int ifindex, err;
677 struct net_device *dev; 752 struct net_device *dev;
678 753
754 rtnl_lock();
755
679 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 756 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
680 if (err) 757 if (err)
681 return err; 758 goto unlock_rtnl;
682 ifindex = dev->ifindex; 759 ifindex = dev->ifindex;
683 dev_put(dev); 760 dev_put(dev);
684 761
@@ -687,12 +764,12 @@ static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
687 goto out; 764 goto out;
688 } 765 }
689 766
690 rtnl_lock();
691 err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex); 767 err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex);
692 rtnl_unlock();
693 768
694 out: 769 out:
695 cfg80211_put_dev(drv); 770 cfg80211_put_dev(drv);
771 unlock_rtnl:
772 rtnl_unlock();
696 return err; 773 return err;
697} 774}
698 775
@@ -738,15 +815,17 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
738 if (info->attrs[NL80211_ATTR_KEY_IDX]) 815 if (info->attrs[NL80211_ATTR_KEY_IDX])
739 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 816 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
740 817
741 if (key_idx > 3) 818 if (key_idx > 5)
742 return -EINVAL; 819 return -EINVAL;
743 820
744 if (info->attrs[NL80211_ATTR_MAC]) 821 if (info->attrs[NL80211_ATTR_MAC])
745 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 822 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
746 823
824 rtnl_lock();
825
747 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 826 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
748 if (err) 827 if (err)
749 return err; 828 goto unlock_rtnl;
750 829
751 if (!drv->ops->get_key) { 830 if (!drv->ops->get_key) {
752 err = -EOPNOTSUPP; 831 err = -EOPNOTSUPP;
@@ -774,10 +853,8 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
774 if (mac_addr) 853 if (mac_addr)
775 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); 854 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
776 855
777 rtnl_lock();
778 err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr, 856 err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr,
779 &cookie, get_key_callback); 857 &cookie, get_key_callback);
780 rtnl_unlock();
781 858
782 if (err) 859 if (err)
783 goto out; 860 goto out;
@@ -795,6 +872,9 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
795 out: 872 out:
796 cfg80211_put_dev(drv); 873 cfg80211_put_dev(drv);
797 dev_put(dev); 874 dev_put(dev);
875 unlock_rtnl:
876 rtnl_unlock();
877
798 return err; 878 return err;
799} 879}
800 880
@@ -804,35 +884,50 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
804 int err; 884 int err;
805 struct net_device *dev; 885 struct net_device *dev;
806 u8 key_idx; 886 u8 key_idx;
887 int (*func)(struct wiphy *wiphy, struct net_device *netdev,
888 u8 key_index);
807 889
808 if (!info->attrs[NL80211_ATTR_KEY_IDX]) 890 if (!info->attrs[NL80211_ATTR_KEY_IDX])
809 return -EINVAL; 891 return -EINVAL;
810 892
811 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 893 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
812 894
813 if (key_idx > 3) 895 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]) {
896 if (key_idx < 4 || key_idx > 5)
897 return -EINVAL;
898 } else if (key_idx > 3)
814 return -EINVAL; 899 return -EINVAL;
815 900
816 /* currently only support setting default key */ 901 /* currently only support setting default key */
817 if (!info->attrs[NL80211_ATTR_KEY_DEFAULT]) 902 if (!info->attrs[NL80211_ATTR_KEY_DEFAULT] &&
903 !info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT])
818 return -EINVAL; 904 return -EINVAL;
819 905
906 rtnl_lock();
907
820 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 908 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
821 if (err) 909 if (err)
822 return err; 910 goto unlock_rtnl;
911
912 if (info->attrs[NL80211_ATTR_KEY_DEFAULT])
913 func = drv->ops->set_default_key;
914 else
915 func = drv->ops->set_default_mgmt_key;
823 916
824 if (!drv->ops->set_default_key) { 917 if (!func) {
825 err = -EOPNOTSUPP; 918 err = -EOPNOTSUPP;
826 goto out; 919 goto out;
827 } 920 }
828 921
829 rtnl_lock(); 922 err = func(&drv->wiphy, dev, key_idx);
830 err = drv->ops->set_default_key(&drv->wiphy, dev, key_idx);
831 rtnl_unlock();
832 923
833 out: 924 out:
834 cfg80211_put_dev(drv); 925 cfg80211_put_dev(drv);
835 dev_put(dev); 926 dev_put(dev);
927
928 unlock_rtnl:
929 rtnl_unlock();
930
836 return err; 931 return err;
837} 932}
838 933
@@ -863,7 +958,7 @@ static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
863 if (info->attrs[NL80211_ATTR_MAC]) 958 if (info->attrs[NL80211_ATTR_MAC])
864 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 959 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
865 960
866 if (key_idx > 3) 961 if (key_idx > 5)
867 return -EINVAL; 962 return -EINVAL;
868 963
869 /* 964 /*
@@ -894,26 +989,33 @@ static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
894 if (params.key_len != 13) 989 if (params.key_len != 13)
895 return -EINVAL; 990 return -EINVAL;
896 break; 991 break;
992 case WLAN_CIPHER_SUITE_AES_CMAC:
993 if (params.key_len != 16)
994 return -EINVAL;
995 break;
897 default: 996 default:
898 return -EINVAL; 997 return -EINVAL;
899 } 998 }
900 999
1000 rtnl_lock();
1001
901 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1002 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
902 if (err) 1003 if (err)
903 return err; 1004 goto unlock_rtnl;
904 1005
905 if (!drv->ops->add_key) { 1006 if (!drv->ops->add_key) {
906 err = -EOPNOTSUPP; 1007 err = -EOPNOTSUPP;
907 goto out; 1008 goto out;
908 } 1009 }
909 1010
910 rtnl_lock();
911 err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, &params); 1011 err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, &params);
912 rtnl_unlock();
913 1012
914 out: 1013 out:
915 cfg80211_put_dev(drv); 1014 cfg80211_put_dev(drv);
916 dev_put(dev); 1015 dev_put(dev);
1016 unlock_rtnl:
1017 rtnl_unlock();
1018
917 return err; 1019 return err;
918} 1020}
919 1021
@@ -928,28 +1030,32 @@ static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
928 if (info->attrs[NL80211_ATTR_KEY_IDX]) 1030 if (info->attrs[NL80211_ATTR_KEY_IDX])
929 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 1031 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
930 1032
931 if (key_idx > 3) 1033 if (key_idx > 5)
932 return -EINVAL; 1034 return -EINVAL;
933 1035
934 if (info->attrs[NL80211_ATTR_MAC]) 1036 if (info->attrs[NL80211_ATTR_MAC])
935 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 1037 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
936 1038
1039 rtnl_lock();
1040
937 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1041 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
938 if (err) 1042 if (err)
939 return err; 1043 goto unlock_rtnl;
940 1044
941 if (!drv->ops->del_key) { 1045 if (!drv->ops->del_key) {
942 err = -EOPNOTSUPP; 1046 err = -EOPNOTSUPP;
943 goto out; 1047 goto out;
944 } 1048 }
945 1049
946 rtnl_lock();
947 err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr); 1050 err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr);
948 rtnl_unlock();
949 1051
950 out: 1052 out:
951 cfg80211_put_dev(drv); 1053 cfg80211_put_dev(drv);
952 dev_put(dev); 1054 dev_put(dev);
1055
1056 unlock_rtnl:
1057 rtnl_unlock();
1058
953 return err; 1059 return err;
954} 1060}
955 1061
@@ -963,9 +1069,16 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
963 struct beacon_parameters params; 1069 struct beacon_parameters params;
964 int haveinfo = 0; 1070 int haveinfo = 0;
965 1071
1072 rtnl_lock();
1073
966 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1074 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
967 if (err) 1075 if (err)
968 return err; 1076 goto unlock_rtnl;
1077
1078 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1079 err = -EOPNOTSUPP;
1080 goto out;
1081 }
969 1082
970 switch (info->genlhdr->cmd) { 1083 switch (info->genlhdr->cmd) {
971 case NL80211_CMD_NEW_BEACON: 1084 case NL80211_CMD_NEW_BEACON:
@@ -1026,13 +1139,14 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1026 goto out; 1139 goto out;
1027 } 1140 }
1028 1141
1029 rtnl_lock();
1030 err = call(&drv->wiphy, dev, &params); 1142 err = call(&drv->wiphy, dev, &params);
1031 rtnl_unlock();
1032 1143
1033 out: 1144 out:
1034 cfg80211_put_dev(drv); 1145 cfg80211_put_dev(drv);
1035 dev_put(dev); 1146 dev_put(dev);
1147 unlock_rtnl:
1148 rtnl_unlock();
1149
1036 return err; 1150 return err;
1037} 1151}
1038 1152
@@ -1042,22 +1156,29 @@ static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
1042 int err; 1156 int err;
1043 struct net_device *dev; 1157 struct net_device *dev;
1044 1158
1159 rtnl_lock();
1160
1045 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1161 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1046 if (err) 1162 if (err)
1047 return err; 1163 goto unlock_rtnl;
1048 1164
1049 if (!drv->ops->del_beacon) { 1165 if (!drv->ops->del_beacon) {
1050 err = -EOPNOTSUPP; 1166 err = -EOPNOTSUPP;
1051 goto out; 1167 goto out;
1052 } 1168 }
1053 1169
1054 rtnl_lock(); 1170 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1171 err = -EOPNOTSUPP;
1172 goto out;
1173 }
1055 err = drv->ops->del_beacon(&drv->wiphy, dev); 1174 err = drv->ops->del_beacon(&drv->wiphy, dev);
1056 rtnl_unlock();
1057 1175
1058 out: 1176 out:
1059 cfg80211_put_dev(drv); 1177 cfg80211_put_dev(drv);
1060 dev_put(dev); 1178 dev_put(dev);
1179 unlock_rtnl:
1180 rtnl_unlock();
1181
1061 return err; 1182 return err;
1062} 1183}
1063 1184
@@ -1182,6 +1303,12 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1182 1303
1183 nla_nest_end(msg, txrate); 1304 nla_nest_end(msg, txrate);
1184 } 1305 }
1306 if (sinfo->filled & STATION_INFO_RX_PACKETS)
1307 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
1308 sinfo->rx_packets);
1309 if (sinfo->filled & STATION_INFO_TX_PACKETS)
1310 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
1311 sinfo->tx_packets);
1185 nla_nest_end(msg, sinfoattr); 1312 nla_nest_end(msg, sinfoattr);
1186 1313
1187 return genlmsg_end(msg, hdr); 1314 return genlmsg_end(msg, hdr);
@@ -1217,30 +1344,32 @@ static int nl80211_dump_station(struct sk_buff *skb,
1217 return -EINVAL; 1344 return -EINVAL;
1218 } 1345 }
1219 1346
1220 netdev = dev_get_by_index(&init_net, ifidx); 1347 rtnl_lock();
1221 if (!netdev) 1348
1222 return -ENODEV; 1349 netdev = __dev_get_by_index(&init_net, ifidx);
1350 if (!netdev) {
1351 err = -ENODEV;
1352 goto out_rtnl;
1353 }
1223 1354
1224 dev = cfg80211_get_dev_from_ifindex(ifidx); 1355 dev = cfg80211_get_dev_from_ifindex(ifidx);
1225 if (IS_ERR(dev)) { 1356 if (IS_ERR(dev)) {
1226 err = PTR_ERR(dev); 1357 err = PTR_ERR(dev);
1227 goto out_put_netdev; 1358 goto out_rtnl;
1228 } 1359 }
1229 1360
1230 if (!dev->ops->dump_station) { 1361 if (!dev->ops->dump_station) {
1231 err = -ENOSYS; 1362 err = -EOPNOTSUPP;
1232 goto out_err; 1363 goto out_err;
1233 } 1364 }
1234 1365
1235 rtnl_lock();
1236
1237 while (1) { 1366 while (1) {
1238 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, 1367 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
1239 mac_addr, &sinfo); 1368 mac_addr, &sinfo);
1240 if (err == -ENOENT) 1369 if (err == -ENOENT)
1241 break; 1370 break;
1242 if (err) 1371 if (err)
1243 goto out_err_rtnl; 1372 goto out_err;
1244 1373
1245 if (nl80211_send_station(skb, 1374 if (nl80211_send_station(skb,
1246 NETLINK_CB(cb->skb).pid, 1375 NETLINK_CB(cb->skb).pid,
@@ -1256,12 +1385,10 @@ static int nl80211_dump_station(struct sk_buff *skb,
1256 out: 1385 out:
1257 cb->args[1] = sta_idx; 1386 cb->args[1] = sta_idx;
1258 err = skb->len; 1387 err = skb->len;
1259 out_err_rtnl:
1260 rtnl_unlock();
1261 out_err: 1388 out_err:
1262 cfg80211_put_dev(dev); 1389 cfg80211_put_dev(dev);
1263 out_put_netdev: 1390 out_rtnl:
1264 dev_put(netdev); 1391 rtnl_unlock();
1265 1392
1266 return err; 1393 return err;
1267} 1394}
@@ -1282,19 +1409,18 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1282 1409
1283 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 1410 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1284 1411
1412 rtnl_lock();
1413
1285 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1414 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1286 if (err) 1415 if (err)
1287 return err; 1416 goto out_rtnl;
1288 1417
1289 if (!drv->ops->get_station) { 1418 if (!drv->ops->get_station) {
1290 err = -EOPNOTSUPP; 1419 err = -EOPNOTSUPP;
1291 goto out; 1420 goto out;
1292 } 1421 }
1293 1422
1294 rtnl_lock();
1295 err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &sinfo); 1423 err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &sinfo);
1296 rtnl_unlock();
1297
1298 if (err) 1424 if (err)
1299 goto out; 1425 goto out;
1300 1426
@@ -1311,10 +1437,12 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1311 1437
1312 out_free: 1438 out_free:
1313 nlmsg_free(msg); 1439 nlmsg_free(msg);
1314
1315 out: 1440 out:
1316 cfg80211_put_dev(drv); 1441 cfg80211_put_dev(drv);
1317 dev_put(dev); 1442 dev_put(dev);
1443 out_rtnl:
1444 rtnl_unlock();
1445
1318 return err; 1446 return err;
1319} 1447}
1320 1448
@@ -1382,9 +1510,11 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
1382 params.plink_action = 1510 params.plink_action =
1383 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); 1511 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
1384 1512
1513 rtnl_lock();
1514
1385 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1515 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1386 if (err) 1516 if (err)
1387 return err; 1517 goto out_rtnl;
1388 1518
1389 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, &params.vlan); 1519 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, &params.vlan);
1390 if (err) 1520 if (err)
@@ -1395,15 +1525,16 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
1395 goto out; 1525 goto out;
1396 } 1526 }
1397 1527
1398 rtnl_lock();
1399 err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, &params); 1528 err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, &params);
1400 rtnl_unlock();
1401 1529
1402 out: 1530 out:
1403 if (params.vlan) 1531 if (params.vlan)
1404 dev_put(params.vlan); 1532 dev_put(params.vlan);
1405 cfg80211_put_dev(drv); 1533 cfg80211_put_dev(drv);
1406 dev_put(dev); 1534 dev_put(dev);
1535 out_rtnl:
1536 rtnl_unlock();
1537
1407 return err; 1538 return err;
1408} 1539}
1409 1540
@@ -1445,9 +1576,11 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1445 &params.station_flags)) 1576 &params.station_flags))
1446 return -EINVAL; 1577 return -EINVAL;
1447 1578
1579 rtnl_lock();
1580
1448 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1581 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1449 if (err) 1582 if (err)
1450 return err; 1583 goto out_rtnl;
1451 1584
1452 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, &params.vlan); 1585 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, &params.vlan);
1453 if (err) 1586 if (err)
@@ -1458,15 +1591,21 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1458 goto out; 1591 goto out;
1459 } 1592 }
1460 1593
1461 rtnl_lock(); 1594 if (!netif_running(dev)) {
1595 err = -ENETDOWN;
1596 goto out;
1597 }
1598
1462 err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, &params); 1599 err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, &params);
1463 rtnl_unlock();
1464 1600
1465 out: 1601 out:
1466 if (params.vlan) 1602 if (params.vlan)
1467 dev_put(params.vlan); 1603 dev_put(params.vlan);
1468 cfg80211_put_dev(drv); 1604 cfg80211_put_dev(drv);
1469 dev_put(dev); 1605 dev_put(dev);
1606 out_rtnl:
1607 rtnl_unlock();
1608
1470 return err; 1609 return err;
1471} 1610}
1472 1611
@@ -1480,22 +1619,25 @@ static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
1480 if (info->attrs[NL80211_ATTR_MAC]) 1619 if (info->attrs[NL80211_ATTR_MAC])
1481 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 1620 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1482 1621
1622 rtnl_lock();
1623
1483 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1624 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1484 if (err) 1625 if (err)
1485 return err; 1626 goto out_rtnl;
1486 1627
1487 if (!drv->ops->del_station) { 1628 if (!drv->ops->del_station) {
1488 err = -EOPNOTSUPP; 1629 err = -EOPNOTSUPP;
1489 goto out; 1630 goto out;
1490 } 1631 }
1491 1632
1492 rtnl_lock();
1493 err = drv->ops->del_station(&drv->wiphy, dev, mac_addr); 1633 err = drv->ops->del_station(&drv->wiphy, dev, mac_addr);
1494 rtnl_unlock();
1495 1634
1496 out: 1635 out:
1497 cfg80211_put_dev(drv); 1636 cfg80211_put_dev(drv);
1498 dev_put(dev); 1637 dev_put(dev);
1638 out_rtnl:
1639 rtnl_unlock();
1640
1499 return err; 1641 return err;
1500} 1642}
1501 1643
@@ -1576,22 +1718,29 @@ static int nl80211_dump_mpath(struct sk_buff *skb,
1576 return -EINVAL; 1718 return -EINVAL;
1577 } 1719 }
1578 1720
1579 netdev = dev_get_by_index(&init_net, ifidx); 1721 rtnl_lock();
1580 if (!netdev) 1722
1581 return -ENODEV; 1723 netdev = __dev_get_by_index(&init_net, ifidx);
1724 if (!netdev) {
1725 err = -ENODEV;
1726 goto out_rtnl;
1727 }
1582 1728
1583 dev = cfg80211_get_dev_from_ifindex(ifidx); 1729 dev = cfg80211_get_dev_from_ifindex(ifidx);
1584 if (IS_ERR(dev)) { 1730 if (IS_ERR(dev)) {
1585 err = PTR_ERR(dev); 1731 err = PTR_ERR(dev);
1586 goto out_put_netdev; 1732 goto out_rtnl;
1587 } 1733 }
1588 1734
1589 if (!dev->ops->dump_mpath) { 1735 if (!dev->ops->dump_mpath) {
1590 err = -ENOSYS; 1736 err = -EOPNOTSUPP;
1591 goto out_err; 1737 goto out_err;
1592 } 1738 }
1593 1739
1594 rtnl_lock(); 1740 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1741 err = -EOPNOTSUPP;
1742 goto out;
1743 }
1595 1744
1596 while (1) { 1745 while (1) {
1597 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, 1746 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
@@ -1599,7 +1748,7 @@ static int nl80211_dump_mpath(struct sk_buff *skb,
1599 if (err == -ENOENT) 1748 if (err == -ENOENT)
1600 break; 1749 break;
1601 if (err) 1750 if (err)
1602 goto out_err_rtnl; 1751 goto out_err;
1603 1752
1604 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, 1753 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
1605 cb->nlh->nlmsg_seq, NLM_F_MULTI, 1754 cb->nlh->nlmsg_seq, NLM_F_MULTI,
@@ -1614,12 +1763,10 @@ static int nl80211_dump_mpath(struct sk_buff *skb,
1614 out: 1763 out:
1615 cb->args[1] = path_idx; 1764 cb->args[1] = path_idx;
1616 err = skb->len; 1765 err = skb->len;
1617 out_err_rtnl:
1618 rtnl_unlock();
1619 out_err: 1766 out_err:
1620 cfg80211_put_dev(dev); 1767 cfg80211_put_dev(dev);
1621 out_put_netdev: 1768 out_rtnl:
1622 dev_put(netdev); 1769 rtnl_unlock();
1623 1770
1624 return err; 1771 return err;
1625} 1772}
@@ -1641,19 +1788,23 @@ static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
1641 1788
1642 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 1789 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1643 1790
1791 rtnl_lock();
1792
1644 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1793 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1645 if (err) 1794 if (err)
1646 return err; 1795 goto out_rtnl;
1647 1796
1648 if (!drv->ops->get_mpath) { 1797 if (!drv->ops->get_mpath) {
1649 err = -EOPNOTSUPP; 1798 err = -EOPNOTSUPP;
1650 goto out; 1799 goto out;
1651 } 1800 }
1652 1801
1653 rtnl_lock(); 1802 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1654 err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo); 1803 err = -EOPNOTSUPP;
1655 rtnl_unlock(); 1804 goto out;
1805 }
1656 1806
1807 err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo);
1657 if (err) 1808 if (err)
1658 goto out; 1809 goto out;
1659 1810
@@ -1670,10 +1821,12 @@ static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
1670 1821
1671 out_free: 1822 out_free:
1672 nlmsg_free(msg); 1823 nlmsg_free(msg);
1673
1674 out: 1824 out:
1675 cfg80211_put_dev(drv); 1825 cfg80211_put_dev(drv);
1676 dev_put(dev); 1826 dev_put(dev);
1827 out_rtnl:
1828 rtnl_unlock();
1829
1677 return err; 1830 return err;
1678} 1831}
1679 1832
@@ -1694,22 +1847,35 @@ static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
1694 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 1847 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1695 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 1848 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
1696 1849
1850 rtnl_lock();
1851
1697 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1852 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1698 if (err) 1853 if (err)
1699 return err; 1854 goto out_rtnl;
1700 1855
1701 if (!drv->ops->change_mpath) { 1856 if (!drv->ops->change_mpath) {
1702 err = -EOPNOTSUPP; 1857 err = -EOPNOTSUPP;
1703 goto out; 1858 goto out;
1704 } 1859 }
1705 1860
1706 rtnl_lock(); 1861 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1862 err = -EOPNOTSUPP;
1863 goto out;
1864 }
1865
1866 if (!netif_running(dev)) {
1867 err = -ENETDOWN;
1868 goto out;
1869 }
1870
1707 err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop); 1871 err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop);
1708 rtnl_unlock();
1709 1872
1710 out: 1873 out:
1711 cfg80211_put_dev(drv); 1874 cfg80211_put_dev(drv);
1712 dev_put(dev); 1875 dev_put(dev);
1876 out_rtnl:
1877 rtnl_unlock();
1878
1713 return err; 1879 return err;
1714} 1880}
1715static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) 1881static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
@@ -1729,22 +1895,35 @@ static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
1729 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 1895 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1730 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 1896 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
1731 1897
1898 rtnl_lock();
1899
1732 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1900 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1733 if (err) 1901 if (err)
1734 return err; 1902 goto out_rtnl;
1735 1903
1736 if (!drv->ops->add_mpath) { 1904 if (!drv->ops->add_mpath) {
1737 err = -EOPNOTSUPP; 1905 err = -EOPNOTSUPP;
1738 goto out; 1906 goto out;
1739 } 1907 }
1740 1908
1741 rtnl_lock(); 1909 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1910 err = -EOPNOTSUPP;
1911 goto out;
1912 }
1913
1914 if (!netif_running(dev)) {
1915 err = -ENETDOWN;
1916 goto out;
1917 }
1918
1742 err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop); 1919 err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop);
1743 rtnl_unlock();
1744 1920
1745 out: 1921 out:
1746 cfg80211_put_dev(drv); 1922 cfg80211_put_dev(drv);
1747 dev_put(dev); 1923 dev_put(dev);
1924 out_rtnl:
1925 rtnl_unlock();
1926
1748 return err; 1927 return err;
1749} 1928}
1750 1929
@@ -1758,22 +1937,25 @@ static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
1758 if (info->attrs[NL80211_ATTR_MAC]) 1937 if (info->attrs[NL80211_ATTR_MAC])
1759 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 1938 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1760 1939
1940 rtnl_lock();
1941
1761 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1942 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1762 if (err) 1943 if (err)
1763 return err; 1944 goto out_rtnl;
1764 1945
1765 if (!drv->ops->del_mpath) { 1946 if (!drv->ops->del_mpath) {
1766 err = -EOPNOTSUPP; 1947 err = -EOPNOTSUPP;
1767 goto out; 1948 goto out;
1768 } 1949 }
1769 1950
1770 rtnl_lock();
1771 err = drv->ops->del_mpath(&drv->wiphy, dev, dst); 1951 err = drv->ops->del_mpath(&drv->wiphy, dev, dst);
1772 rtnl_unlock();
1773 1952
1774 out: 1953 out:
1775 cfg80211_put_dev(drv); 1954 cfg80211_put_dev(drv);
1776 dev_put(dev); 1955 dev_put(dev);
1956 out_rtnl:
1957 rtnl_unlock();
1958
1777 return err; 1959 return err;
1778} 1960}
1779 1961
@@ -1806,22 +1988,30 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
1806 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 1988 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
1807 } 1989 }
1808 1990
1991 rtnl_lock();
1992
1809 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1993 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1810 if (err) 1994 if (err)
1811 return err; 1995 goto out_rtnl;
1812 1996
1813 if (!drv->ops->change_bss) { 1997 if (!drv->ops->change_bss) {
1814 err = -EOPNOTSUPP; 1998 err = -EOPNOTSUPP;
1815 goto out; 1999 goto out;
1816 } 2000 }
1817 2001
1818 rtnl_lock(); 2002 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
2003 err = -EOPNOTSUPP;
2004 goto out;
2005 }
2006
1819 err = drv->ops->change_bss(&drv->wiphy, dev, &params); 2007 err = drv->ops->change_bss(&drv->wiphy, dev, &params);
1820 rtnl_unlock();
1821 2008
1822 out: 2009 out:
1823 cfg80211_put_dev(drv); 2010 cfg80211_put_dev(drv);
1824 dev_put(dev); 2011 dev_put(dev);
2012 out_rtnl:
2013 rtnl_unlock();
2014
1825 return err; 2015 return err;
1826} 2016}
1827 2017
@@ -1876,6 +2066,19 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
1876 int r; 2066 int r;
1877 char *data = NULL; 2067 char *data = NULL;
1878 2068
2069 /*
2070 * You should only get this when cfg80211 hasn't yet initialized
2071 * completely when built-in to the kernel right between the time
2072 * window between nl80211_init() and regulatory_init(), if that is
2073 * even possible.
2074 */
2075 mutex_lock(&cfg80211_mutex);
2076 if (unlikely(!cfg80211_regdomain)) {
2077 mutex_unlock(&cfg80211_mutex);
2078 return -EINPROGRESS;
2079 }
2080 mutex_unlock(&cfg80211_mutex);
2081
1879 if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) 2082 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
1880 return -EINVAL; 2083 return -EINVAL;
1881 2084
@@ -1886,9 +2089,9 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
1886 if (is_world_regdom(data)) 2089 if (is_world_regdom(data))
1887 return -EINVAL; 2090 return -EINVAL;
1888#endif 2091#endif
1889 mutex_lock(&cfg80211_drv_mutex); 2092
1890 r = __regulatory_hint(NULL, REGDOM_SET_BY_USER, data, 0, ENVIRON_ANY); 2093 r = regulatory_hint_user(data);
1891 mutex_unlock(&cfg80211_drv_mutex); 2094
1892 return r; 2095 return r;
1893} 2096}
1894 2097
@@ -1903,15 +2106,20 @@ static int nl80211_get_mesh_params(struct sk_buff *skb,
1903 struct nlattr *pinfoattr; 2106 struct nlattr *pinfoattr;
1904 struct sk_buff *msg; 2107 struct sk_buff *msg;
1905 2108
2109 rtnl_lock();
2110
1906 /* Look up our device */ 2111 /* Look up our device */
1907 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 2112 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1908 if (err) 2113 if (err)
1909 return err; 2114 goto out_rtnl;
2115
2116 if (!drv->ops->get_mesh_params) {
2117 err = -EOPNOTSUPP;
2118 goto out;
2119 }
1910 2120
1911 /* Get the mesh params */ 2121 /* Get the mesh params */
1912 rtnl_lock();
1913 err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params); 2122 err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params);
1914 rtnl_unlock();
1915 if (err) 2123 if (err)
1916 goto out; 2124 goto out;
1917 2125
@@ -1960,13 +2168,16 @@ static int nl80211_get_mesh_params(struct sk_buff *skb,
1960 err = genlmsg_unicast(msg, info->snd_pid); 2168 err = genlmsg_unicast(msg, info->snd_pid);
1961 goto out; 2169 goto out;
1962 2170
1963nla_put_failure: 2171 nla_put_failure:
1964 genlmsg_cancel(msg, hdr); 2172 genlmsg_cancel(msg, hdr);
1965 err = -EMSGSIZE; 2173 err = -EMSGSIZE;
1966out: 2174 out:
1967 /* Cleanup */ 2175 /* Cleanup */
1968 cfg80211_put_dev(drv); 2176 cfg80211_put_dev(drv);
1969 dev_put(dev); 2177 dev_put(dev);
2178 out_rtnl:
2179 rtnl_unlock();
2180
1970 return err; 2181 return err;
1971} 2182}
1972 2183
@@ -2013,9 +2224,16 @@ static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2013 parent_attr, nl80211_meshconf_params_policy)) 2224 parent_attr, nl80211_meshconf_params_policy))
2014 return -EINVAL; 2225 return -EINVAL;
2015 2226
2227 rtnl_lock();
2228
2016 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 2229 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2017 if (err) 2230 if (err)
2018 return err; 2231 goto out_rtnl;
2232
2233 if (!drv->ops->set_mesh_params) {
2234 err = -EOPNOTSUPP;
2235 goto out;
2236 }
2019 2237
2020 /* This makes sure that there aren't more than 32 mesh config 2238 /* This makes sure that there aren't more than 32 mesh config
2021 * parameters (otherwise our bitfield scheme would not work.) */ 2239 * parameters (otherwise our bitfield scheme would not work.) */
@@ -2057,18 +2275,95 @@ static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2057 nla_get_u16); 2275 nla_get_u16);
2058 2276
2059 /* Apply changes */ 2277 /* Apply changes */
2060 rtnl_lock();
2061 err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask); 2278 err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask);
2062 rtnl_unlock();
2063 2279
2280 out:
2064 /* cleanup */ 2281 /* cleanup */
2065 cfg80211_put_dev(drv); 2282 cfg80211_put_dev(drv);
2066 dev_put(dev); 2283 dev_put(dev);
2284 out_rtnl:
2285 rtnl_unlock();
2286
2067 return err; 2287 return err;
2068} 2288}
2069 2289
2070#undef FILL_IN_MESH_PARAM_IF_SET 2290#undef FILL_IN_MESH_PARAM_IF_SET
2071 2291
2292static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
2293{
2294 struct sk_buff *msg;
2295 void *hdr = NULL;
2296 struct nlattr *nl_reg_rules;
2297 unsigned int i;
2298 int err = -EINVAL;
2299
2300 mutex_lock(&cfg80211_mutex);
2301
2302 if (!cfg80211_regdomain)
2303 goto out;
2304
2305 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2306 if (!msg) {
2307 err = -ENOBUFS;
2308 goto out;
2309 }
2310
2311 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2312 NL80211_CMD_GET_REG);
2313 if (!hdr)
2314 goto nla_put_failure;
2315
2316 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
2317 cfg80211_regdomain->alpha2);
2318
2319 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
2320 if (!nl_reg_rules)
2321 goto nla_put_failure;
2322
2323 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
2324 struct nlattr *nl_reg_rule;
2325 const struct ieee80211_reg_rule *reg_rule;
2326 const struct ieee80211_freq_range *freq_range;
2327 const struct ieee80211_power_rule *power_rule;
2328
2329 reg_rule = &cfg80211_regdomain->reg_rules[i];
2330 freq_range = &reg_rule->freq_range;
2331 power_rule = &reg_rule->power_rule;
2332
2333 nl_reg_rule = nla_nest_start(msg, i);
2334 if (!nl_reg_rule)
2335 goto nla_put_failure;
2336
2337 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
2338 reg_rule->flags);
2339 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
2340 freq_range->start_freq_khz);
2341 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
2342 freq_range->end_freq_khz);
2343 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
2344 freq_range->max_bandwidth_khz);
2345 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
2346 power_rule->max_antenna_gain);
2347 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
2348 power_rule->max_eirp);
2349
2350 nla_nest_end(msg, nl_reg_rule);
2351 }
2352
2353 nla_nest_end(msg, nl_reg_rules);
2354
2355 genlmsg_end(msg, hdr);
2356 err = genlmsg_unicast(msg, info->snd_pid);
2357 goto out;
2358
2359nla_put_failure:
2360 genlmsg_cancel(msg, hdr);
2361 err = -EMSGSIZE;
2362out:
2363 mutex_unlock(&cfg80211_mutex);
2364 return err;
2365}
2366
2072static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) 2367static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
2073{ 2368{
2074 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; 2369 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
@@ -2124,9 +2419,9 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
2124 2419
2125 BUG_ON(rule_idx != num_rules); 2420 BUG_ON(rule_idx != num_rules);
2126 2421
2127 mutex_lock(&cfg80211_drv_mutex); 2422 mutex_lock(&cfg80211_mutex);
2128 r = set_regdom(rd); 2423 r = set_regdom(rd);
2129 mutex_unlock(&cfg80211_drv_mutex); 2424 mutex_unlock(&cfg80211_mutex);
2130 return r; 2425 return r;
2131 2426
2132 bad_reg: 2427 bad_reg:
@@ -2134,6 +2429,553 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
2134 return -EINVAL; 2429 return -EINVAL;
2135} 2430}
2136 2431
2432static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2433{
2434 struct cfg80211_registered_device *drv;
2435 struct net_device *dev;
2436 struct cfg80211_scan_request *request;
2437 struct cfg80211_ssid *ssid;
2438 struct ieee80211_channel *channel;
2439 struct nlattr *attr;
2440 struct wiphy *wiphy;
2441 int err, tmp, n_ssids = 0, n_channels = 0, i;
2442 enum ieee80211_band band;
2443 size_t ie_len;
2444
2445 rtnl_lock();
2446
2447 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2448 if (err)
2449 goto out_rtnl;
2450
2451 wiphy = &drv->wiphy;
2452
2453 if (!drv->ops->scan) {
2454 err = -EOPNOTSUPP;
2455 goto out;
2456 }
2457
2458 if (!netif_running(dev)) {
2459 err = -ENETDOWN;
2460 goto out;
2461 }
2462
2463 if (drv->scan_req) {
2464 err = -EBUSY;
2465 goto out;
2466 }
2467
2468 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2469 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp)
2470 n_channels++;
2471 if (!n_channels) {
2472 err = -EINVAL;
2473 goto out;
2474 }
2475 } else {
2476 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
2477 if (wiphy->bands[band])
2478 n_channels += wiphy->bands[band]->n_channels;
2479 }
2480
2481 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
2482 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
2483 n_ssids++;
2484
2485 if (n_ssids > wiphy->max_scan_ssids) {
2486 err = -EINVAL;
2487 goto out;
2488 }
2489
2490 if (info->attrs[NL80211_ATTR_IE])
2491 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2492 else
2493 ie_len = 0;
2494
2495 request = kzalloc(sizeof(*request)
2496 + sizeof(*ssid) * n_ssids
2497 + sizeof(channel) * n_channels
2498 + ie_len, GFP_KERNEL);
2499 if (!request) {
2500 err = -ENOMEM;
2501 goto out;
2502 }
2503
2504 request->channels = (void *)((char *)request + sizeof(*request));
2505 request->n_channels = n_channels;
2506 if (n_ssids)
2507 request->ssids = (void *)(request->channels + n_channels);
2508 request->n_ssids = n_ssids;
2509 if (ie_len) {
2510 if (request->ssids)
2511 request->ie = (void *)(request->ssids + n_ssids);
2512 else
2513 request->ie = (void *)(request->channels + n_channels);
2514 }
2515
2516 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2517 /* user specified, bail out if channel not found */
2518 request->n_channels = n_channels;
2519 i = 0;
2520 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
2521 request->channels[i] = ieee80211_get_channel(wiphy, nla_get_u32(attr));
2522 if (!request->channels[i]) {
2523 err = -EINVAL;
2524 goto out_free;
2525 }
2526 i++;
2527 }
2528 } else {
2529 /* all channels */
2530 i = 0;
2531 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2532 int j;
2533 if (!wiphy->bands[band])
2534 continue;
2535 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
2536 request->channels[i] = &wiphy->bands[band]->channels[j];
2537 i++;
2538 }
2539 }
2540 }
2541
2542 i = 0;
2543 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
2544 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
2545 if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) {
2546 err = -EINVAL;
2547 goto out_free;
2548 }
2549 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
2550 request->ssids[i].ssid_len = nla_len(attr);
2551 i++;
2552 }
2553 }
2554
2555 if (info->attrs[NL80211_ATTR_IE]) {
2556 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2557 memcpy(request->ie, nla_data(info->attrs[NL80211_ATTR_IE]),
2558 request->ie_len);
2559 }
2560
2561 request->ifidx = dev->ifindex;
2562 request->wiphy = &drv->wiphy;
2563
2564 drv->scan_req = request;
2565 err = drv->ops->scan(&drv->wiphy, dev, request);
2566
2567 out_free:
2568 if (err) {
2569 drv->scan_req = NULL;
2570 kfree(request);
2571 }
2572 out:
2573 cfg80211_put_dev(drv);
2574 dev_put(dev);
2575 out_rtnl:
2576 rtnl_unlock();
2577
2578 return err;
2579}
2580
2581static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags,
2582 struct cfg80211_registered_device *rdev,
2583 struct net_device *dev,
2584 struct cfg80211_bss *res)
2585{
2586 void *hdr;
2587 struct nlattr *bss;
2588
2589 hdr = nl80211hdr_put(msg, pid, seq, flags,
2590 NL80211_CMD_NEW_SCAN_RESULTS);
2591 if (!hdr)
2592 return -1;
2593
2594 NLA_PUT_U32(msg, NL80211_ATTR_SCAN_GENERATION,
2595 rdev->bss_generation);
2596 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2597
2598 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
2599 if (!bss)
2600 goto nla_put_failure;
2601 if (!is_zero_ether_addr(res->bssid))
2602 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
2603 if (res->information_elements && res->len_information_elements)
2604 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
2605 res->len_information_elements,
2606 res->information_elements);
2607 if (res->tsf)
2608 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
2609 if (res->beacon_interval)
2610 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
2611 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
2612 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
2613
2614 switch (rdev->wiphy.signal_type) {
2615 case CFG80211_SIGNAL_TYPE_MBM:
2616 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
2617 break;
2618 case CFG80211_SIGNAL_TYPE_UNSPEC:
2619 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
2620 break;
2621 default:
2622 break;
2623 }
2624
2625 nla_nest_end(msg, bss);
2626
2627 return genlmsg_end(msg, hdr);
2628
2629 nla_put_failure:
2630 genlmsg_cancel(msg, hdr);
2631 return -EMSGSIZE;
2632}
2633
2634static int nl80211_dump_scan(struct sk_buff *skb,
2635 struct netlink_callback *cb)
2636{
2637 struct cfg80211_registered_device *dev;
2638 struct net_device *netdev;
2639 struct cfg80211_internal_bss *scan;
2640 int ifidx = cb->args[0];
2641 int start = cb->args[1], idx = 0;
2642 int err;
2643
2644 if (!ifidx) {
2645 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
2646 nl80211_fam.attrbuf, nl80211_fam.maxattr,
2647 nl80211_policy);
2648 if (err)
2649 return err;
2650
2651 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
2652 return -EINVAL;
2653
2654 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
2655 if (!ifidx)
2656 return -EINVAL;
2657 cb->args[0] = ifidx;
2658 }
2659
2660 netdev = dev_get_by_index(&init_net, ifidx);
2661 if (!netdev)
2662 return -ENODEV;
2663
2664 dev = cfg80211_get_dev_from_ifindex(ifidx);
2665 if (IS_ERR(dev)) {
2666 err = PTR_ERR(dev);
2667 goto out_put_netdev;
2668 }
2669
2670 spin_lock_bh(&dev->bss_lock);
2671 cfg80211_bss_expire(dev);
2672
2673 list_for_each_entry(scan, &dev->bss_list, list) {
2674 if (++idx <= start)
2675 continue;
2676 if (nl80211_send_bss(skb,
2677 NETLINK_CB(cb->skb).pid,
2678 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2679 dev, netdev, &scan->pub) < 0) {
2680 idx--;
2681 goto out;
2682 }
2683 }
2684
2685 out:
2686 spin_unlock_bh(&dev->bss_lock);
2687
2688 cb->args[1] = idx;
2689 err = skb->len;
2690 cfg80211_put_dev(dev);
2691 out_put_netdev:
2692 dev_put(netdev);
2693
2694 return err;
2695}
2696
2697static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
2698{
2699 return auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM ||
2700 auth_type == NL80211_AUTHTYPE_SHARED_KEY ||
2701 auth_type == NL80211_AUTHTYPE_FT ||
2702 auth_type == NL80211_AUTHTYPE_NETWORK_EAP;
2703}
2704
2705static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
2706{
2707 struct cfg80211_registered_device *drv;
2708 struct net_device *dev;
2709 struct cfg80211_auth_request req;
2710 struct wiphy *wiphy;
2711 int err;
2712
2713 rtnl_lock();
2714
2715 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2716 if (err)
2717 goto unlock_rtnl;
2718
2719 if (!drv->ops->auth) {
2720 err = -EOPNOTSUPP;
2721 goto out;
2722 }
2723
2724 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2725 err = -EOPNOTSUPP;
2726 goto out;
2727 }
2728
2729 if (!netif_running(dev)) {
2730 err = -ENETDOWN;
2731 goto out;
2732 }
2733
2734 if (!info->attrs[NL80211_ATTR_MAC]) {
2735 err = -EINVAL;
2736 goto out;
2737 }
2738
2739 wiphy = &drv->wiphy;
2740 memset(&req, 0, sizeof(req));
2741
2742 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2743
2744 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2745 req.chan = ieee80211_get_channel(
2746 wiphy,
2747 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2748 if (!req.chan) {
2749 err = -EINVAL;
2750 goto out;
2751 }
2752 }
2753
2754 if (info->attrs[NL80211_ATTR_SSID]) {
2755 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2756 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
2757 }
2758
2759 if (info->attrs[NL80211_ATTR_IE]) {
2760 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2761 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2762 }
2763
2764 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2765 req.auth_type =
2766 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
2767 if (!nl80211_valid_auth_type(req.auth_type)) {
2768 err = -EINVAL;
2769 goto out;
2770 }
2771 }
2772
2773 err = drv->ops->auth(&drv->wiphy, dev, &req);
2774
2775out:
2776 cfg80211_put_dev(drv);
2777 dev_put(dev);
2778unlock_rtnl:
2779 rtnl_unlock();
2780 return err;
2781}
2782
2783static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
2784{
2785 struct cfg80211_registered_device *drv;
2786 struct net_device *dev;
2787 struct cfg80211_assoc_request req;
2788 struct wiphy *wiphy;
2789 int err;
2790
2791 rtnl_lock();
2792
2793 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2794 if (err)
2795 goto unlock_rtnl;
2796
2797 if (!drv->ops->assoc) {
2798 err = -EOPNOTSUPP;
2799 goto out;
2800 }
2801
2802 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2803 err = -EOPNOTSUPP;
2804 goto out;
2805 }
2806
2807 if (!netif_running(dev)) {
2808 err = -ENETDOWN;
2809 goto out;
2810 }
2811
2812 if (!info->attrs[NL80211_ATTR_MAC] ||
2813 !info->attrs[NL80211_ATTR_SSID]) {
2814 err = -EINVAL;
2815 goto out;
2816 }
2817
2818 wiphy = &drv->wiphy;
2819 memset(&req, 0, sizeof(req));
2820
2821 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2822
2823 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2824 req.chan = ieee80211_get_channel(
2825 wiphy,
2826 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2827 if (!req.chan) {
2828 err = -EINVAL;
2829 goto out;
2830 }
2831 }
2832
2833 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2834 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
2835
2836 if (info->attrs[NL80211_ATTR_IE]) {
2837 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2838 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2839 }
2840
2841 err = drv->ops->assoc(&drv->wiphy, dev, &req);
2842
2843out:
2844 cfg80211_put_dev(drv);
2845 dev_put(dev);
2846unlock_rtnl:
2847 rtnl_unlock();
2848 return err;
2849}
2850
2851static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
2852{
2853 struct cfg80211_registered_device *drv;
2854 struct net_device *dev;
2855 struct cfg80211_deauth_request req;
2856 struct wiphy *wiphy;
2857 int err;
2858
2859 rtnl_lock();
2860
2861 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2862 if (err)
2863 goto unlock_rtnl;
2864
2865 if (!drv->ops->deauth) {
2866 err = -EOPNOTSUPP;
2867 goto out;
2868 }
2869
2870 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2871 err = -EOPNOTSUPP;
2872 goto out;
2873 }
2874
2875 if (!netif_running(dev)) {
2876 err = -ENETDOWN;
2877 goto out;
2878 }
2879
2880 if (!info->attrs[NL80211_ATTR_MAC]) {
2881 err = -EINVAL;
2882 goto out;
2883 }
2884
2885 wiphy = &drv->wiphy;
2886 memset(&req, 0, sizeof(req));
2887
2888 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2889
2890 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
2891 req.reason_code =
2892 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
2893 if (req.reason_code == 0) {
2894 /* Reason Code 0 is reserved */
2895 err = -EINVAL;
2896 goto out;
2897 }
2898 }
2899
2900 if (info->attrs[NL80211_ATTR_IE]) {
2901 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2902 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2903 }
2904
2905 err = drv->ops->deauth(&drv->wiphy, dev, &req);
2906
2907out:
2908 cfg80211_put_dev(drv);
2909 dev_put(dev);
2910unlock_rtnl:
2911 rtnl_unlock();
2912 return err;
2913}
2914
2915static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
2916{
2917 struct cfg80211_registered_device *drv;
2918 struct net_device *dev;
2919 struct cfg80211_disassoc_request req;
2920 struct wiphy *wiphy;
2921 int err;
2922
2923 rtnl_lock();
2924
2925 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2926 if (err)
2927 goto unlock_rtnl;
2928
2929 if (!drv->ops->disassoc) {
2930 err = -EOPNOTSUPP;
2931 goto out;
2932 }
2933
2934 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2935 err = -EOPNOTSUPP;
2936 goto out;
2937 }
2938
2939 if (!netif_running(dev)) {
2940 err = -ENETDOWN;
2941 goto out;
2942 }
2943
2944 if (!info->attrs[NL80211_ATTR_MAC]) {
2945 err = -EINVAL;
2946 goto out;
2947 }
2948
2949 wiphy = &drv->wiphy;
2950 memset(&req, 0, sizeof(req));
2951
2952 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2953
2954 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
2955 req.reason_code =
2956 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
2957 if (req.reason_code == 0) {
2958 /* Reason Code 0 is reserved */
2959 err = -EINVAL;
2960 goto out;
2961 }
2962 }
2963
2964 if (info->attrs[NL80211_ATTR_IE]) {
2965 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2966 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2967 }
2968
2969 err = drv->ops->disassoc(&drv->wiphy, dev, &req);
2970
2971out:
2972 cfg80211_put_dev(drv);
2973 dev_put(dev);
2974unlock_rtnl:
2975 rtnl_unlock();
2976 return err;
2977}
2978
2137static struct genl_ops nl80211_ops[] = { 2979static struct genl_ops nl80211_ops[] = {
2138 { 2980 {
2139 .cmd = NL80211_CMD_GET_WIPHY, 2981 .cmd = NL80211_CMD_GET_WIPHY,
@@ -2220,7 +3062,6 @@ static struct genl_ops nl80211_ops[] = {
2220 .doit = nl80211_get_station, 3062 .doit = nl80211_get_station,
2221 .dumpit = nl80211_dump_station, 3063 .dumpit = nl80211_dump_station,
2222 .policy = nl80211_policy, 3064 .policy = nl80211_policy,
2223 .flags = GENL_ADMIN_PERM,
2224 }, 3065 },
2225 { 3066 {
2226 .cmd = NL80211_CMD_SET_STATION, 3067 .cmd = NL80211_CMD_SET_STATION,
@@ -2272,6 +3113,12 @@ static struct genl_ops nl80211_ops[] = {
2272 .flags = GENL_ADMIN_PERM, 3113 .flags = GENL_ADMIN_PERM,
2273 }, 3114 },
2274 { 3115 {
3116 .cmd = NL80211_CMD_GET_REG,
3117 .doit = nl80211_get_reg,
3118 .policy = nl80211_policy,
3119 /* can be retrieved by unprivileged users */
3120 },
3121 {
2275 .cmd = NL80211_CMD_SET_REG, 3122 .cmd = NL80211_CMD_SET_REG,
2276 .doit = nl80211_set_reg, 3123 .doit = nl80211_set_reg,
2277 .policy = nl80211_policy, 3124 .policy = nl80211_policy,
@@ -2295,12 +3142,56 @@ static struct genl_ops nl80211_ops[] = {
2295 .policy = nl80211_policy, 3142 .policy = nl80211_policy,
2296 .flags = GENL_ADMIN_PERM, 3143 .flags = GENL_ADMIN_PERM,
2297 }, 3144 },
3145 {
3146 .cmd = NL80211_CMD_TRIGGER_SCAN,
3147 .doit = nl80211_trigger_scan,
3148 .policy = nl80211_policy,
3149 .flags = GENL_ADMIN_PERM,
3150 },
3151 {
3152 .cmd = NL80211_CMD_GET_SCAN,
3153 .policy = nl80211_policy,
3154 .dumpit = nl80211_dump_scan,
3155 },
3156 {
3157 .cmd = NL80211_CMD_AUTHENTICATE,
3158 .doit = nl80211_authenticate,
3159 .policy = nl80211_policy,
3160 .flags = GENL_ADMIN_PERM,
3161 },
3162 {
3163 .cmd = NL80211_CMD_ASSOCIATE,
3164 .doit = nl80211_associate,
3165 .policy = nl80211_policy,
3166 .flags = GENL_ADMIN_PERM,
3167 },
3168 {
3169 .cmd = NL80211_CMD_DEAUTHENTICATE,
3170 .doit = nl80211_deauthenticate,
3171 .policy = nl80211_policy,
3172 .flags = GENL_ADMIN_PERM,
3173 },
3174 {
3175 .cmd = NL80211_CMD_DISASSOCIATE,
3176 .doit = nl80211_disassociate,
3177 .policy = nl80211_policy,
3178 .flags = GENL_ADMIN_PERM,
3179 },
3180};
3181static struct genl_multicast_group nl80211_mlme_mcgrp = {
3182 .name = "mlme",
2298}; 3183};
2299 3184
2300/* multicast groups */ 3185/* multicast groups */
2301static struct genl_multicast_group nl80211_config_mcgrp = { 3186static struct genl_multicast_group nl80211_config_mcgrp = {
2302 .name = "config", 3187 .name = "config",
2303}; 3188};
3189static struct genl_multicast_group nl80211_scan_mcgrp = {
3190 .name = "scan",
3191};
3192static struct genl_multicast_group nl80211_regulatory_mcgrp = {
3193 .name = "regulatory",
3194};
2304 3195
2305/* notification functions */ 3196/* notification functions */
2306 3197
@@ -2320,6 +3211,186 @@ void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
2320 genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL); 3211 genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL);
2321} 3212}
2322 3213
3214static int nl80211_send_scan_donemsg(struct sk_buff *msg,
3215 struct cfg80211_registered_device *rdev,
3216 struct net_device *netdev,
3217 u32 pid, u32 seq, int flags,
3218 u32 cmd)
3219{
3220 void *hdr;
3221
3222 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
3223 if (!hdr)
3224 return -1;
3225
3226 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3227 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3228
3229 /* XXX: we should probably bounce back the request? */
3230
3231 return genlmsg_end(msg, hdr);
3232
3233 nla_put_failure:
3234 genlmsg_cancel(msg, hdr);
3235 return -EMSGSIZE;
3236}
3237
3238void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
3239 struct net_device *netdev)
3240{
3241 struct sk_buff *msg;
3242
3243 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3244 if (!msg)
3245 return;
3246
3247 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
3248 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
3249 nlmsg_free(msg);
3250 return;
3251 }
3252
3253 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
3254}
3255
3256void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
3257 struct net_device *netdev)
3258{
3259 struct sk_buff *msg;
3260
3261 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3262 if (!msg)
3263 return;
3264
3265 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
3266 NL80211_CMD_SCAN_ABORTED) < 0) {
3267 nlmsg_free(msg);
3268 return;
3269 }
3270
3271 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
3272}
3273
3274/*
3275 * This can happen on global regulatory changes or device specific settings
3276 * based on custom world regulatory domains.
3277 */
3278void nl80211_send_reg_change_event(struct regulatory_request *request)
3279{
3280 struct sk_buff *msg;
3281 void *hdr;
3282
3283 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3284 if (!msg)
3285 return;
3286
3287 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
3288 if (!hdr) {
3289 nlmsg_free(msg);
3290 return;
3291 }
3292
3293 /* Userspace can always count this one always being set */
3294 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
3295
3296 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
3297 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3298 NL80211_REGDOM_TYPE_WORLD);
3299 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
3300 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3301 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
3302 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
3303 request->intersect)
3304 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3305 NL80211_REGDOM_TYPE_INTERSECTION);
3306 else {
3307 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3308 NL80211_REGDOM_TYPE_COUNTRY);
3309 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
3310 }
3311
3312 if (wiphy_idx_valid(request->wiphy_idx))
3313 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
3314
3315 if (genlmsg_end(msg, hdr) < 0) {
3316 nlmsg_free(msg);
3317 return;
3318 }
3319
3320 genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_KERNEL);
3321
3322 return;
3323
3324nla_put_failure:
3325 genlmsg_cancel(msg, hdr);
3326 nlmsg_free(msg);
3327}
3328
3329static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
3330 struct net_device *netdev,
3331 const u8 *buf, size_t len,
3332 enum nl80211_commands cmd)
3333{
3334 struct sk_buff *msg;
3335 void *hdr;
3336
3337 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3338 if (!msg)
3339 return;
3340
3341 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
3342 if (!hdr) {
3343 nlmsg_free(msg);
3344 return;
3345 }
3346
3347 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3348 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3349 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
3350
3351 if (genlmsg_end(msg, hdr) < 0) {
3352 nlmsg_free(msg);
3353 return;
3354 }
3355
3356 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL);
3357 return;
3358
3359 nla_put_failure:
3360 genlmsg_cancel(msg, hdr);
3361 nlmsg_free(msg);
3362}
3363
3364void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
3365 struct net_device *netdev, const u8 *buf, size_t len)
3366{
3367 nl80211_send_mlme_event(rdev, netdev, buf, len,
3368 NL80211_CMD_AUTHENTICATE);
3369}
3370
3371void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
3372 struct net_device *netdev, const u8 *buf,
3373 size_t len)
3374{
3375 nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE);
3376}
3377
3378void nl80211_send_rx_deauth(struct cfg80211_registered_device *rdev,
3379 struct net_device *netdev, const u8 *buf,
3380 size_t len)
3381{
3382 nl80211_send_mlme_event(rdev, netdev, buf, len,
3383 NL80211_CMD_DEAUTHENTICATE);
3384}
3385
3386void nl80211_send_rx_disassoc(struct cfg80211_registered_device *rdev,
3387 struct net_device *netdev, const u8 *buf,
3388 size_t len)
3389{
3390 nl80211_send_mlme_event(rdev, netdev, buf, len,
3391 NL80211_CMD_DISASSOCIATE);
3392}
3393
2323/* initialisation/exit functions */ 3394/* initialisation/exit functions */
2324 3395
2325int nl80211_init(void) 3396int nl80211_init(void)
@@ -2340,6 +3411,18 @@ int nl80211_init(void)
2340 if (err) 3411 if (err)
2341 goto err_out; 3412 goto err_out;
2342 3413
3414 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
3415 if (err)
3416 goto err_out;
3417
3418 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
3419 if (err)
3420 goto err_out;
3421
3422 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
3423 if (err)
3424 goto err_out;
3425
2343 return 0; 3426 return 0;
2344 err_out: 3427 err_out:
2345 genl_unregister_family(&nl80211_fam); 3428 genl_unregister_family(&nl80211_fam);