aboutsummaryrefslogtreecommitdiffstats
path: root/net/wireless
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /net/wireless
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'net/wireless')
-rw-r--r--net/wireless/Kconfig2
-rw-r--r--net/wireless/Makefile2
-rw-r--r--net/wireless/chan.c54
-rw-r--r--net/wireless/core.c231
-rw-r--r--net/wireless/core.h88
-rw-r--r--net/wireless/debugfs.c2
-rw-r--r--net/wireless/ethtool.c33
-rw-r--r--net/wireless/ibss.c21
-rw-r--r--net/wireless/lib80211.c8
-rw-r--r--net/wireless/lib80211_crypt_tkip.c16
-rw-r--r--net/wireless/lib80211_crypt_wep.c3
-rw-r--r--net/wireless/mesh.c161
-rw-r--r--net/wireless/mlme.c279
-rw-r--r--net/wireless/nl80211.c3581
-rw-r--r--net/wireless/nl80211.h35
-rw-r--r--net/wireless/radiotap.c61
-rw-r--r--net/wireless/reg.c407
-rw-r--r--net/wireless/reg.h1
-rw-r--r--net/wireless/scan.c162
-rw-r--r--net/wireless/sme.c30
-rw-r--r--net/wireless/sysfs.c20
-rw-r--r--net/wireless/util.c230
-rw-r--r--net/wireless/wext-compat.c59
-rw-r--r--net/wireless/wext-core.c12
-rw-r--r--net/wireless/wext-sme.c2
25 files changed, 3631 insertions, 1869 deletions
diff --git a/net/wireless/Kconfig b/net/wireless/Kconfig
index d0ee29063e5d..1f1ef70f34f2 100644
--- a/net/wireless/Kconfig
+++ b/net/wireless/Kconfig
@@ -95,7 +95,7 @@ config CFG80211_DEBUGFS
95 If unsure, say N. 95 If unsure, say N.
96 96
97config CFG80211_INTERNAL_REGDB 97config CFG80211_INTERNAL_REGDB
98 bool "use statically compiled regulatory rules database" if EMBEDDED 98 bool "use statically compiled regulatory rules database" if EXPERT
99 default n 99 default n
100 depends on CFG80211 100 depends on CFG80211
101 ---help--- 101 ---help---
diff --git a/net/wireless/Makefile b/net/wireless/Makefile
index e77e508126fa..55a28ab21db9 100644
--- a/net/wireless/Makefile
+++ b/net/wireless/Makefile
@@ -10,7 +10,7 @@ obj-$(CONFIG_WEXT_SPY) += wext-spy.o
10obj-$(CONFIG_WEXT_PRIV) += wext-priv.o 10obj-$(CONFIG_WEXT_PRIV) += wext-priv.o
11 11
12cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o 12cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o
13cfg80211-y += mlme.o ibss.o sme.o chan.o ethtool.o 13cfg80211-y += mlme.o ibss.o sme.o chan.o ethtool.o mesh.o
14cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o 14cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o
15cfg80211-$(CONFIG_CFG80211_WEXT) += wext-compat.o wext-sme.o 15cfg80211-$(CONFIG_CFG80211_WEXT) += wext-compat.o wext-sme.o
16cfg80211-$(CONFIG_CFG80211_INTERNAL_REGDB) += regdb.o 16cfg80211-$(CONFIG_CFG80211_INTERNAL_REGDB) += regdb.o
diff --git a/net/wireless/chan.c b/net/wireless/chan.c
index d0c92dddb26b..17cd0c04d139 100644
--- a/net/wireless/chan.c
+++ b/net/wireless/chan.c
@@ -44,6 +44,38 @@ rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
44 return chan; 44 return chan;
45} 45}
46 46
47static bool can_beacon_sec_chan(struct wiphy *wiphy,
48 struct ieee80211_channel *chan,
49 enum nl80211_channel_type channel_type)
50{
51 struct ieee80211_channel *sec_chan;
52 int diff;
53
54 switch (channel_type) {
55 case NL80211_CHAN_HT40PLUS:
56 diff = 20;
57 break;
58 case NL80211_CHAN_HT40MINUS:
59 diff = -20;
60 break;
61 default:
62 return false;
63 }
64
65 sec_chan = ieee80211_get_channel(wiphy, chan->center_freq + diff);
66 if (!sec_chan)
67 return false;
68
69 /* we'll need a DFS capability later */
70 if (sec_chan->flags & (IEEE80211_CHAN_DISABLED |
71 IEEE80211_CHAN_PASSIVE_SCAN |
72 IEEE80211_CHAN_NO_IBSS |
73 IEEE80211_CHAN_RADAR))
74 return false;
75
76 return true;
77}
78
47int cfg80211_set_freq(struct cfg80211_registered_device *rdev, 79int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
48 struct wireless_dev *wdev, int freq, 80 struct wireless_dev *wdev, int freq,
49 enum nl80211_channel_type channel_type) 81 enum nl80211_channel_type channel_type)
@@ -68,6 +100,28 @@ int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
68 if (!chan) 100 if (!chan)
69 return -EINVAL; 101 return -EINVAL;
70 102
103 /* Both channels should be able to initiate communication */
104 if (wdev && (wdev->iftype == NL80211_IFTYPE_ADHOC ||
105 wdev->iftype == NL80211_IFTYPE_AP ||
106 wdev->iftype == NL80211_IFTYPE_AP_VLAN ||
107 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
108 wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
109 switch (channel_type) {
110 case NL80211_CHAN_HT40PLUS:
111 case NL80211_CHAN_HT40MINUS:
112 if (!can_beacon_sec_chan(&rdev->wiphy, chan,
113 channel_type)) {
114 printk(KERN_DEBUG
115 "cfg80211: Secondary channel not "
116 "allowed to initiate communication\n");
117 return -EINVAL;
118 }
119 break;
120 default:
121 break;
122 }
123 }
124
71 result = rdev->ops->set_channel(&rdev->wiphy, 125 result = rdev->ops->set_channel(&rdev->wiphy,
72 wdev ? wdev->netdev : NULL, 126 wdev ? wdev->netdev : NULL,
73 chan, channel_type); 127 chan, channel_type);
diff --git a/net/wireless/core.c b/net/wireless/core.c
index d6d046b9f6f2..880dbe2e6f94 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -4,6 +4,8 @@
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> 4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 */ 5 */
6 6
7#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8
7#include <linux/if.h> 9#include <linux/if.h>
8#include <linux/module.h> 10#include <linux/module.h>
9#include <linux/err.h> 11#include <linux/err.h>
@@ -44,6 +46,11 @@ static struct dentry *ieee80211_debugfs_dir;
44/* for the cleanup, scan and event works */ 46/* for the cleanup, scan and event works */
45struct workqueue_struct *cfg80211_wq; 47struct workqueue_struct *cfg80211_wq;
46 48
49static bool cfg80211_disable_40mhz_24ghz;
50module_param(cfg80211_disable_40mhz_24ghz, bool, 0644);
51MODULE_PARM_DESC(cfg80211_disable_40mhz_24ghz,
52 "Disable 40MHz support in the 2.4GHz band");
53
47/* requires cfg80211_mutex to be held! */ 54/* requires cfg80211_mutex to be held! */
48struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx) 55struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx)
49{ 56{
@@ -216,8 +223,7 @@ int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
216 rdev->wiphy.debugfsdir, 223 rdev->wiphy.debugfsdir,
217 rdev->wiphy.debugfsdir->d_parent, 224 rdev->wiphy.debugfsdir->d_parent,
218 newname)) 225 newname))
219 printk(KERN_ERR "cfg80211: failed to rename debugfs dir to %s!\n", 226 pr_err("failed to rename debugfs dir to %s!\n", newname);
220 newname);
221 227
222 nl80211_notify_dev_rename(rdev); 228 nl80211_notify_dev_rename(rdev);
223 229
@@ -253,11 +259,16 @@ int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
253 WARN_ON(err); 259 WARN_ON(err);
254 wdev->netdev->features |= NETIF_F_NETNS_LOCAL; 260 wdev->netdev->features |= NETIF_F_NETNS_LOCAL;
255 } 261 }
262
263 return err;
256 } 264 }
257 265
258 wiphy_net_set(&rdev->wiphy, net); 266 wiphy_net_set(&rdev->wiphy, net);
259 267
260 return err; 268 err = device_rename(&rdev->wiphy.dev, dev_name(&rdev->wiphy.dev));
269 WARN_ON(err);
270
271 return 0;
261} 272}
262 273
263static void cfg80211_rfkill_poll(struct rfkill *rfkill, void *data) 274static void cfg80211_rfkill_poll(struct rfkill *rfkill, void *data)
@@ -326,6 +337,7 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
326 WARN_ON(ops->add_virtual_intf && !ops->del_virtual_intf); 337 WARN_ON(ops->add_virtual_intf && !ops->del_virtual_intf);
327 WARN_ON(ops->add_station && !ops->del_station); 338 WARN_ON(ops->add_station && !ops->del_station);
328 WARN_ON(ops->add_mpath && !ops->del_mpath); 339 WARN_ON(ops->add_mpath && !ops->del_mpath);
340 WARN_ON(ops->join_mesh && !ops->leave_mesh);
329 341
330 alloc_size = sizeof(*rdev) + sizeof_priv; 342 alloc_size = sizeof(*rdev) + sizeof_priv;
331 343
@@ -354,11 +366,12 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
354 366
355 mutex_init(&rdev->mtx); 367 mutex_init(&rdev->mtx);
356 mutex_init(&rdev->devlist_mtx); 368 mutex_init(&rdev->devlist_mtx);
369 mutex_init(&rdev->sched_scan_mtx);
357 INIT_LIST_HEAD(&rdev->netdev_list); 370 INIT_LIST_HEAD(&rdev->netdev_list);
358 spin_lock_init(&rdev->bss_lock); 371 spin_lock_init(&rdev->bss_lock);
359 INIT_LIST_HEAD(&rdev->bss_list); 372 INIT_LIST_HEAD(&rdev->bss_list);
360 INIT_WORK(&rdev->scan_done_wk, __cfg80211_scan_done); 373 INIT_WORK(&rdev->scan_done_wk, __cfg80211_scan_done);
361 374 INIT_WORK(&rdev->sched_scan_results_wk, __cfg80211_sched_scan_results);
362#ifdef CONFIG_CFG80211_WEXT 375#ifdef CONFIG_CFG80211_WEXT
363 rdev->wiphy.wext = &cfg80211_wext_handler; 376 rdev->wiphy.wext = &cfg80211_wext_handler;
364#endif 377#endif
@@ -404,6 +417,67 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
404} 417}
405EXPORT_SYMBOL(wiphy_new); 418EXPORT_SYMBOL(wiphy_new);
406 419
420static int wiphy_verify_combinations(struct wiphy *wiphy)
421{
422 const struct ieee80211_iface_combination *c;
423 int i, j;
424
425 /* If we have combinations enforce them */
426 if (wiphy->n_iface_combinations)
427 wiphy->flags |= WIPHY_FLAG_ENFORCE_COMBINATIONS;
428
429 for (i = 0; i < wiphy->n_iface_combinations; i++) {
430 u32 cnt = 0;
431 u16 all_iftypes = 0;
432
433 c = &wiphy->iface_combinations[i];
434
435 /* Combinations with just one interface aren't real */
436 if (WARN_ON(c->max_interfaces < 2))
437 return -EINVAL;
438
439 /* Need at least one channel */
440 if (WARN_ON(!c->num_different_channels))
441 return -EINVAL;
442
443 if (WARN_ON(!c->n_limits))
444 return -EINVAL;
445
446 for (j = 0; j < c->n_limits; j++) {
447 u16 types = c->limits[j].types;
448
449 /*
450 * interface types shouldn't overlap, this is
451 * used in cfg80211_can_change_interface()
452 */
453 if (WARN_ON(types & all_iftypes))
454 return -EINVAL;
455 all_iftypes |= types;
456
457 if (WARN_ON(!c->limits[j].max))
458 return -EINVAL;
459
460 /* Shouldn't list software iftypes in combinations! */
461 if (WARN_ON(wiphy->software_iftypes & types))
462 return -EINVAL;
463
464 cnt += c->limits[j].max;
465 /*
466 * Don't advertise an unsupported type
467 * in a combination.
468 */
469 if (WARN_ON((wiphy->interface_modes & types) != types))
470 return -EINVAL;
471 }
472
473 /* You can't even choose that many! */
474 if (WARN_ON(cnt < c->max_interfaces))
475 return -EINVAL;
476 }
477
478 return 0;
479}
480
407int wiphy_register(struct wiphy *wiphy) 481int wiphy_register(struct wiphy *wiphy)
408{ 482{
409 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 483 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
@@ -428,10 +502,14 @@ int wiphy_register(struct wiphy *wiphy)
428 502
429 /* sanity check ifmodes */ 503 /* sanity check ifmodes */
430 WARN_ON(!ifmodes); 504 WARN_ON(!ifmodes);
431 ifmodes &= ((1 << __NL80211_IFTYPE_AFTER_LAST) - 1) & ~1; 505 ifmodes &= ((1 << NUM_NL80211_IFTYPES) - 1) & ~1;
432 if (WARN_ON(ifmodes != wiphy->interface_modes)) 506 if (WARN_ON(ifmodes != wiphy->interface_modes))
433 wiphy->interface_modes = ifmodes; 507 wiphy->interface_modes = ifmodes;
434 508
509 res = wiphy_verify_combinations(wiphy);
510 if (res)
511 return res;
512
435 /* sanity check supported bands/channels */ 513 /* sanity check supported bands/channels */
436 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 514 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
437 sband = wiphy->bands[band]; 515 sband = wiphy->bands[band];
@@ -444,6 +522,18 @@ int wiphy_register(struct wiphy *wiphy)
444 return -EINVAL; 522 return -EINVAL;
445 523
446 /* 524 /*
525 * Since cfg80211_disable_40mhz_24ghz is global, we can
526 * modify the sband's ht data even if the driver uses a
527 * global structure for that.
528 */
529 if (cfg80211_disable_40mhz_24ghz &&
530 band == IEEE80211_BAND_2GHZ &&
531 sband->ht_cap.ht_supported) {
532 sband->ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
533 sband->ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
534 }
535
536 /*
447 * Since we use a u32 for rate bitmaps in 537 * Since we use a u32 for rate bitmaps in
448 * ieee80211_get_response_rate, we cannot 538 * ieee80211_get_response_rate, we cannot
449 * have more than 32 legacy rates. 539 * have more than 32 legacy rates.
@@ -469,6 +559,13 @@ int wiphy_register(struct wiphy *wiphy)
469 return -EINVAL; 559 return -EINVAL;
470 } 560 }
471 561
562 if (rdev->wiphy.wowlan.n_patterns) {
563 if (WARN_ON(!rdev->wiphy.wowlan.pattern_min_len ||
564 rdev->wiphy.wowlan.pattern_min_len >
565 rdev->wiphy.wowlan.pattern_max_len))
566 return -EINVAL;
567 }
568
472 /* check and set up bitrates */ 569 /* check and set up bitrates */
473 ieee80211_set_bitrate_flags(wiphy); 570 ieee80211_set_bitrate_flags(wiphy);
474 571
@@ -605,8 +702,10 @@ void cfg80211_dev_free(struct cfg80211_registered_device *rdev)
605 rfkill_destroy(rdev->rfkill); 702 rfkill_destroy(rdev->rfkill);
606 mutex_destroy(&rdev->mtx); 703 mutex_destroy(&rdev->mtx);
607 mutex_destroy(&rdev->devlist_mtx); 704 mutex_destroy(&rdev->devlist_mtx);
705 mutex_destroy(&rdev->sched_scan_mtx);
608 list_for_each_entry_safe(scan, tmp, &rdev->bss_list, list) 706 list_for_each_entry_safe(scan, tmp, &rdev->bss_list, list)
609 cfg80211_put_bss(&scan->pub); 707 cfg80211_put_bss(&scan->pub);
708 cfg80211_rdev_free_wowlan(rdev);
610 kfree(rdev); 709 kfree(rdev);
611} 710}
612 711
@@ -642,6 +741,15 @@ static void wdev_cleanup_work(struct work_struct *work)
642 741
643 cfg80211_unlock_rdev(rdev); 742 cfg80211_unlock_rdev(rdev);
644 743
744 mutex_lock(&rdev->sched_scan_mtx);
745
746 if (WARN_ON(rdev->sched_scan_req &&
747 rdev->sched_scan_req->dev == wdev->netdev)) {
748 __cfg80211_stop_sched_scan(rdev, false);
749 }
750
751 mutex_unlock(&rdev->sched_scan_mtx);
752
645 mutex_lock(&rdev->devlist_mtx); 753 mutex_lock(&rdev->devlist_mtx);
646 rdev->opencount--; 754 rdev->opencount--;
647 mutex_unlock(&rdev->devlist_mtx); 755 mutex_unlock(&rdev->devlist_mtx);
@@ -661,6 +769,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
661 struct net_device *dev = ndev; 769 struct net_device *dev = ndev;
662 struct wireless_dev *wdev = dev->ieee80211_ptr; 770 struct wireless_dev *wdev = dev->ieee80211_ptr;
663 struct cfg80211_registered_device *rdev; 771 struct cfg80211_registered_device *rdev;
772 int ret;
664 773
665 if (!wdev) 774 if (!wdev)
666 return NOTIFY_DONE; 775 return NOTIFY_DONE;
@@ -683,8 +792,8 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
683 INIT_WORK(&wdev->cleanup_work, wdev_cleanup_work); 792 INIT_WORK(&wdev->cleanup_work, wdev_cleanup_work);
684 INIT_LIST_HEAD(&wdev->event_list); 793 INIT_LIST_HEAD(&wdev->event_list);
685 spin_lock_init(&wdev->event_lock); 794 spin_lock_init(&wdev->event_lock);
686 INIT_LIST_HEAD(&wdev->action_registrations); 795 INIT_LIST_HEAD(&wdev->mgmt_registrations);
687 spin_lock_init(&wdev->action_registrations_lock); 796 spin_lock_init(&wdev->mgmt_registrations_lock);
688 797
689 mutex_lock(&rdev->devlist_mtx); 798 mutex_lock(&rdev->devlist_mtx);
690 list_add_rcu(&wdev->list, &rdev->netdev_list); 799 list_add_rcu(&wdev->list, &rdev->netdev_list);
@@ -694,8 +803,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
694 803
695 if (sysfs_create_link(&dev->dev.kobj, &rdev->wiphy.dev.kobj, 804 if (sysfs_create_link(&dev->dev.kobj, &rdev->wiphy.dev.kobj,
696 "phy80211")) { 805 "phy80211")) {
697 printk(KERN_ERR "wireless: failed to add phy80211 " 806 pr_err("failed to add phy80211 symlink to netdev!\n");
698 "symlink to netdev!\n");
699 } 807 }
700 wdev->netdev = dev; 808 wdev->netdev = dev;
701 wdev->sme_state = CFG80211_SME_IDLE; 809 wdev->sme_state = CFG80211_SME_IDLE;
@@ -712,18 +820,12 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
712 wdev->ps = false; 820 wdev->ps = false;
713 /* allow mac80211 to determine the timeout */ 821 /* allow mac80211 to determine the timeout */
714 wdev->ps_timeout = -1; 822 wdev->ps_timeout = -1;
715 if (rdev->ops->set_power_mgmt)
716 if (rdev->ops->set_power_mgmt(wdev->wiphy, dev,
717 wdev->ps,
718 wdev->ps_timeout)) {
719 /* assume this means it's off */
720 wdev->ps = false;
721 }
722 823
723 if (!dev->ethtool_ops) 824 if (!dev->ethtool_ops)
724 dev->ethtool_ops = &cfg80211_ethtool_ops; 825 dev->ethtool_ops = &cfg80211_ethtool_ops;
725 826
726 if ((wdev->iftype == NL80211_IFTYPE_STATION || 827 if ((wdev->iftype == NL80211_IFTYPE_STATION ||
828 wdev->iftype == NL80211_IFTYPE_P2P_CLIENT ||
727 wdev->iftype == NL80211_IFTYPE_ADHOC) && !wdev->use_4addr) 829 wdev->iftype == NL80211_IFTYPE_ADHOC) && !wdev->use_4addr)
728 dev->priv_flags |= IFF_DONT_BRIDGE; 830 dev->priv_flags |= IFF_DONT_BRIDGE;
729 break; 831 break;
@@ -732,7 +834,12 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
732 case NL80211_IFTYPE_ADHOC: 834 case NL80211_IFTYPE_ADHOC:
733 cfg80211_leave_ibss(rdev, dev, true); 835 cfg80211_leave_ibss(rdev, dev, true);
734 break; 836 break;
837 case NL80211_IFTYPE_P2P_CLIENT:
735 case NL80211_IFTYPE_STATION: 838 case NL80211_IFTYPE_STATION:
839 mutex_lock(&rdev->sched_scan_mtx);
840 __cfg80211_stop_sched_scan(rdev, false);
841 mutex_unlock(&rdev->sched_scan_mtx);
842
736 wdev_lock(wdev); 843 wdev_lock(wdev);
737#ifdef CONFIG_CFG80211_WEXT 844#ifdef CONFIG_CFG80211_WEXT
738 kfree(wdev->wext.ie); 845 kfree(wdev->wext.ie);
@@ -745,9 +852,13 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
745 cfg80211_mlme_down(rdev, dev); 852 cfg80211_mlme_down(rdev, dev);
746 wdev_unlock(wdev); 853 wdev_unlock(wdev);
747 break; 854 break;
855 case NL80211_IFTYPE_MESH_POINT:
856 cfg80211_leave_mesh(rdev, dev);
857 break;
748 default: 858 default:
749 break; 859 break;
750 } 860 }
861 wdev->beacon_interval = 0;
751 break; 862 break;
752 case NETDEV_DOWN: 863 case NETDEV_DOWN:
753 dev_hold(dev); 864 dev_hold(dev);
@@ -768,23 +879,53 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
768 } 879 }
769 cfg80211_lock_rdev(rdev); 880 cfg80211_lock_rdev(rdev);
770 mutex_lock(&rdev->devlist_mtx); 881 mutex_lock(&rdev->devlist_mtx);
771#ifdef CONFIG_CFG80211_WEXT
772 wdev_lock(wdev); 882 wdev_lock(wdev);
773 switch (wdev->iftype) { 883 switch (wdev->iftype) {
884#ifdef CONFIG_CFG80211_WEXT
774 case NL80211_IFTYPE_ADHOC: 885 case NL80211_IFTYPE_ADHOC:
775 cfg80211_ibss_wext_join(rdev, wdev); 886 cfg80211_ibss_wext_join(rdev, wdev);
776 break; 887 break;
777 case NL80211_IFTYPE_STATION: 888 case NL80211_IFTYPE_STATION:
778 cfg80211_mgd_wext_connect(rdev, wdev); 889 cfg80211_mgd_wext_connect(rdev, wdev);
779 break; 890 break;
891#endif
892#ifdef CONFIG_MAC80211_MESH
893 case NL80211_IFTYPE_MESH_POINT:
894 {
895 /* backward compat code... */
896 struct mesh_setup setup;
897 memcpy(&setup, &default_mesh_setup,
898 sizeof(setup));
899 /* back compat only needed for mesh_id */
900 setup.mesh_id = wdev->ssid;
901 setup.mesh_id_len = wdev->mesh_id_up_len;
902 if (wdev->mesh_id_up_len)
903 __cfg80211_join_mesh(rdev, dev,
904 &setup,
905 &default_mesh_config);
906 break;
907 }
908#endif
780 default: 909 default:
781 break; 910 break;
782 } 911 }
783 wdev_unlock(wdev); 912 wdev_unlock(wdev);
784#endif
785 rdev->opencount++; 913 rdev->opencount++;
786 mutex_unlock(&rdev->devlist_mtx); 914 mutex_unlock(&rdev->devlist_mtx);
787 cfg80211_unlock_rdev(rdev); 915 cfg80211_unlock_rdev(rdev);
916
917 /*
918 * Configure power management to the driver here so that its
919 * correctly set also after interface type changes etc.
920 */
921 if (wdev->iftype == NL80211_IFTYPE_STATION &&
922 rdev->ops->set_power_mgmt)
923 if (rdev->ops->set_power_mgmt(wdev->wiphy, dev,
924 wdev->ps,
925 wdev->ps_timeout)) {
926 /* assume this means it's off */
927 wdev->ps = false;
928 }
788 break; 929 break;
789 case NETDEV_UNREGISTER: 930 case NETDEV_UNREGISTER:
790 /* 931 /*
@@ -804,7 +945,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
804 sysfs_remove_link(&dev->dev.kobj, "phy80211"); 945 sysfs_remove_link(&dev->dev.kobj, "phy80211");
805 list_del_rcu(&wdev->list); 946 list_del_rcu(&wdev->list);
806 rdev->devlist_generation++; 947 rdev->devlist_generation++;
807 cfg80211_mlme_purge_actions(wdev); 948 cfg80211_mlme_purge_registrations(wdev);
808#ifdef CONFIG_CFG80211_WEXT 949#ifdef CONFIG_CFG80211_WEXT
809 kfree(wdev->wext.keys); 950 kfree(wdev->wext.keys);
810#endif 951#endif
@@ -824,6 +965,9 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
824 return notifier_from_errno(-EOPNOTSUPP); 965 return notifier_from_errno(-EOPNOTSUPP);
825 if (rfkill_blocked(rdev->rfkill)) 966 if (rfkill_blocked(rdev->rfkill))
826 return notifier_from_errno(-ERFKILL); 967 return notifier_from_errno(-ERFKILL);
968 ret = cfg80211_can_add_interface(rdev, wdev->iftype);
969 if (ret)
970 return notifier_from_errno(ret);
827 break; 971 break;
828 } 972 }
829 973
@@ -910,52 +1054,3 @@ static void __exit cfg80211_exit(void)
910 destroy_workqueue(cfg80211_wq); 1054 destroy_workqueue(cfg80211_wq);
911} 1055}
912module_exit(cfg80211_exit); 1056module_exit(cfg80211_exit);
913
914static int ___wiphy_printk(const char *level, const struct wiphy *wiphy,
915 struct va_format *vaf)
916{
917 if (!wiphy)
918 return printk("%s(NULL wiphy *): %pV", level, vaf);
919
920 return printk("%s%s: %pV", level, wiphy_name(wiphy), vaf);
921}
922
923int __wiphy_printk(const char *level, const struct wiphy *wiphy,
924 const char *fmt, ...)
925{
926 struct va_format vaf;
927 va_list args;
928 int r;
929
930 va_start(args, fmt);
931
932 vaf.fmt = fmt;
933 vaf.va = &args;
934
935 r = ___wiphy_printk(level, wiphy, &vaf);
936 va_end(args);
937
938 return r;
939}
940EXPORT_SYMBOL(__wiphy_printk);
941
942#define define_wiphy_printk_level(func, kern_level) \
943int func(const struct wiphy *wiphy, const char *fmt, ...) \
944{ \
945 struct va_format vaf; \
946 va_list args; \
947 int r; \
948 \
949 va_start(args, fmt); \
950 \
951 vaf.fmt = fmt; \
952 vaf.va = &args; \
953 \
954 r = ___wiphy_printk(kern_level, wiphy, &vaf); \
955 va_end(args); \
956 \
957 return r; \
958} \
959EXPORT_SYMBOL(func);
960
961define_wiphy_printk_level(wiphy_debug, KERN_DEBUG);
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 63d57ae399c3..a570ff9214ec 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -60,8 +60,12 @@ struct cfg80211_registered_device {
60 struct rb_root bss_tree; 60 struct rb_root bss_tree;
61 u32 bss_generation; 61 u32 bss_generation;
62 struct cfg80211_scan_request *scan_req; /* protected by RTNL */ 62 struct cfg80211_scan_request *scan_req; /* protected by RTNL */
63 struct cfg80211_sched_scan_request *sched_scan_req;
63 unsigned long suspend_at; 64 unsigned long suspend_at;
64 struct work_struct scan_done_wk; 65 struct work_struct scan_done_wk;
66 struct work_struct sched_scan_results_wk;
67
68 struct mutex sched_scan_mtx;
65 69
66#ifdef CONFIG_NL80211_TESTMODE 70#ifdef CONFIG_NL80211_TESTMODE
67 struct genl_info *testmode_info; 71 struct genl_info *testmode_info;
@@ -70,6 +74,8 @@ struct cfg80211_registered_device {
70 struct work_struct conn_work; 74 struct work_struct conn_work;
71 struct work_struct event_work; 75 struct work_struct event_work;
72 76
77 struct cfg80211_wowlan *wowlan;
78
73 /* must be last because of the way we do wiphy_priv(), 79 /* must be last because of the way we do wiphy_priv(),
74 * and it should at least be aligned to NETDEV_ALIGN */ 80 * and it should at least be aligned to NETDEV_ALIGN */
75 struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN))); 81 struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN)));
@@ -86,16 +92,31 @@ struct cfg80211_registered_device *wiphy_to_dev(struct wiphy *wiphy)
86static inline 92static inline
87bool wiphy_idx_valid(int wiphy_idx) 93bool wiphy_idx_valid(int wiphy_idx)
88{ 94{
89 return (wiphy_idx >= 0); 95 return wiphy_idx >= 0;
90} 96}
91 97
98static inline void
99cfg80211_rdev_free_wowlan(struct cfg80211_registered_device *rdev)
100{
101 int i;
102
103 if (!rdev->wowlan)
104 return;
105 for (i = 0; i < rdev->wowlan->n_patterns; i++)
106 kfree(rdev->wowlan->patterns[i].mask);
107 kfree(rdev->wowlan->patterns);
108 kfree(rdev->wowlan);
109}
92 110
93extern struct workqueue_struct *cfg80211_wq; 111extern struct workqueue_struct *cfg80211_wq;
94extern struct mutex cfg80211_mutex; 112extern struct mutex cfg80211_mutex;
95extern struct list_head cfg80211_rdev_list; 113extern struct list_head cfg80211_rdev_list;
96extern int cfg80211_rdev_list_generation; 114extern int cfg80211_rdev_list_generation;
97 115
98#define assert_cfg80211_lock() WARN_ON(!mutex_is_locked(&cfg80211_mutex)) 116static inline void assert_cfg80211_lock(void)
117{
118 lockdep_assert_held(&cfg80211_mutex);
119}
99 120
100/* 121/*
101 * You can use this to mark a wiphy_idx as not having an associated wiphy. 122 * You can use this to mark a wiphy_idx as not having an associated wiphy.
@@ -202,8 +223,8 @@ static inline void wdev_unlock(struct wireless_dev *wdev)
202 mutex_unlock(&wdev->mtx); 223 mutex_unlock(&wdev->mtx);
203} 224}
204 225
205#define ASSERT_RDEV_LOCK(rdev) WARN_ON(!mutex_is_locked(&(rdev)->mtx)); 226#define ASSERT_RDEV_LOCK(rdev) lockdep_assert_held(&(rdev)->mtx)
206#define ASSERT_WDEV_LOCK(wdev) WARN_ON(!mutex_is_locked(&(wdev)->mtx)); 227#define ASSERT_WDEV_LOCK(wdev) lockdep_assert_held(&(wdev)->mtx)
207 228
208enum cfg80211_event_type { 229enum cfg80211_event_type {
209 EVENT_CONNECT_RESULT, 230 EVENT_CONNECT_RESULT,
@@ -226,6 +247,7 @@ struct cfg80211_event {
226 u16 status; 247 u16 status;
227 } cr; 248 } cr;
228 struct { 249 struct {
250 struct ieee80211_channel *channel;
229 u8 bssid[ETH_ALEN]; 251 u8 bssid[ETH_ALEN];
230 const u8 *req_ie; 252 const u8 *req_ie;
231 const u8 *resp_ie; 253 const u8 *resp_ie;
@@ -282,6 +304,20 @@ void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid);
282int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev, 304int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
283 struct wireless_dev *wdev); 305 struct wireless_dev *wdev);
284 306
307/* mesh */
308extern const struct mesh_config default_mesh_config;
309extern const struct mesh_setup default_mesh_setup;
310int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
311 struct net_device *dev,
312 const struct mesh_setup *setup,
313 const struct mesh_config *conf);
314int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
315 struct net_device *dev,
316 const struct mesh_setup *setup,
317 const struct mesh_config *conf);
318int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
319 struct net_device *dev);
320
285/* MLME */ 321/* MLME */
286int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, 322int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
287 struct net_device *dev, 323 struct net_device *dev,
@@ -331,16 +367,17 @@ void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
331 const u8 *resp_ie, size_t resp_ie_len, 367 const u8 *resp_ie, size_t resp_ie_len,
332 u16 status, bool wextev, 368 u16 status, bool wextev,
333 struct cfg80211_bss *bss); 369 struct cfg80211_bss *bss);
334int cfg80211_mlme_register_action(struct wireless_dev *wdev, u32 snd_pid, 370int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_pid,
335 const u8 *match_data, int match_len); 371 u16 frame_type, const u8 *match_data,
336void cfg80211_mlme_unregister_actions(struct wireless_dev *wdev, u32 nlpid); 372 int match_len);
337void cfg80211_mlme_purge_actions(struct wireless_dev *wdev); 373void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlpid);
338int cfg80211_mlme_action(struct cfg80211_registered_device *rdev, 374void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev);
339 struct net_device *dev, 375int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
340 struct ieee80211_channel *chan, 376 struct net_device *dev,
341 enum nl80211_channel_type channel_type, 377 struct ieee80211_channel *chan, bool offchan,
342 bool channel_type_valid, 378 enum nl80211_channel_type channel_type,
343 const u8 *buf, size_t len, u64 *cookie); 379 bool channel_type_valid, unsigned int wait,
380 const u8 *buf, size_t len, u64 *cookie);
344 381
345/* SME */ 382/* SME */
346int __cfg80211_connect(struct cfg80211_registered_device *rdev, 383int __cfg80211_connect(struct cfg80211_registered_device *rdev,
@@ -358,7 +395,9 @@ int __cfg80211_disconnect(struct cfg80211_registered_device *rdev,
358int cfg80211_disconnect(struct cfg80211_registered_device *rdev, 395int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
359 struct net_device *dev, u16 reason, 396 struct net_device *dev, u16 reason,
360 bool wextev); 397 bool wextev);
361void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid, 398void __cfg80211_roamed(struct wireless_dev *wdev,
399 struct ieee80211_channel *channel,
400 const u8 *bssid,
362 const u8 *req_ie, size_t req_ie_len, 401 const u8 *req_ie, size_t req_ie_len,
363 const u8 *resp_ie, size_t resp_ie_len); 402 const u8 *resp_ie, size_t resp_ie_len);
364int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev, 403int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev,
@@ -371,7 +410,7 @@ bool cfg80211_sme_failed_reassoc(struct wireless_dev *wdev);
371/* internal helpers */ 410/* internal helpers */
372int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev, 411int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
373 struct key_params *params, int key_idx, 412 struct key_params *params, int key_idx,
374 const u8 *mac_addr); 413 bool pairwise, const u8 *mac_addr);
375void __cfg80211_disconnected(struct net_device *dev, const u8 *ie, 414void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
376 size_t ie_len, u16 reason, bool from_ap); 415 size_t ie_len, u16 reason, bool from_ap);
377void cfg80211_sme_scan_done(struct net_device *dev); 416void cfg80211_sme_scan_done(struct net_device *dev);
@@ -379,12 +418,26 @@ void cfg80211_sme_rx_auth(struct net_device *dev, const u8 *buf, size_t len);
379void cfg80211_sme_disassoc(struct net_device *dev, int idx); 418void cfg80211_sme_disassoc(struct net_device *dev, int idx);
380void __cfg80211_scan_done(struct work_struct *wk); 419void __cfg80211_scan_done(struct work_struct *wk);
381void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak); 420void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak);
421void __cfg80211_sched_scan_results(struct work_struct *wk);
422int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
423 bool driver_initiated);
382void cfg80211_upload_connect_keys(struct wireless_dev *wdev); 424void cfg80211_upload_connect_keys(struct wireless_dev *wdev);
383int cfg80211_change_iface(struct cfg80211_registered_device *rdev, 425int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
384 struct net_device *dev, enum nl80211_iftype ntype, 426 struct net_device *dev, enum nl80211_iftype ntype,
385 u32 *flags, struct vif_params *params); 427 u32 *flags, struct vif_params *params);
386void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev); 428void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev);
387 429
430int cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
431 struct wireless_dev *wdev,
432 enum nl80211_iftype iftype);
433
434static inline int
435cfg80211_can_add_interface(struct cfg80211_registered_device *rdev,
436 enum nl80211_iftype iftype)
437{
438 return cfg80211_can_change_interface(rdev, NULL, iftype);
439}
440
388struct ieee80211_channel * 441struct ieee80211_channel *
389rdev_freq_to_chan(struct cfg80211_registered_device *rdev, 442rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
390 int freq, enum nl80211_channel_type channel_type); 443 int freq, enum nl80211_channel_type channel_type);
@@ -394,6 +447,9 @@ int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
394 447
395u16 cfg80211_calculate_bitrate(struct rate_info *rate); 448u16 cfg80211_calculate_bitrate(struct rate_info *rate);
396 449
450int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
451 u32 beacon_int);
452
397#ifdef CONFIG_CFG80211_DEVELOPER_WARNINGS 453#ifdef CONFIG_CFG80211_DEVELOPER_WARNINGS
398#define CFG80211_DEV_WARN_ON(cond) WARN_ON(cond) 454#define CFG80211_DEV_WARN_ON(cond) WARN_ON(cond)
399#else 455#else
diff --git a/net/wireless/debugfs.c b/net/wireless/debugfs.c
index a4991a3efec0..39765bcfb472 100644
--- a/net/wireless/debugfs.c
+++ b/net/wireless/debugfs.c
@@ -34,6 +34,7 @@ static ssize_t name## _read(struct file *file, char __user *userbuf, \
34static const struct file_operations name## _ops = { \ 34static const struct file_operations name## _ops = { \
35 .read = name## _read, \ 35 .read = name## _read, \
36 .open = cfg80211_open_file_generic, \ 36 .open = cfg80211_open_file_generic, \
37 .llseek = generic_file_llseek, \
37}; 38};
38 39
39DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d", 40DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
@@ -102,6 +103,7 @@ static ssize_t ht40allow_map_read(struct file *file,
102static const struct file_operations ht40allow_map_ops = { 103static const struct file_operations ht40allow_map_ops = {
103 .read = ht40allow_map_read, 104 .read = ht40allow_map_read,
104 .open = cfg80211_open_file_generic, 105 .open = cfg80211_open_file_generic,
106 .llseek = default_llseek,
105}; 107};
106 108
107#define DEBUGFS_ADD(name) \ 109#define DEBUGFS_ADD(name) \
diff --git a/net/wireless/ethtool.c b/net/wireless/ethtool.c
index ca4c825be93d..9bde4d1d3e9b 100644
--- a/net/wireless/ethtool.c
+++ b/net/wireless/ethtool.c
@@ -1,5 +1,6 @@
1#include <linux/utsname.h> 1#include <linux/utsname.h>
2#include <net/cfg80211.h> 2#include <net/cfg80211.h>
3#include "core.h"
3#include "ethtool.h" 4#include "ethtool.h"
4 5
5static void cfg80211_get_drvinfo(struct net_device *dev, 6static void cfg80211_get_drvinfo(struct net_device *dev,
@@ -37,9 +38,41 @@ static void cfg80211_get_regs(struct net_device *dev, struct ethtool_regs *regs,
37 regs->len = 0; 38 regs->len = 0;
38} 39}
39 40
41static void cfg80211_get_ringparam(struct net_device *dev,
42 struct ethtool_ringparam *rp)
43{
44 struct wireless_dev *wdev = dev->ieee80211_ptr;
45 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
46
47 memset(rp, 0, sizeof(*rp));
48
49 if (rdev->ops->get_ringparam)
50 rdev->ops->get_ringparam(wdev->wiphy,
51 &rp->tx_pending, &rp->tx_max_pending,
52 &rp->rx_pending, &rp->rx_max_pending);
53}
54
55static int cfg80211_set_ringparam(struct net_device *dev,
56 struct ethtool_ringparam *rp)
57{
58 struct wireless_dev *wdev = dev->ieee80211_ptr;
59 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
60
61 if (rp->rx_mini_pending != 0 || rp->rx_jumbo_pending != 0)
62 return -EINVAL;
63
64 if (rdev->ops->set_ringparam)
65 return rdev->ops->set_ringparam(wdev->wiphy,
66 rp->tx_pending, rp->rx_pending);
67
68 return -ENOTSUPP;
69}
70
40const struct ethtool_ops cfg80211_ethtool_ops = { 71const struct ethtool_ops cfg80211_ethtool_ops = {
41 .get_drvinfo = cfg80211_get_drvinfo, 72 .get_drvinfo = cfg80211_get_drvinfo,
42 .get_regs_len = cfg80211_get_regs_len, 73 .get_regs_len = cfg80211_get_regs_len,
43 .get_regs = cfg80211_get_regs, 74 .get_regs = cfg80211_get_regs,
44 .get_link = ethtool_op_get_link, 75 .get_link = ethtool_op_get_link,
76 .get_ringparam = cfg80211_get_ringparam,
77 .set_ringparam = cfg80211_set_ringparam,
45}; 78};
diff --git a/net/wireless/ibss.c b/net/wireless/ibss.c
index 27a8ce9343c3..f33fbb79437c 100644
--- a/net/wireless/ibss.c
+++ b/net/wireless/ibss.c
@@ -88,6 +88,25 @@ int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
88 if (wdev->ssid_len) 88 if (wdev->ssid_len)
89 return -EALREADY; 89 return -EALREADY;
90 90
91 if (!params->basic_rates) {
92 /*
93 * If no rates were explicitly configured,
94 * use the mandatory rate set for 11b or
95 * 11a for maximum compatibility.
96 */
97 struct ieee80211_supported_band *sband =
98 rdev->wiphy.bands[params->channel->band];
99 int j;
100 u32 flag = params->channel->band == IEEE80211_BAND_5GHZ ?
101 IEEE80211_RATE_MANDATORY_A :
102 IEEE80211_RATE_MANDATORY_B;
103
104 for (j = 0; j < sband->n_bitrates; j++) {
105 if (sband->bitrates[j].flags & flag)
106 params->basic_rates |= BIT(j);
107 }
108 }
109
91 if (WARN_ON(wdev->connect_keys)) 110 if (WARN_ON(wdev->connect_keys))
92 kfree(wdev->connect_keys); 111 kfree(wdev->connect_keys);
93 wdev->connect_keys = connkeys; 112 wdev->connect_keys = connkeys;
@@ -141,7 +160,7 @@ static void __cfg80211_clear_ibss(struct net_device *dev, bool nowext)
141 */ 160 */
142 if (rdev->ops->del_key) 161 if (rdev->ops->del_key)
143 for (i = 0; i < 6; i++) 162 for (i = 0; i < 6; i++)
144 rdev->ops->del_key(wdev->wiphy, dev, i, NULL); 163 rdev->ops->del_key(wdev->wiphy, dev, i, false, NULL);
145 164
146 if (wdev->current_bss) { 165 if (wdev->current_bss) {
147 cfg80211_unhold_bss(wdev->current_bss); 166 cfg80211_unhold_bss(wdev->current_bss);
diff --git a/net/wireless/lib80211.c b/net/wireless/lib80211.c
index 97d411f74507..3268fac5ab22 100644
--- a/net/wireless/lib80211.c
+++ b/net/wireless/lib80211.c
@@ -13,6 +13,8 @@
13 * 13 *
14 */ 14 */
15 15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
16#include <linux/module.h> 18#include <linux/module.h>
17#include <linux/ctype.h> 19#include <linux/ctype.h>
18#include <linux/ieee80211.h> 20#include <linux/ieee80211.h>
@@ -224,8 +226,8 @@ int lib80211_unregister_crypto_ops(struct lib80211_crypto_ops *ops)
224 return -EINVAL; 226 return -EINVAL;
225 227
226 found: 228 found:
227 printk(KERN_DEBUG "lib80211_crypt: unregistered algorithm " 229 printk(KERN_DEBUG "lib80211_crypt: unregistered algorithm '%s'\n",
228 "'%s'\n", ops->name); 230 ops->name);
229 list_del(&alg->list); 231 list_del(&alg->list);
230 spin_unlock_irqrestore(&lib80211_crypto_lock, flags); 232 spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
231 kfree(alg); 233 kfree(alg);
@@ -270,7 +272,7 @@ static struct lib80211_crypto_ops lib80211_crypt_null = {
270 272
271static int __init lib80211_init(void) 273static int __init lib80211_init(void)
272{ 274{
273 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION "\n"); 275 pr_info(DRV_DESCRIPTION "\n");
274 return lib80211_register_crypto_ops(&lib80211_crypt_null); 276 return lib80211_register_crypto_ops(&lib80211_crypt_null);
275} 277}
276 278
diff --git a/net/wireless/lib80211_crypt_tkip.c b/net/wireless/lib80211_crypt_tkip.c
index 0fe40510e2cb..7ea4f2b0770e 100644
--- a/net/wireless/lib80211_crypt_tkip.c
+++ b/net/wireless/lib80211_crypt_tkip.c
@@ -10,6 +10,8 @@
10 * more details. 10 * more details.
11 */ 11 */
12 12
13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
13#include <linux/err.h> 15#include <linux/err.h>
14#include <linux/module.h> 16#include <linux/module.h>
15#include <linux/init.h> 17#include <linux/init.h>
@@ -99,8 +101,7 @@ static void *lib80211_tkip_init(int key_idx)
99 priv->tx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, 101 priv->tx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0,
100 CRYPTO_ALG_ASYNC); 102 CRYPTO_ALG_ASYNC);
101 if (IS_ERR(priv->tx_tfm_arc4)) { 103 if (IS_ERR(priv->tx_tfm_arc4)) {
102 printk(KERN_DEBUG "lib80211_crypt_tkip: could not allocate " 104 printk(KERN_DEBUG pr_fmt("could not allocate crypto API arc4\n"));
103 "crypto API arc4\n");
104 priv->tx_tfm_arc4 = NULL; 105 priv->tx_tfm_arc4 = NULL;
105 goto fail; 106 goto fail;
106 } 107 }
@@ -108,8 +109,7 @@ static void *lib80211_tkip_init(int key_idx)
108 priv->tx_tfm_michael = crypto_alloc_hash("michael_mic", 0, 109 priv->tx_tfm_michael = crypto_alloc_hash("michael_mic", 0,
109 CRYPTO_ALG_ASYNC); 110 CRYPTO_ALG_ASYNC);
110 if (IS_ERR(priv->tx_tfm_michael)) { 111 if (IS_ERR(priv->tx_tfm_michael)) {
111 printk(KERN_DEBUG "lib80211_crypt_tkip: could not allocate " 112 printk(KERN_DEBUG pr_fmt("could not allocate crypto API michael_mic\n"));
112 "crypto API michael_mic\n");
113 priv->tx_tfm_michael = NULL; 113 priv->tx_tfm_michael = NULL;
114 goto fail; 114 goto fail;
115 } 115 }
@@ -117,8 +117,7 @@ static void *lib80211_tkip_init(int key_idx)
117 priv->rx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, 117 priv->rx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0,
118 CRYPTO_ALG_ASYNC); 118 CRYPTO_ALG_ASYNC);
119 if (IS_ERR(priv->rx_tfm_arc4)) { 119 if (IS_ERR(priv->rx_tfm_arc4)) {
120 printk(KERN_DEBUG "lib80211_crypt_tkip: could not allocate " 120 printk(KERN_DEBUG pr_fmt("could not allocate crypto API arc4\n"));
121 "crypto API arc4\n");
122 priv->rx_tfm_arc4 = NULL; 121 priv->rx_tfm_arc4 = NULL;
123 goto fail; 122 goto fail;
124 } 123 }
@@ -126,8 +125,7 @@ static void *lib80211_tkip_init(int key_idx)
126 priv->rx_tfm_michael = crypto_alloc_hash("michael_mic", 0, 125 priv->rx_tfm_michael = crypto_alloc_hash("michael_mic", 0,
127 CRYPTO_ALG_ASYNC); 126 CRYPTO_ALG_ASYNC);
128 if (IS_ERR(priv->rx_tfm_michael)) { 127 if (IS_ERR(priv->rx_tfm_michael)) {
129 printk(KERN_DEBUG "lib80211_crypt_tkip: could not allocate " 128 printk(KERN_DEBUG pr_fmt("could not allocate crypto API michael_mic\n"));
130 "crypto API michael_mic\n");
131 priv->rx_tfm_michael = NULL; 129 priv->rx_tfm_michael = NULL;
132 goto fail; 130 goto fail;
133 } 131 }
@@ -536,7 +534,7 @@ static int michael_mic(struct crypto_hash *tfm_michael, u8 * key, u8 * hdr,
536 struct scatterlist sg[2]; 534 struct scatterlist sg[2];
537 535
538 if (tfm_michael == NULL) { 536 if (tfm_michael == NULL) {
539 printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n"); 537 pr_warn("%s(): tfm_michael == NULL\n", __func__);
540 return -1; 538 return -1;
541 } 539 }
542 sg_init_table(sg, 2); 540 sg_init_table(sg, 2);
diff --git a/net/wireless/lib80211_crypt_wep.c b/net/wireless/lib80211_crypt_wep.c
index e2e88878ba35..2f265e033ae2 100644
--- a/net/wireless/lib80211_crypt_wep.c
+++ b/net/wireless/lib80211_crypt_wep.c
@@ -96,13 +96,12 @@ static int lib80211_wep_build_iv(struct sk_buff *skb, int hdr_len,
96 u8 *key, int keylen, void *priv) 96 u8 *key, int keylen, void *priv)
97{ 97{
98 struct lib80211_wep_data *wep = priv; 98 struct lib80211_wep_data *wep = priv;
99 u32 klen, len; 99 u32 klen;
100 u8 *pos; 100 u8 *pos;
101 101
102 if (skb_headroom(skb) < 4 || skb->len < hdr_len) 102 if (skb_headroom(skb) < 4 || skb->len < hdr_len)
103 return -1; 103 return -1;
104 104
105 len = skb->len - hdr_len;
106 pos = skb_push(skb, 4); 105 pos = skb_push(skb, 4);
107 memmove(pos, pos + 4, hdr_len); 106 memmove(pos, pos + 4, hdr_len);
108 pos += hdr_len; 107 pos += hdr_len;
diff --git a/net/wireless/mesh.c b/net/wireless/mesh.c
new file mode 100644
index 000000000000..5c116083eeca
--- /dev/null
+++ b/net/wireless/mesh.c
@@ -0,0 +1,161 @@
1#include <linux/ieee80211.h>
2#include <net/cfg80211.h>
3#include "nl80211.h"
4#include "core.h"
5
6/* Default values, timeouts in ms */
7#define MESH_TTL 31
8#define MESH_DEFAULT_ELEMENT_TTL 31
9#define MESH_MAX_RETR 3
10#define MESH_RET_T 100
11#define MESH_CONF_T 100
12#define MESH_HOLD_T 100
13
14#define MESH_PATH_TIMEOUT 5000
15
16/*
17 * Minimum interval between two consecutive PREQs originated by the same
18 * interface
19 */
20#define MESH_PREQ_MIN_INT 10
21#define MESH_DIAM_TRAVERSAL_TIME 50
22
23/*
24 * A path will be refreshed if it is used PATH_REFRESH_TIME milliseconds
25 * before timing out. This way it will remain ACTIVE and no data frames
26 * will be unnecessarily held in the pending queue.
27 */
28#define MESH_PATH_REFRESH_TIME 1000
29#define MESH_MIN_DISCOVERY_TIMEOUT (2 * MESH_DIAM_TRAVERSAL_TIME)
30
31/* Default maximum number of established plinks per interface */
32#define MESH_MAX_ESTAB_PLINKS 32
33
34#define MESH_MAX_PREQ_RETRIES 4
35
36
37const struct mesh_config default_mesh_config = {
38 .dot11MeshRetryTimeout = MESH_RET_T,
39 .dot11MeshConfirmTimeout = MESH_CONF_T,
40 .dot11MeshHoldingTimeout = MESH_HOLD_T,
41 .dot11MeshMaxRetries = MESH_MAX_RETR,
42 .dot11MeshTTL = MESH_TTL,
43 .element_ttl = MESH_DEFAULT_ELEMENT_TTL,
44 .auto_open_plinks = true,
45 .dot11MeshMaxPeerLinks = MESH_MAX_ESTAB_PLINKS,
46 .dot11MeshHWMPactivePathTimeout = MESH_PATH_TIMEOUT,
47 .dot11MeshHWMPpreqMinInterval = MESH_PREQ_MIN_INT,
48 .dot11MeshHWMPnetDiameterTraversalTime = MESH_DIAM_TRAVERSAL_TIME,
49 .dot11MeshHWMPmaxPREQretries = MESH_MAX_PREQ_RETRIES,
50 .path_refresh_time = MESH_PATH_REFRESH_TIME,
51 .min_discovery_timeout = MESH_MIN_DISCOVERY_TIMEOUT,
52};
53
54const struct mesh_setup default_mesh_setup = {
55 .path_sel_proto = IEEE80211_PATH_PROTOCOL_HWMP,
56 .path_metric = IEEE80211_PATH_METRIC_AIRTIME,
57 .ie = NULL,
58 .ie_len = 0,
59 .is_secure = false,
60};
61
62int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
63 struct net_device *dev,
64 const struct mesh_setup *setup,
65 const struct mesh_config *conf)
66{
67 struct wireless_dev *wdev = dev->ieee80211_ptr;
68 int err;
69
70 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != IEEE80211_MAX_MESH_ID_LEN);
71
72 ASSERT_WDEV_LOCK(wdev);
73
74 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
75 return -EOPNOTSUPP;
76
77 if (!(rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
78 setup->is_secure)
79 return -EOPNOTSUPP;
80
81 if (wdev->mesh_id_len)
82 return -EALREADY;
83
84 if (!setup->mesh_id_len)
85 return -EINVAL;
86
87 if (!rdev->ops->join_mesh)
88 return -EOPNOTSUPP;
89
90 err = rdev->ops->join_mesh(&rdev->wiphy, dev, conf, setup);
91 if (!err) {
92 memcpy(wdev->ssid, setup->mesh_id, setup->mesh_id_len);
93 wdev->mesh_id_len = setup->mesh_id_len;
94 }
95
96 return err;
97}
98
99int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
100 struct net_device *dev,
101 const struct mesh_setup *setup,
102 const struct mesh_config *conf)
103{
104 struct wireless_dev *wdev = dev->ieee80211_ptr;
105 int err;
106
107 wdev_lock(wdev);
108 err = __cfg80211_join_mesh(rdev, dev, setup, conf);
109 wdev_unlock(wdev);
110
111 return err;
112}
113
114void cfg80211_notify_new_peer_candidate(struct net_device *dev,
115 const u8 *macaddr, const u8* ie, u8 ie_len, gfp_t gfp)
116{
117 struct wireless_dev *wdev = dev->ieee80211_ptr;
118
119 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
120 return;
121
122 nl80211_send_new_peer_candidate(wiphy_to_dev(wdev->wiphy), dev,
123 macaddr, ie, ie_len, gfp);
124}
125EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
126
127static int __cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
128 struct net_device *dev)
129{
130 struct wireless_dev *wdev = dev->ieee80211_ptr;
131 int err;
132
133 ASSERT_WDEV_LOCK(wdev);
134
135 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
136 return -EOPNOTSUPP;
137
138 if (!rdev->ops->leave_mesh)
139 return -EOPNOTSUPP;
140
141 if (!wdev->mesh_id_len)
142 return -ENOTCONN;
143
144 err = rdev->ops->leave_mesh(&rdev->wiphy, dev);
145 if (!err)
146 wdev->mesh_id_len = 0;
147 return err;
148}
149
150int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
151 struct net_device *dev)
152{
153 struct wireless_dev *wdev = dev->ieee80211_ptr;
154 int err;
155
156 wdev_lock(wdev);
157 err = __cfg80211_leave_mesh(rdev, dev);
158 wdev_unlock(wdev);
159
160 return err;
161}
diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c
index d1a3fb99fdf2..493b939970cd 100644
--- a/net/wireless/mlme.c
+++ b/net/wireless/mlme.c
@@ -149,7 +149,7 @@ void __cfg80211_send_deauth(struct net_device *dev,
149 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; 149 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
150 const u8 *bssid = mgmt->bssid; 150 const u8 *bssid = mgmt->bssid;
151 int i; 151 int i;
152 bool found = false; 152 bool found = false, was_current = false;
153 153
154 ASSERT_WDEV_LOCK(wdev); 154 ASSERT_WDEV_LOCK(wdev);
155 155
@@ -159,6 +159,7 @@ void __cfg80211_send_deauth(struct net_device *dev,
159 cfg80211_put_bss(&wdev->current_bss->pub); 159 cfg80211_put_bss(&wdev->current_bss->pub);
160 wdev->current_bss = NULL; 160 wdev->current_bss = NULL;
161 found = true; 161 found = true;
162 was_current = true;
162 } else for (i = 0; i < MAX_AUTH_BSSES; i++) { 163 } else for (i = 0; i < MAX_AUTH_BSSES; i++) {
163 if (wdev->auth_bsses[i] && 164 if (wdev->auth_bsses[i] &&
164 memcmp(wdev->auth_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) { 165 memcmp(wdev->auth_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) {
@@ -183,7 +184,7 @@ void __cfg80211_send_deauth(struct net_device *dev,
183 184
184 nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL); 185 nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL);
185 186
186 if (wdev->sme_state == CFG80211_SME_CONNECTED) { 187 if (wdev->sme_state == CFG80211_SME_CONNECTED && was_current) {
187 u16 reason_code; 188 u16 reason_code;
188 bool from_ap; 189 bool from_ap;
189 190
@@ -262,6 +263,28 @@ void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len)
262} 263}
263EXPORT_SYMBOL(cfg80211_send_disassoc); 264EXPORT_SYMBOL(cfg80211_send_disassoc);
264 265
266void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf,
267 size_t len)
268{
269 struct wireless_dev *wdev = dev->ieee80211_ptr;
270 struct wiphy *wiphy = wdev->wiphy;
271 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
272
273 nl80211_send_unprot_deauth(rdev, dev, buf, len, GFP_ATOMIC);
274}
275EXPORT_SYMBOL(cfg80211_send_unprot_deauth);
276
277void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf,
278 size_t len)
279{
280 struct wireless_dev *wdev = dev->ieee80211_ptr;
281 struct wiphy *wiphy = wdev->wiphy;
282 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
283
284 nl80211_send_unprot_disassoc(rdev, dev, buf, len, GFP_ATOMIC);
285}
286EXPORT_SYMBOL(cfg80211_send_unprot_disassoc);
287
265static void __cfg80211_auth_remove(struct wireless_dev *wdev, const u8 *addr) 288static void __cfg80211_auth_remove(struct wireless_dev *wdev, const u8 *addr)
266{ 289{
267 int i; 290 int i;
@@ -747,31 +770,62 @@ void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
747} 770}
748EXPORT_SYMBOL(cfg80211_new_sta); 771EXPORT_SYMBOL(cfg80211_new_sta);
749 772
750struct cfg80211_action_registration { 773void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
774{
775 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
776 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
777
778 nl80211_send_sta_del_event(rdev, dev, mac_addr, gfp);
779}
780EXPORT_SYMBOL(cfg80211_del_sta);
781
782struct cfg80211_mgmt_registration {
751 struct list_head list; 783 struct list_head list;
752 784
753 u32 nlpid; 785 u32 nlpid;
754 786
755 int match_len; 787 int match_len;
756 788
789 __le16 frame_type;
790
757 u8 match[]; 791 u8 match[];
758}; 792};
759 793
760int cfg80211_mlme_register_action(struct wireless_dev *wdev, u32 snd_pid, 794int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_pid,
761 const u8 *match_data, int match_len) 795 u16 frame_type, const u8 *match_data,
796 int match_len)
762{ 797{
763 struct cfg80211_action_registration *reg, *nreg; 798 struct wiphy *wiphy = wdev->wiphy;
799 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
800 struct cfg80211_mgmt_registration *reg, *nreg;
764 int err = 0; 801 int err = 0;
802 u16 mgmt_type;
803
804 if (!wdev->wiphy->mgmt_stypes)
805 return -EOPNOTSUPP;
806
807 if ((frame_type & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT)
808 return -EINVAL;
809
810 if (frame_type & ~(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE))
811 return -EINVAL;
812
813 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
814 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].rx & BIT(mgmt_type)))
815 return -EINVAL;
765 816
766 nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL); 817 nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL);
767 if (!nreg) 818 if (!nreg)
768 return -ENOMEM; 819 return -ENOMEM;
769 820
770 spin_lock_bh(&wdev->action_registrations_lock); 821 spin_lock_bh(&wdev->mgmt_registrations_lock);
771 822
772 list_for_each_entry(reg, &wdev->action_registrations, list) { 823 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
773 int mlen = min(match_len, reg->match_len); 824 int mlen = min(match_len, reg->match_len);
774 825
826 if (frame_type != le16_to_cpu(reg->frame_type))
827 continue;
828
775 if (memcmp(reg->match, match_data, mlen) == 0) { 829 if (memcmp(reg->match, match_data, mlen) == 0) {
776 err = -EALREADY; 830 err = -EALREADY;
777 break; 831 break;
@@ -786,140 +840,223 @@ int cfg80211_mlme_register_action(struct wireless_dev *wdev, u32 snd_pid,
786 memcpy(nreg->match, match_data, match_len); 840 memcpy(nreg->match, match_data, match_len);
787 nreg->match_len = match_len; 841 nreg->match_len = match_len;
788 nreg->nlpid = snd_pid; 842 nreg->nlpid = snd_pid;
789 list_add(&nreg->list, &wdev->action_registrations); 843 nreg->frame_type = cpu_to_le16(frame_type);
844 list_add(&nreg->list, &wdev->mgmt_registrations);
845
846 if (rdev->ops->mgmt_frame_register)
847 rdev->ops->mgmt_frame_register(wiphy, wdev->netdev,
848 frame_type, true);
790 849
791 out: 850 out:
792 spin_unlock_bh(&wdev->action_registrations_lock); 851 spin_unlock_bh(&wdev->mgmt_registrations_lock);
852
793 return err; 853 return err;
794} 854}
795 855
796void cfg80211_mlme_unregister_actions(struct wireless_dev *wdev, u32 nlpid) 856void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlpid)
797{ 857{
798 struct cfg80211_action_registration *reg, *tmp; 858 struct wiphy *wiphy = wdev->wiphy;
859 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
860 struct cfg80211_mgmt_registration *reg, *tmp;
799 861
800 spin_lock_bh(&wdev->action_registrations_lock); 862 spin_lock_bh(&wdev->mgmt_registrations_lock);
801 863
802 list_for_each_entry_safe(reg, tmp, &wdev->action_registrations, list) { 864 list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) {
803 if (reg->nlpid == nlpid) { 865 if (reg->nlpid != nlpid)
804 list_del(&reg->list); 866 continue;
805 kfree(reg); 867
868 if (rdev->ops->mgmt_frame_register) {
869 u16 frame_type = le16_to_cpu(reg->frame_type);
870
871 rdev->ops->mgmt_frame_register(wiphy, wdev->netdev,
872 frame_type, false);
806 } 873 }
874
875 list_del(&reg->list);
876 kfree(reg);
807 } 877 }
808 878
809 spin_unlock_bh(&wdev->action_registrations_lock); 879 spin_unlock_bh(&wdev->mgmt_registrations_lock);
810} 880}
811 881
812void cfg80211_mlme_purge_actions(struct wireless_dev *wdev) 882void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev)
813{ 883{
814 struct cfg80211_action_registration *reg, *tmp; 884 struct cfg80211_mgmt_registration *reg, *tmp;
815 885
816 spin_lock_bh(&wdev->action_registrations_lock); 886 spin_lock_bh(&wdev->mgmt_registrations_lock);
817 887
818 list_for_each_entry_safe(reg, tmp, &wdev->action_registrations, list) { 888 list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) {
819 list_del(&reg->list); 889 list_del(&reg->list);
820 kfree(reg); 890 kfree(reg);
821 } 891 }
822 892
823 spin_unlock_bh(&wdev->action_registrations_lock); 893 spin_unlock_bh(&wdev->mgmt_registrations_lock);
824} 894}
825 895
826int cfg80211_mlme_action(struct cfg80211_registered_device *rdev, 896int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
827 struct net_device *dev, 897 struct net_device *dev,
828 struct ieee80211_channel *chan, 898 struct ieee80211_channel *chan, bool offchan,
829 enum nl80211_channel_type channel_type, 899 enum nl80211_channel_type channel_type,
830 bool channel_type_valid, 900 bool channel_type_valid, unsigned int wait,
831 const u8 *buf, size_t len, u64 *cookie) 901 const u8 *buf, size_t len, u64 *cookie)
832{ 902{
833 struct wireless_dev *wdev = dev->ieee80211_ptr; 903 struct wireless_dev *wdev = dev->ieee80211_ptr;
834 const struct ieee80211_mgmt *mgmt; 904 const struct ieee80211_mgmt *mgmt;
905 u16 stype;
906
907 if (!wdev->wiphy->mgmt_stypes)
908 return -EOPNOTSUPP;
835 909
836 if (rdev->ops->action == NULL) 910 if (!rdev->ops->mgmt_tx)
837 return -EOPNOTSUPP; 911 return -EOPNOTSUPP;
912
838 if (len < 24 + 1) 913 if (len < 24 + 1)
839 return -EINVAL; 914 return -EINVAL;
840 915
841 mgmt = (const struct ieee80211_mgmt *) buf; 916 mgmt = (const struct ieee80211_mgmt *) buf;
842 if (!ieee80211_is_action(mgmt->frame_control)) 917
918 if (!ieee80211_is_mgmt(mgmt->frame_control))
843 return -EINVAL; 919 return -EINVAL;
844 if (mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) { 920
845 /* Verify that we are associated with the destination AP */ 921 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
922 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].tx & BIT(stype >> 4)))
923 return -EINVAL;
924
925 if (ieee80211_is_action(mgmt->frame_control) &&
926 mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) {
927 int err = 0;
928
846 wdev_lock(wdev); 929 wdev_lock(wdev);
847 930
848 if (!wdev->current_bss || 931 switch (wdev->iftype) {
849 memcmp(wdev->current_bss->pub.bssid, mgmt->bssid, 932 case NL80211_IFTYPE_ADHOC:
850 ETH_ALEN) != 0 || 933 case NL80211_IFTYPE_STATION:
851 (wdev->iftype == NL80211_IFTYPE_STATION && 934 case NL80211_IFTYPE_P2P_CLIENT:
852 memcmp(wdev->current_bss->pub.bssid, mgmt->da, 935 if (!wdev->current_bss) {
853 ETH_ALEN) != 0)) { 936 err = -ENOTCONN;
854 wdev_unlock(wdev); 937 break;
855 return -ENOTCONN; 938 }
856 } 939
940 if (memcmp(wdev->current_bss->pub.bssid,
941 mgmt->bssid, ETH_ALEN)) {
942 err = -ENOTCONN;
943 break;
944 }
857 945
946 /*
947 * check for IBSS DA must be done by driver as
948 * cfg80211 doesn't track the stations
949 */
950 if (wdev->iftype == NL80211_IFTYPE_ADHOC)
951 break;
952
953 /* for station, check that DA is the AP */
954 if (memcmp(wdev->current_bss->pub.bssid,
955 mgmt->da, ETH_ALEN)) {
956 err = -ENOTCONN;
957 break;
958 }
959 break;
960 case NL80211_IFTYPE_AP:
961 case NL80211_IFTYPE_P2P_GO:
962 case NL80211_IFTYPE_AP_VLAN:
963 if (memcmp(mgmt->bssid, dev->dev_addr, ETH_ALEN))
964 err = -EINVAL;
965 break;
966 case NL80211_IFTYPE_MESH_POINT:
967 if (memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN)) {
968 err = -EINVAL;
969 break;
970 }
971 /*
972 * check for mesh DA must be done by driver as
973 * cfg80211 doesn't track the stations
974 */
975 break;
976 default:
977 err = -EOPNOTSUPP;
978 break;
979 }
858 wdev_unlock(wdev); 980 wdev_unlock(wdev);
981
982 if (err)
983 return err;
859 } 984 }
860 985
861 if (memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0) 986 if (memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0)
862 return -EINVAL; 987 return -EINVAL;
863 988
864 /* Transmit the Action frame as requested by user space */ 989 /* Transmit the Action frame as requested by user space */
865 return rdev->ops->action(&rdev->wiphy, dev, chan, channel_type, 990 return rdev->ops->mgmt_tx(&rdev->wiphy, dev, chan, offchan,
866 channel_type_valid, buf, len, cookie); 991 channel_type, channel_type_valid,
992 wait, buf, len, cookie);
867} 993}
868 994
869bool cfg80211_rx_action(struct net_device *dev, int freq, const u8 *buf, 995bool cfg80211_rx_mgmt(struct net_device *dev, int freq, const u8 *buf,
870 size_t len, gfp_t gfp) 996 size_t len, gfp_t gfp)
871{ 997{
872 struct wireless_dev *wdev = dev->ieee80211_ptr; 998 struct wireless_dev *wdev = dev->ieee80211_ptr;
873 struct wiphy *wiphy = wdev->wiphy; 999 struct wiphy *wiphy = wdev->wiphy;
874 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 1000 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
875 struct cfg80211_action_registration *reg; 1001 struct cfg80211_mgmt_registration *reg;
876 const u8 *action_data; 1002 const struct ieee80211_txrx_stypes *stypes =
877 int action_data_len; 1003 &wiphy->mgmt_stypes[wdev->iftype];
1004 struct ieee80211_mgmt *mgmt = (void *)buf;
1005 const u8 *data;
1006 int data_len;
878 bool result = false; 1007 bool result = false;
1008 __le16 ftype = mgmt->frame_control &
1009 cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE);
1010 u16 stype;
1011
1012 stype = (le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE) >> 4;
879 1013
880 /* frame length - min size excluding category */ 1014 if (!(stypes->rx & BIT(stype)))
881 action_data_len = len - (IEEE80211_MIN_ACTION_SIZE - 1); 1015 return false;
882 1016
883 /* action data starts with category */ 1017 data = buf + ieee80211_hdrlen(mgmt->frame_control);
884 action_data = buf + IEEE80211_MIN_ACTION_SIZE - 1; 1018 data_len = len - ieee80211_hdrlen(mgmt->frame_control);
885 1019
886 spin_lock_bh(&wdev->action_registrations_lock); 1020 spin_lock_bh(&wdev->mgmt_registrations_lock);
887 1021
888 list_for_each_entry(reg, &wdev->action_registrations, list) { 1022 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
889 if (reg->match_len > action_data_len) 1023 if (reg->frame_type != ftype)
890 continue; 1024 continue;
891 1025
892 if (memcmp(reg->match, action_data, reg->match_len)) 1026 if (reg->match_len > data_len)
1027 continue;
1028
1029 if (memcmp(reg->match, data, reg->match_len))
893 continue; 1030 continue;
894 1031
895 /* found match! */ 1032 /* found match! */
896 1033
897 /* Indicate the received Action frame to user space */ 1034 /* Indicate the received Action frame to user space */
898 if (nl80211_send_action(rdev, dev, reg->nlpid, freq, 1035 if (nl80211_send_mgmt(rdev, dev, reg->nlpid, freq,
899 buf, len, gfp)) 1036 buf, len, gfp))
900 continue; 1037 continue;
901 1038
902 result = true; 1039 result = true;
903 break; 1040 break;
904 } 1041 }
905 1042
906 spin_unlock_bh(&wdev->action_registrations_lock); 1043 spin_unlock_bh(&wdev->mgmt_registrations_lock);
907 1044
908 return result; 1045 return result;
909} 1046}
910EXPORT_SYMBOL(cfg80211_rx_action); 1047EXPORT_SYMBOL(cfg80211_rx_mgmt);
911 1048
912void cfg80211_action_tx_status(struct net_device *dev, u64 cookie, 1049void cfg80211_mgmt_tx_status(struct net_device *dev, u64 cookie,
913 const u8 *buf, size_t len, bool ack, gfp_t gfp) 1050 const u8 *buf, size_t len, bool ack, gfp_t gfp)
914{ 1051{
915 struct wireless_dev *wdev = dev->ieee80211_ptr; 1052 struct wireless_dev *wdev = dev->ieee80211_ptr;
916 struct wiphy *wiphy = wdev->wiphy; 1053 struct wiphy *wiphy = wdev->wiphy;
917 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 1054 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
918 1055
919 /* Indicate TX status of the Action frame to user space */ 1056 /* Indicate TX status of the Action frame to user space */
920 nl80211_send_action_tx_status(rdev, dev, cookie, buf, len, ack, gfp); 1057 nl80211_send_mgmt_tx_status(rdev, dev, cookie, buf, len, ack, gfp);
921} 1058}
922EXPORT_SYMBOL(cfg80211_action_tx_status); 1059EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
923 1060
924void cfg80211_cqm_rssi_notify(struct net_device *dev, 1061void cfg80211_cqm_rssi_notify(struct net_device *dev,
925 enum nl80211_cqm_rssi_threshold_event rssi_event, 1062 enum nl80211_cqm_rssi_threshold_event rssi_event,
@@ -933,3 +1070,15 @@ void cfg80211_cqm_rssi_notify(struct net_device *dev,
933 nl80211_send_cqm_rssi_notify(rdev, dev, rssi_event, gfp); 1070 nl80211_send_cqm_rssi_notify(rdev, dev, rssi_event, gfp);
934} 1071}
935EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); 1072EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
1073
1074void cfg80211_cqm_pktloss_notify(struct net_device *dev,
1075 const u8 *peer, u32 num_packets, gfp_t gfp)
1076{
1077 struct wireless_dev *wdev = dev->ieee80211_ptr;
1078 struct wiphy *wiphy = wdev->wiphy;
1079 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
1080
1081 /* Indicate roaming trigger event to user space */
1082 nl80211_send_cqm_pktloss_notify(rdev, dev, peer, num_packets, gfp);
1083}
1084EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 37902a54e9c1..cea338150d05 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -23,6 +23,11 @@
23#include "nl80211.h" 23#include "nl80211.h"
24#include "reg.h" 24#include "reg.h"
25 25
26static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
27 struct genl_info *info);
28static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
29 struct genl_info *info);
30
26/* the netlink family */ 31/* the netlink family */
27static struct genl_family nl80211_fam = { 32static struct genl_family nl80211_fam = {
28 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ 33 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
@@ -31,6 +36,8 @@ static struct genl_family nl80211_fam = {
31 .version = 1, /* no particular meaning now */ 36 .version = 1, /* no particular meaning now */
32 .maxattr = NL80211_ATTR_MAX, 37 .maxattr = NL80211_ATTR_MAX,
33 .netnsok = true, 38 .netnsok = true,
39 .pre_doit = nl80211_pre_doit,
40 .post_doit = nl80211_post_doit,
34}; 41};
35 42
36/* internal helper: get rdev and dev */ 43/* internal helper: get rdev and dev */
@@ -86,6 +93,7 @@ static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
86 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, 93 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
87 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, 94 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
88 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, 95 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 },
96 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
89 97
90 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, 98 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
91 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, 99 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
@@ -113,8 +121,10 @@ static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
113 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, 121 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
114 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, 122 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
115 .len = NL80211_MAX_SUPP_RATES }, 123 .len = NL80211_MAX_SUPP_RATES },
124 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
116 125
117 [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, 126 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
127 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
118 128
119 [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, 129 [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY,
120 .len = NL80211_HT_CAPABILITY_LEN }, 130 .len = NL80211_HT_CAPABILITY_LEN },
@@ -136,6 +146,8 @@ static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
136 .len = sizeof(struct nl80211_sta_flag_update), 146 .len = sizeof(struct nl80211_sta_flag_update),
137 }, 147 },
138 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, 148 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
149 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
150 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
139 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, 151 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
140 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, 152 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
141 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, 153 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
@@ -153,12 +165,20 @@ static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
153 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, 165 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
154 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, 166 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
155 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, 167 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
156
157 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, 168 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
158 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, 169 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
170 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
171 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
172 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
173 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
174 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
175 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
176 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
177 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
178 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
159}; 179};
160 180
161/* policy for the attributes */ 181/* policy for the key attributes */
162static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { 182static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
163 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, 183 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
164 [NL80211_KEY_IDX] = { .type = NLA_U8 }, 184 [NL80211_KEY_IDX] = { .type = NLA_U8 },
@@ -166,6 +186,24 @@ static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
166 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, 186 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 },
167 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, 187 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
168 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, 188 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
189 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
190 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
191};
192
193/* policy for the key default flags */
194static const struct nla_policy
195nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
196 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
197 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
198};
199
200/* policy for WoWLAN attributes */
201static const struct nla_policy
202nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
203 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
204 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
205 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
206 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
169}; 207};
170 208
171/* ifidx get helper */ 209/* ifidx get helper */
@@ -188,6 +226,47 @@ static int nl80211_get_ifidx(struct netlink_callback *cb)
188 return res; 226 return res;
189} 227}
190 228
229static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
230 struct netlink_callback *cb,
231 struct cfg80211_registered_device **rdev,
232 struct net_device **dev)
233{
234 int ifidx = cb->args[0];
235 int err;
236
237 if (!ifidx)
238 ifidx = nl80211_get_ifidx(cb);
239 if (ifidx < 0)
240 return ifidx;
241
242 cb->args[0] = ifidx;
243
244 rtnl_lock();
245
246 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
247 if (!*dev) {
248 err = -ENODEV;
249 goto out_rtnl;
250 }
251
252 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
253 if (IS_ERR(*rdev)) {
254 err = PTR_ERR(*rdev);
255 goto out_rtnl;
256 }
257
258 return 0;
259 out_rtnl:
260 rtnl_unlock();
261 return err;
262}
263
264static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
265{
266 cfg80211_unlock_rdev(rdev);
267 rtnl_unlock();
268}
269
191/* IE validation */ 270/* IE validation */
192static bool is_valid_ie_attr(const struct nlattr *attr) 271static bool is_valid_ie_attr(const struct nlattr *attr)
193{ 272{
@@ -255,7 +334,9 @@ static int nl80211_msg_put_channel(struct sk_buff *msg,
255struct key_parse { 334struct key_parse {
256 struct key_params p; 335 struct key_params p;
257 int idx; 336 int idx;
337 int type;
258 bool def, defmgmt; 338 bool def, defmgmt;
339 bool def_uni, def_multi;
259}; 340};
260 341
261static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) 342static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
@@ -269,6 +350,13 @@ static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
269 k->def = !!tb[NL80211_KEY_DEFAULT]; 350 k->def = !!tb[NL80211_KEY_DEFAULT];
270 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; 351 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
271 352
353 if (k->def) {
354 k->def_uni = true;
355 k->def_multi = true;
356 }
357 if (k->defmgmt)
358 k->def_multi = true;
359
272 if (tb[NL80211_KEY_IDX]) 360 if (tb[NL80211_KEY_IDX])
273 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); 361 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
274 362
@@ -285,6 +373,25 @@ static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
285 if (tb[NL80211_KEY_CIPHER]) 373 if (tb[NL80211_KEY_CIPHER])
286 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); 374 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
287 375
376 if (tb[NL80211_KEY_TYPE]) {
377 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
378 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
379 return -EINVAL;
380 }
381
382 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
383 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
384 int err = nla_parse_nested(kdt,
385 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
386 tb[NL80211_KEY_DEFAULT_TYPES],
387 nl80211_key_default_policy);
388 if (err)
389 return err;
390
391 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
392 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
393 }
394
288 return 0; 395 return 0;
289} 396}
290 397
@@ -309,6 +416,32 @@ static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
309 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; 416 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
310 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; 417 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
311 418
419 if (k->def) {
420 k->def_uni = true;
421 k->def_multi = true;
422 }
423 if (k->defmgmt)
424 k->def_multi = true;
425
426 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
427 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
428 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
429 return -EINVAL;
430 }
431
432 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
433 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
434 int err = nla_parse_nested(
435 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
436 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
437 nl80211_key_default_policy);
438 if (err)
439 return err;
440
441 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
442 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
443 }
444
312 return 0; 445 return 0;
313} 446}
314 447
@@ -318,6 +451,7 @@ static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
318 451
319 memset(k, 0, sizeof(*k)); 452 memset(k, 0, sizeof(*k));
320 k->idx = -1; 453 k->idx = -1;
454 k->type = -1;
321 455
322 if (info->attrs[NL80211_ATTR_KEY]) 456 if (info->attrs[NL80211_ATTR_KEY])
323 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); 457 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
@@ -330,6 +464,11 @@ static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
330 if (k->def && k->defmgmt) 464 if (k->def && k->defmgmt)
331 return -EINVAL; 465 return -EINVAL;
332 466
467 if (k->defmgmt) {
468 if (k->def_uni || !k->def_multi)
469 return -EINVAL;
470 }
471
333 if (k->idx != -1) { 472 if (k->idx != -1) {
334 if (k->defmgmt) { 473 if (k->defmgmt) {
335 if (k->idx < 4 || k->idx > 5) 474 if (k->idx < 4 || k->idx > 5)
@@ -379,10 +518,12 @@ nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
379 goto error; 518 goto error;
380 def = 1; 519 def = 1;
381 result->def = parse.idx; 520 result->def = parse.idx;
521 if (!parse.def_uni || !parse.def_multi)
522 goto error;
382 } else if (parse.defmgmt) 523 } else if (parse.defmgmt)
383 goto error; 524 goto error;
384 err = cfg80211_validate_key_settings(rdev, &parse.p, 525 err = cfg80211_validate_key_settings(rdev, &parse.p,
385 parse.idx, NULL); 526 parse.idx, false, NULL);
386 if (err) 527 if (err)
387 goto error; 528 goto error;
388 result->params[parse.idx].cipher = parse.p.cipher; 529 result->params[parse.idx].cipher = parse.p.cipher;
@@ -401,18 +542,18 @@ static int nl80211_key_allowed(struct wireless_dev *wdev)
401{ 542{
402 ASSERT_WDEV_LOCK(wdev); 543 ASSERT_WDEV_LOCK(wdev);
403 544
404 if (!netif_running(wdev->netdev))
405 return -ENETDOWN;
406
407 switch (wdev->iftype) { 545 switch (wdev->iftype) {
408 case NL80211_IFTYPE_AP: 546 case NL80211_IFTYPE_AP:
409 case NL80211_IFTYPE_AP_VLAN: 547 case NL80211_IFTYPE_AP_VLAN:
548 case NL80211_IFTYPE_P2P_GO:
549 case NL80211_IFTYPE_MESH_POINT:
410 break; 550 break;
411 case NL80211_IFTYPE_ADHOC: 551 case NL80211_IFTYPE_ADHOC:
412 if (!wdev->current_bss) 552 if (!wdev->current_bss)
413 return -ENOLINK; 553 return -ENOLINK;
414 break; 554 break;
415 case NL80211_IFTYPE_STATION: 555 case NL80211_IFTYPE_STATION:
556 case NL80211_IFTYPE_P2P_CLIENT:
416 if (wdev->sme_state != CFG80211_SME_CONNECTED) 557 if (wdev->sme_state != CFG80211_SME_CONNECTED)
417 return -ENOLINK; 558 return -ENOLINK;
418 break; 559 break;
@@ -423,6 +564,88 @@ static int nl80211_key_allowed(struct wireless_dev *wdev)
423 return 0; 564 return 0;
424} 565}
425 566
567static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
568{
569 struct nlattr *nl_modes = nla_nest_start(msg, attr);
570 int i;
571
572 if (!nl_modes)
573 goto nla_put_failure;
574
575 i = 0;
576 while (ifmodes) {
577 if (ifmodes & 1)
578 NLA_PUT_FLAG(msg, i);
579 ifmodes >>= 1;
580 i++;
581 }
582
583 nla_nest_end(msg, nl_modes);
584 return 0;
585
586nla_put_failure:
587 return -ENOBUFS;
588}
589
590static int nl80211_put_iface_combinations(struct wiphy *wiphy,
591 struct sk_buff *msg)
592{
593 struct nlattr *nl_combis;
594 int i, j;
595
596 nl_combis = nla_nest_start(msg,
597 NL80211_ATTR_INTERFACE_COMBINATIONS);
598 if (!nl_combis)
599 goto nla_put_failure;
600
601 for (i = 0; i < wiphy->n_iface_combinations; i++) {
602 const struct ieee80211_iface_combination *c;
603 struct nlattr *nl_combi, *nl_limits;
604
605 c = &wiphy->iface_combinations[i];
606
607 nl_combi = nla_nest_start(msg, i + 1);
608 if (!nl_combi)
609 goto nla_put_failure;
610
611 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
612 if (!nl_limits)
613 goto nla_put_failure;
614
615 for (j = 0; j < c->n_limits; j++) {
616 struct nlattr *nl_limit;
617
618 nl_limit = nla_nest_start(msg, j + 1);
619 if (!nl_limit)
620 goto nla_put_failure;
621 NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX,
622 c->limits[j].max);
623 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
624 c->limits[j].types))
625 goto nla_put_failure;
626 nla_nest_end(msg, nl_limit);
627 }
628
629 nla_nest_end(msg, nl_limits);
630
631 if (c->beacon_int_infra_match)
632 NLA_PUT_FLAG(msg,
633 NL80211_IFACE_COMB_STA_AP_BI_MATCH);
634 NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
635 c->num_different_channels);
636 NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM,
637 c->max_interfaces);
638
639 nla_nest_end(msg, nl_combi);
640 }
641
642 nla_nest_end(msg, nl_combis);
643
644 return 0;
645nla_put_failure:
646 return -ENOBUFS;
647}
648
426static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, 649static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
427 struct cfg80211_registered_device *dev) 650 struct cfg80211_registered_device *dev)
428{ 651{
@@ -430,13 +653,13 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
430 struct nlattr *nl_bands, *nl_band; 653 struct nlattr *nl_bands, *nl_band;
431 struct nlattr *nl_freqs, *nl_freq; 654 struct nlattr *nl_freqs, *nl_freq;
432 struct nlattr *nl_rates, *nl_rate; 655 struct nlattr *nl_rates, *nl_rate;
433 struct nlattr *nl_modes;
434 struct nlattr *nl_cmds; 656 struct nlattr *nl_cmds;
435 enum ieee80211_band band; 657 enum ieee80211_band band;
436 struct ieee80211_channel *chan; 658 struct ieee80211_channel *chan;
437 struct ieee80211_rate *rate; 659 struct ieee80211_rate *rate;
438 int i; 660 int i;
439 u16 ifmodes = dev->wiphy.interface_modes; 661 const struct ieee80211_txrx_stypes *mgmt_stypes =
662 dev->wiphy.mgmt_stypes;
440 663
441 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); 664 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
442 if (!hdr) 665 if (!hdr)
@@ -458,12 +681,16 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
458 dev->wiphy.rts_threshold); 681 dev->wiphy.rts_threshold);
459 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, 682 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
460 dev->wiphy.coverage_class); 683 dev->wiphy.coverage_class);
461
462 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, 684 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
463 dev->wiphy.max_scan_ssids); 685 dev->wiphy.max_scan_ssids);
464 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, 686 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
465 dev->wiphy.max_scan_ie_len); 687 dev->wiphy.max_scan_ie_len);
466 688
689 if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)
690 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN);
691 if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH)
692 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH);
693
467 NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, 694 NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
468 sizeof(u32) * dev->wiphy.n_cipher_suites, 695 sizeof(u32) * dev->wiphy.n_cipher_suites,
469 dev->wiphy.cipher_suites); 696 dev->wiphy.cipher_suites);
@@ -471,19 +698,28 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
471 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, 698 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
472 dev->wiphy.max_num_pmkids); 699 dev->wiphy.max_num_pmkids);
473 700
474 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); 701 if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL)
475 if (!nl_modes) 702 NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE);
476 goto nla_put_failure; 703
477 704 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
478 i = 0; 705 dev->wiphy.available_antennas_tx);
479 while (ifmodes) { 706 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
480 if (ifmodes & 1) 707 dev->wiphy.available_antennas_rx);
481 NLA_PUT_FLAG(msg, i); 708
482 ifmodes >>= 1; 709 if ((dev->wiphy.available_antennas_tx ||
483 i++; 710 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
711 u32 tx_ant = 0, rx_ant = 0;
712 int res;
713 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
714 if (!res) {
715 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant);
716 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant);
717 }
484 } 718 }
485 719
486 nla_nest_end(msg, nl_modes); 720 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
721 dev->wiphy.interface_modes))
722 goto nla_put_failure;
487 723
488 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); 724 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
489 if (!nl_bands) 725 if (!nl_bands)
@@ -575,24 +811,29 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
575 CMD(add_beacon, NEW_BEACON); 811 CMD(add_beacon, NEW_BEACON);
576 CMD(add_station, NEW_STATION); 812 CMD(add_station, NEW_STATION);
577 CMD(add_mpath, NEW_MPATH); 813 CMD(add_mpath, NEW_MPATH);
578 CMD(set_mesh_params, SET_MESH_PARAMS); 814 CMD(update_mesh_config, SET_MESH_CONFIG);
579 CMD(change_bss, SET_BSS); 815 CMD(change_bss, SET_BSS);
580 CMD(auth, AUTHENTICATE); 816 CMD(auth, AUTHENTICATE);
581 CMD(assoc, ASSOCIATE); 817 CMD(assoc, ASSOCIATE);
582 CMD(deauth, DEAUTHENTICATE); 818 CMD(deauth, DEAUTHENTICATE);
583 CMD(disassoc, DISASSOCIATE); 819 CMD(disassoc, DISASSOCIATE);
584 CMD(join_ibss, JOIN_IBSS); 820 CMD(join_ibss, JOIN_IBSS);
821 CMD(join_mesh, JOIN_MESH);
585 CMD(set_pmksa, SET_PMKSA); 822 CMD(set_pmksa, SET_PMKSA);
586 CMD(del_pmksa, DEL_PMKSA); 823 CMD(del_pmksa, DEL_PMKSA);
587 CMD(flush_pmksa, FLUSH_PMKSA); 824 CMD(flush_pmksa, FLUSH_PMKSA);
588 CMD(remain_on_channel, REMAIN_ON_CHANNEL); 825 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
589 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); 826 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
590 CMD(action, ACTION); 827 CMD(mgmt_tx, FRAME);
828 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
591 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { 829 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
592 i++; 830 i++;
593 NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); 831 NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS);
594 } 832 }
595 CMD(set_channel, SET_CHANNEL); 833 CMD(set_channel, SET_CHANNEL);
834 CMD(set_wds_peer, SET_WDS_PEER);
835 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
836 CMD(sched_scan_start, START_SCHED_SCAN);
596 837
597#undef CMD 838#undef CMD
598 839
@@ -608,6 +849,99 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
608 849
609 nla_nest_end(msg, nl_cmds); 850 nla_nest_end(msg, nl_cmds);
610 851
852 if (dev->ops->remain_on_channel)
853 NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
854 dev->wiphy.max_remain_on_channel_duration);
855
856 /* for now at least assume all drivers have it */
857 if (dev->ops->mgmt_tx)
858 NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK);
859
860 if (mgmt_stypes) {
861 u16 stypes;
862 struct nlattr *nl_ftypes, *nl_ifs;
863 enum nl80211_iftype ift;
864
865 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
866 if (!nl_ifs)
867 goto nla_put_failure;
868
869 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
870 nl_ftypes = nla_nest_start(msg, ift);
871 if (!nl_ftypes)
872 goto nla_put_failure;
873 i = 0;
874 stypes = mgmt_stypes[ift].tx;
875 while (stypes) {
876 if (stypes & 1)
877 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
878 (i << 4) | IEEE80211_FTYPE_MGMT);
879 stypes >>= 1;
880 i++;
881 }
882 nla_nest_end(msg, nl_ftypes);
883 }
884
885 nla_nest_end(msg, nl_ifs);
886
887 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
888 if (!nl_ifs)
889 goto nla_put_failure;
890
891 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
892 nl_ftypes = nla_nest_start(msg, ift);
893 if (!nl_ftypes)
894 goto nla_put_failure;
895 i = 0;
896 stypes = mgmt_stypes[ift].rx;
897 while (stypes) {
898 if (stypes & 1)
899 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
900 (i << 4) | IEEE80211_FTYPE_MGMT);
901 stypes >>= 1;
902 i++;
903 }
904 nla_nest_end(msg, nl_ftypes);
905 }
906 nla_nest_end(msg, nl_ifs);
907 }
908
909 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
910 struct nlattr *nl_wowlan;
911
912 nl_wowlan = nla_nest_start(msg,
913 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
914 if (!nl_wowlan)
915 goto nla_put_failure;
916
917 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY)
918 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
919 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT)
920 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
921 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT)
922 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
923 if (dev->wiphy.wowlan.n_patterns) {
924 struct nl80211_wowlan_pattern_support pat = {
925 .max_patterns = dev->wiphy.wowlan.n_patterns,
926 .min_pattern_len =
927 dev->wiphy.wowlan.pattern_min_len,
928 .max_pattern_len =
929 dev->wiphy.wowlan.pattern_max_len,
930 };
931 NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
932 sizeof(pat), &pat);
933 }
934
935 nla_nest_end(msg, nl_wowlan);
936 }
937
938 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
939 dev->wiphy.software_iftypes))
940 goto nla_put_failure;
941
942 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
943 goto nla_put_failure;
944
611 return genlmsg_end(msg, hdr); 945 return genlmsg_end(msg, hdr);
612 946
613 nla_put_failure: 947 nla_put_failure:
@@ -644,28 +978,18 @@ static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
644static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) 978static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
645{ 979{
646 struct sk_buff *msg; 980 struct sk_buff *msg;
647 struct cfg80211_registered_device *dev; 981 struct cfg80211_registered_device *dev = info->user_ptr[0];
648
649 dev = cfg80211_get_dev_from_info(info);
650 if (IS_ERR(dev))
651 return PTR_ERR(dev);
652 982
653 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 983 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
654 if (!msg) 984 if (!msg)
655 goto out_err; 985 return -ENOMEM;
656
657 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0)
658 goto out_free;
659 986
660 cfg80211_unlock_rdev(dev); 987 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
988 nlmsg_free(msg);
989 return -ENOBUFS;
990 }
661 991
662 return genlmsg_reply(msg, info); 992 return genlmsg_reply(msg, info);
663
664 out_free:
665 nlmsg_free(msg);
666 out_err:
667 cfg80211_unlock_rdev(dev);
668 return -ENOBUFS;
669} 993}
670 994
671static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { 995static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
@@ -709,7 +1033,8 @@ static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
709 wdev->iftype == NL80211_IFTYPE_AP || 1033 wdev->iftype == NL80211_IFTYPE_AP ||
710 wdev->iftype == NL80211_IFTYPE_WDS || 1034 wdev->iftype == NL80211_IFTYPE_WDS ||
711 wdev->iftype == NL80211_IFTYPE_MESH_POINT || 1035 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
712 wdev->iftype == NL80211_IFTYPE_MONITOR; 1036 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1037 wdev->iftype == NL80211_IFTYPE_P2P_GO;
713} 1038}
714 1039
715static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, 1040static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
@@ -753,38 +1078,48 @@ static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
753 1078
754static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) 1079static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
755{ 1080{
756 struct cfg80211_registered_device *rdev; 1081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
757 struct net_device *netdev; 1082 struct net_device *netdev = info->user_ptr[1];
758 int result;
759 1083
760 rtnl_lock(); 1084 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
1085}
761 1086
762 result = get_rdev_dev_by_info_ifindex(info, &rdev, &netdev); 1087static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
763 if (result) 1088{
764 goto unlock; 1089 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1090 struct net_device *dev = info->user_ptr[1];
1091 struct wireless_dev *wdev = dev->ieee80211_ptr;
1092 const u8 *bssid;
765 1093
766 result = __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); 1094 if (!info->attrs[NL80211_ATTR_MAC])
1095 return -EINVAL;
767 1096
768 unlock: 1097 if (netif_running(dev))
769 rtnl_unlock(); 1098 return -EBUSY;
770 1099
771 return result; 1100 if (!rdev->ops->set_wds_peer)
1101 return -EOPNOTSUPP;
1102
1103 if (wdev->iftype != NL80211_IFTYPE_WDS)
1104 return -EOPNOTSUPP;
1105
1106 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
1107 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
772} 1108}
773 1109
1110
774static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) 1111static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
775{ 1112{
776 struct cfg80211_registered_device *rdev; 1113 struct cfg80211_registered_device *rdev;
777 struct net_device *netdev = NULL; 1114 struct net_device *netdev = NULL;
778 struct wireless_dev *wdev; 1115 struct wireless_dev *wdev;
779 int result, rem_txq_params = 0; 1116 int result = 0, rem_txq_params = 0;
780 struct nlattr *nl_txq_params; 1117 struct nlattr *nl_txq_params;
781 u32 changed; 1118 u32 changed;
782 u8 retry_short = 0, retry_long = 0; 1119 u8 retry_short = 0, retry_long = 0;
783 u32 frag_threshold = 0, rts_threshold = 0; 1120 u32 frag_threshold = 0, rts_threshold = 0;
784 u8 coverage_class = 0; 1121 u8 coverage_class = 0;
785 1122
786 rtnl_lock();
787
788 /* 1123 /*
789 * Try to find the wiphy and netdev. Normally this 1124 * Try to find the wiphy and netdev. Normally this
790 * function shouldn't need the netdev, but this is 1125 * function shouldn't need the netdev, but this is
@@ -811,8 +1146,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
811 rdev = __cfg80211_rdev_from_info(info); 1146 rdev = __cfg80211_rdev_from_info(info);
812 if (IS_ERR(rdev)) { 1147 if (IS_ERR(rdev)) {
813 mutex_unlock(&cfg80211_mutex); 1148 mutex_unlock(&cfg80211_mutex);
814 result = PTR_ERR(rdev); 1149 return PTR_ERR(rdev);
815 goto unlock;
816 } 1150 }
817 wdev = NULL; 1151 wdev = NULL;
818 netdev = NULL; 1152 netdev = NULL;
@@ -900,6 +1234,35 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
900 goto bad_res; 1234 goto bad_res;
901 } 1235 }
902 1236
1237 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1238 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1239 u32 tx_ant, rx_ant;
1240 if ((!rdev->wiphy.available_antennas_tx &&
1241 !rdev->wiphy.available_antennas_rx) ||
1242 !rdev->ops->set_antenna) {
1243 result = -EOPNOTSUPP;
1244 goto bad_res;
1245 }
1246
1247 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1248 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1249
1250 /* reject antenna configurations which don't match the
1251 * available antenna masks, except for the "all" mask */
1252 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1253 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
1254 result = -EINVAL;
1255 goto bad_res;
1256 }
1257
1258 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1259 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
1260
1261 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1262 if (result)
1263 goto bad_res;
1264 }
1265
903 changed = 0; 1266 changed = 0;
904 1267
905 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { 1268 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
@@ -994,8 +1357,6 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
994 mutex_unlock(&rdev->mtx); 1357 mutex_unlock(&rdev->mtx);
995 if (netdev) 1358 if (netdev)
996 dev_put(netdev); 1359 dev_put(netdev);
997 unlock:
998 rtnl_unlock();
999 return result; 1360 return result;
1000} 1361}
1001 1362
@@ -1075,33 +1436,20 @@ static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *
1075static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) 1436static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1076{ 1437{
1077 struct sk_buff *msg; 1438 struct sk_buff *msg;
1078 struct cfg80211_registered_device *dev; 1439 struct cfg80211_registered_device *dev = info->user_ptr[0];
1079 struct net_device *netdev; 1440 struct net_device *netdev = info->user_ptr[1];
1080 int err;
1081
1082 err = get_rdev_dev_by_info_ifindex(info, &dev, &netdev);
1083 if (err)
1084 return err;
1085 1441
1086 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 1442 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1087 if (!msg) 1443 if (!msg)
1088 goto out_err; 1444 return -ENOMEM;
1089 1445
1090 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, 1446 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
1091 dev, netdev) < 0) 1447 dev, netdev) < 0) {
1092 goto out_free; 1448 nlmsg_free(msg);
1093 1449 return -ENOBUFS;
1094 dev_put(netdev); 1450 }
1095 cfg80211_unlock_rdev(dev);
1096 1451
1097 return genlmsg_reply(msg, info); 1452 return genlmsg_reply(msg, info);
1098
1099 out_free:
1100 nlmsg_free(msg);
1101 out_err:
1102 dev_put(netdev);
1103 cfg80211_unlock_rdev(dev);
1104 return -ENOBUFS;
1105} 1453}
1106 1454
1107static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { 1455static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
@@ -1161,42 +1509,42 @@ static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
1161 1509
1162static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) 1510static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1163{ 1511{
1164 struct cfg80211_registered_device *rdev; 1512 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1165 struct vif_params params; 1513 struct vif_params params;
1166 int err; 1514 int err;
1167 enum nl80211_iftype otype, ntype; 1515 enum nl80211_iftype otype, ntype;
1168 struct net_device *dev; 1516 struct net_device *dev = info->user_ptr[1];
1169 u32 _flags, *flags = NULL; 1517 u32 _flags, *flags = NULL;
1170 bool change = false; 1518 bool change = false;
1171 1519
1172 memset(&params, 0, sizeof(params)); 1520 memset(&params, 0, sizeof(params));
1173 1521
1174 rtnl_lock();
1175
1176 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
1177 if (err)
1178 goto unlock_rtnl;
1179
1180 otype = ntype = dev->ieee80211_ptr->iftype; 1522 otype = ntype = dev->ieee80211_ptr->iftype;
1181 1523
1182 if (info->attrs[NL80211_ATTR_IFTYPE]) { 1524 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1183 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 1525 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1184 if (otype != ntype) 1526 if (otype != ntype)
1185 change = true; 1527 change = true;
1186 if (ntype > NL80211_IFTYPE_MAX) { 1528 if (ntype > NL80211_IFTYPE_MAX)
1187 err = -EINVAL; 1529 return -EINVAL;
1188 goto unlock;
1189 }
1190 } 1530 }
1191 1531
1192 if (info->attrs[NL80211_ATTR_MESH_ID]) { 1532 if (info->attrs[NL80211_ATTR_MESH_ID]) {
1193 if (ntype != NL80211_IFTYPE_MESH_POINT) { 1533 struct wireless_dev *wdev = dev->ieee80211_ptr;
1194 err = -EINVAL; 1534
1195 goto unlock; 1535 if (ntype != NL80211_IFTYPE_MESH_POINT)
1196 } 1536 return -EINVAL;
1197 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); 1537 if (netif_running(dev))
1198 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 1538 return -EBUSY;
1199 change = true; 1539
1540 wdev_lock(wdev);
1541 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1542 IEEE80211_MAX_MESH_ID_LEN);
1543 wdev->mesh_id_up_len =
1544 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1545 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1546 wdev->mesh_id_up_len);
1547 wdev_unlock(wdev);
1200 } 1548 }
1201 1549
1202 if (info->attrs[NL80211_ATTR_4ADDR]) { 1550 if (info->attrs[NL80211_ATTR_4ADDR]) {
@@ -1204,20 +1552,18 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1204 change = true; 1552 change = true;
1205 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); 1553 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
1206 if (err) 1554 if (err)
1207 goto unlock; 1555 return err;
1208 } else { 1556 } else {
1209 params.use_4addr = -1; 1557 params.use_4addr = -1;
1210 } 1558 }
1211 1559
1212 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { 1560 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
1213 if (ntype != NL80211_IFTYPE_MONITOR) { 1561 if (ntype != NL80211_IFTYPE_MONITOR)
1214 err = -EINVAL; 1562 return -EINVAL;
1215 goto unlock;
1216 }
1217 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], 1563 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1218 &_flags); 1564 &_flags);
1219 if (err) 1565 if (err)
1220 goto unlock; 1566 return err;
1221 1567
1222 flags = &_flags; 1568 flags = &_flags;
1223 change = true; 1569 change = true;
@@ -1231,18 +1577,14 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1231 if (!err && params.use_4addr != -1) 1577 if (!err && params.use_4addr != -1)
1232 dev->ieee80211_ptr->use_4addr = params.use_4addr; 1578 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1233 1579
1234 unlock:
1235 dev_put(dev);
1236 cfg80211_unlock_rdev(rdev);
1237 unlock_rtnl:
1238 rtnl_unlock();
1239 return err; 1580 return err;
1240} 1581}
1241 1582
1242static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) 1583static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1243{ 1584{
1244 struct cfg80211_registered_device *rdev; 1585 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1245 struct vif_params params; 1586 struct vif_params params;
1587 struct net_device *dev;
1246 int err; 1588 int err;
1247 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; 1589 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
1248 u32 flags; 1590 u32 flags;
@@ -1258,72 +1600,52 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1258 return -EINVAL; 1600 return -EINVAL;
1259 } 1601 }
1260 1602
1261 rtnl_lock();
1262
1263 rdev = cfg80211_get_dev_from_info(info);
1264 if (IS_ERR(rdev)) {
1265 err = PTR_ERR(rdev);
1266 goto unlock_rtnl;
1267 }
1268
1269 if (!rdev->ops->add_virtual_intf || 1603 if (!rdev->ops->add_virtual_intf ||
1270 !(rdev->wiphy.interface_modes & (1 << type))) { 1604 !(rdev->wiphy.interface_modes & (1 << type)))
1271 err = -EOPNOTSUPP; 1605 return -EOPNOTSUPP;
1272 goto unlock;
1273 }
1274
1275 if (type == NL80211_IFTYPE_MESH_POINT &&
1276 info->attrs[NL80211_ATTR_MESH_ID]) {
1277 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
1278 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1279 }
1280 1606
1281 if (info->attrs[NL80211_ATTR_4ADDR]) { 1607 if (info->attrs[NL80211_ATTR_4ADDR]) {
1282 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 1608 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1283 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); 1609 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
1284 if (err) 1610 if (err)
1285 goto unlock; 1611 return err;
1286 } 1612 }
1287 1613
1288 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? 1614 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1289 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, 1615 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1290 &flags); 1616 &flags);
1291 err = rdev->ops->add_virtual_intf(&rdev->wiphy, 1617 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
1292 nla_data(info->attrs[NL80211_ATTR_IFNAME]), 1618 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
1293 type, err ? NULL : &flags, &params); 1619 type, err ? NULL : &flags, &params);
1620 if (IS_ERR(dev))
1621 return PTR_ERR(dev);
1294 1622
1295 unlock: 1623 if (type == NL80211_IFTYPE_MESH_POINT &&
1296 cfg80211_unlock_rdev(rdev); 1624 info->attrs[NL80211_ATTR_MESH_ID]) {
1297 unlock_rtnl: 1625 struct wireless_dev *wdev = dev->ieee80211_ptr;
1298 rtnl_unlock(); 1626
1299 return err; 1627 wdev_lock(wdev);
1628 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1629 IEEE80211_MAX_MESH_ID_LEN);
1630 wdev->mesh_id_up_len =
1631 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1632 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1633 wdev->mesh_id_up_len);
1634 wdev_unlock(wdev);
1635 }
1636
1637 return 0;
1300} 1638}
1301 1639
1302static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) 1640static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1303{ 1641{
1304 struct cfg80211_registered_device *rdev; 1642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1305 int err; 1643 struct net_device *dev = info->user_ptr[1];
1306 struct net_device *dev;
1307 1644
1308 rtnl_lock(); 1645 if (!rdev->ops->del_virtual_intf)
1309 1646 return -EOPNOTSUPP;
1310 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
1311 if (err)
1312 goto unlock_rtnl;
1313
1314 if (!rdev->ops->del_virtual_intf) {
1315 err = -EOPNOTSUPP;
1316 goto out;
1317 }
1318
1319 err = rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
1320 1647
1321 out: 1648 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
1322 cfg80211_unlock_rdev(rdev);
1323 dev_put(dev);
1324 unlock_rtnl:
1325 rtnl_unlock();
1326 return err;
1327} 1649}
1328 1650
1329struct get_key_cookie { 1651struct get_key_cookie {
@@ -1376,11 +1698,12 @@ static void get_key_callback(void *c, struct key_params *params)
1376 1698
1377static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) 1699static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1378{ 1700{
1379 struct cfg80211_registered_device *rdev; 1701 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1380 int err; 1702 int err;
1381 struct net_device *dev; 1703 struct net_device *dev = info->user_ptr[1];
1382 u8 key_idx = 0; 1704 u8 key_idx = 0;
1383 u8 *mac_addr = NULL; 1705 const u8 *mac_addr = NULL;
1706 bool pairwise;
1384 struct get_key_cookie cookie = { 1707 struct get_key_cookie cookie = {
1385 .error = 0, 1708 .error = 0,
1386 }; 1709 };
@@ -1396,30 +1719,28 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1396 if (info->attrs[NL80211_ATTR_MAC]) 1719 if (info->attrs[NL80211_ATTR_MAC])
1397 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 1720 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1398 1721
1399 rtnl_lock(); 1722 pairwise = !!mac_addr;
1400 1723 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
1401 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); 1724 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1402 if (err) 1725 if (kt >= NUM_NL80211_KEYTYPES)
1403 goto unlock_rtnl; 1726 return -EINVAL;
1404 1727 if (kt != NL80211_KEYTYPE_GROUP &&
1405 if (!rdev->ops->get_key) { 1728 kt != NL80211_KEYTYPE_PAIRWISE)
1406 err = -EOPNOTSUPP; 1729 return -EINVAL;
1407 goto out; 1730 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
1408 } 1731 }
1409 1732
1733 if (!rdev->ops->get_key)
1734 return -EOPNOTSUPP;
1735
1410 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 1736 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1411 if (!msg) { 1737 if (!msg)
1412 err = -ENOMEM; 1738 return -ENOMEM;
1413 goto out;
1414 }
1415 1739
1416 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, 1740 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
1417 NL80211_CMD_NEW_KEY); 1741 NL80211_CMD_NEW_KEY);
1418 1742 if (IS_ERR(hdr))
1419 if (IS_ERR(hdr)) { 1743 return PTR_ERR(hdr);
1420 err = PTR_ERR(hdr);
1421 goto free_msg;
1422 }
1423 1744
1424 cookie.msg = msg; 1745 cookie.msg = msg;
1425 cookie.idx = key_idx; 1746 cookie.idx = key_idx;
@@ -1429,8 +1750,12 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1429 if (mac_addr) 1750 if (mac_addr)
1430 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); 1751 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1431 1752
1432 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, mac_addr, 1753 if (pairwise && mac_addr &&
1433 &cookie, get_key_callback); 1754 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1755 return -ENOENT;
1756
1757 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
1758 mac_addr, &cookie, get_key_callback);
1434 1759
1435 if (err) 1760 if (err)
1436 goto free_msg; 1761 goto free_msg;
@@ -1439,30 +1764,21 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1439 goto nla_put_failure; 1764 goto nla_put_failure;
1440 1765
1441 genlmsg_end(msg, hdr); 1766 genlmsg_end(msg, hdr);
1442 err = genlmsg_reply(msg, info); 1767 return genlmsg_reply(msg, info);
1443 goto out;
1444 1768
1445 nla_put_failure: 1769 nla_put_failure:
1446 err = -ENOBUFS; 1770 err = -ENOBUFS;
1447 free_msg: 1771 free_msg:
1448 nlmsg_free(msg); 1772 nlmsg_free(msg);
1449 out:
1450 cfg80211_unlock_rdev(rdev);
1451 dev_put(dev);
1452 unlock_rtnl:
1453 rtnl_unlock();
1454
1455 return err; 1773 return err;
1456} 1774}
1457 1775
1458static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) 1776static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1459{ 1777{
1460 struct cfg80211_registered_device *rdev; 1778 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1461 struct key_parse key; 1779 struct key_parse key;
1462 int err; 1780 int err;
1463 struct net_device *dev; 1781 struct net_device *dev = info->user_ptr[1];
1464 int (*func)(struct wiphy *wiphy, struct net_device *netdev,
1465 u8 key_index);
1466 1782
1467 err = nl80211_parse_key(info, &key); 1783 err = nl80211_parse_key(info, &key);
1468 if (err) 1784 if (err)
@@ -1475,54 +1791,65 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1475 if (!key.def && !key.defmgmt) 1791 if (!key.def && !key.defmgmt)
1476 return -EINVAL; 1792 return -EINVAL;
1477 1793
1478 rtnl_lock(); 1794 wdev_lock(dev->ieee80211_ptr);
1479 1795
1480 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); 1796 if (key.def) {
1481 if (err) 1797 if (!rdev->ops->set_default_key) {
1482 goto unlock_rtnl; 1798 err = -EOPNOTSUPP;
1799 goto out;
1800 }
1483 1801
1484 if (key.def) 1802 err = nl80211_key_allowed(dev->ieee80211_ptr);
1485 func = rdev->ops->set_default_key; 1803 if (err)
1486 else 1804 goto out;
1487 func = rdev->ops->set_default_mgmt_key;
1488 1805
1489 if (!func) { 1806 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
1490 err = -EOPNOTSUPP; 1807 key.def_uni, key.def_multi);
1491 goto out;
1492 }
1493 1808
1494 wdev_lock(dev->ieee80211_ptr); 1809 if (err)
1495 err = nl80211_key_allowed(dev->ieee80211_ptr); 1810 goto out;
1496 if (!err)
1497 err = func(&rdev->wiphy, dev, key.idx);
1498 1811
1499#ifdef CONFIG_CFG80211_WEXT 1812#ifdef CONFIG_CFG80211_WEXT
1500 if (!err) { 1813 dev->ieee80211_ptr->wext.default_key = key.idx;
1501 if (func == rdev->ops->set_default_key)
1502 dev->ieee80211_ptr->wext.default_key = key.idx;
1503 else
1504 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
1505 }
1506#endif 1814#endif
1507 wdev_unlock(dev->ieee80211_ptr); 1815 } else {
1816 if (key.def_uni || !key.def_multi) {
1817 err = -EINVAL;
1818 goto out;
1819 }
1508 1820
1509 out: 1821 if (!rdev->ops->set_default_mgmt_key) {
1510 cfg80211_unlock_rdev(rdev); 1822 err = -EOPNOTSUPP;
1511 dev_put(dev); 1823 goto out;
1824 }
1512 1825
1513 unlock_rtnl: 1826 err = nl80211_key_allowed(dev->ieee80211_ptr);
1514 rtnl_unlock(); 1827 if (err)
1828 goto out;
1829
1830 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
1831 dev, key.idx);
1832 if (err)
1833 goto out;
1834
1835#ifdef CONFIG_CFG80211_WEXT
1836 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
1837#endif
1838 }
1839
1840 out:
1841 wdev_unlock(dev->ieee80211_ptr);
1515 1842
1516 return err; 1843 return err;
1517} 1844}
1518 1845
1519static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) 1846static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1520{ 1847{
1521 struct cfg80211_registered_device *rdev; 1848 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1522 int err; 1849 int err;
1523 struct net_device *dev; 1850 struct net_device *dev = info->user_ptr[1];
1524 struct key_parse key; 1851 struct key_parse key;
1525 u8 *mac_addr = NULL; 1852 const u8 *mac_addr = NULL;
1526 1853
1527 err = nl80211_parse_key(info, &key); 1854 err = nl80211_parse_key(info, &key);
1528 if (err) 1855 if (err)
@@ -1534,43 +1861,42 @@ static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1534 if (info->attrs[NL80211_ATTR_MAC]) 1861 if (info->attrs[NL80211_ATTR_MAC])
1535 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 1862 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1536 1863
1537 rtnl_lock(); 1864 if (key.type == -1) {
1865 if (mac_addr)
1866 key.type = NL80211_KEYTYPE_PAIRWISE;
1867 else
1868 key.type = NL80211_KEYTYPE_GROUP;
1869 }
1538 1870
1539 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); 1871 /* for now */
1540 if (err) 1872 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
1541 goto unlock_rtnl; 1873 key.type != NL80211_KEYTYPE_GROUP)
1874 return -EINVAL;
1542 1875
1543 if (!rdev->ops->add_key) { 1876 if (!rdev->ops->add_key)
1544 err = -EOPNOTSUPP; 1877 return -EOPNOTSUPP;
1545 goto out;
1546 }
1547 1878
1548 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, mac_addr)) { 1879 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
1549 err = -EINVAL; 1880 key.type == NL80211_KEYTYPE_PAIRWISE,
1550 goto out; 1881 mac_addr))
1551 } 1882 return -EINVAL;
1552 1883
1553 wdev_lock(dev->ieee80211_ptr); 1884 wdev_lock(dev->ieee80211_ptr);
1554 err = nl80211_key_allowed(dev->ieee80211_ptr); 1885 err = nl80211_key_allowed(dev->ieee80211_ptr);
1555 if (!err) 1886 if (!err)
1556 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, 1887 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
1888 key.type == NL80211_KEYTYPE_PAIRWISE,
1557 mac_addr, &key.p); 1889 mac_addr, &key.p);
1558 wdev_unlock(dev->ieee80211_ptr); 1890 wdev_unlock(dev->ieee80211_ptr);
1559 1891
1560 out:
1561 cfg80211_unlock_rdev(rdev);
1562 dev_put(dev);
1563 unlock_rtnl:
1564 rtnl_unlock();
1565
1566 return err; 1892 return err;
1567} 1893}
1568 1894
1569static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) 1895static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1570{ 1896{
1571 struct cfg80211_registered_device *rdev; 1897 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1572 int err; 1898 int err;
1573 struct net_device *dev; 1899 struct net_device *dev = info->user_ptr[1];
1574 u8 *mac_addr = NULL; 1900 u8 *mac_addr = NULL;
1575 struct key_parse key; 1901 struct key_parse key;
1576 1902
@@ -1581,21 +1907,32 @@ static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1581 if (info->attrs[NL80211_ATTR_MAC]) 1907 if (info->attrs[NL80211_ATTR_MAC])
1582 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 1908 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1583 1909
1584 rtnl_lock(); 1910 if (key.type == -1) {
1911 if (mac_addr)
1912 key.type = NL80211_KEYTYPE_PAIRWISE;
1913 else
1914 key.type = NL80211_KEYTYPE_GROUP;
1915 }
1585 1916
1586 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); 1917 /* for now */
1587 if (err) 1918 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
1588 goto unlock_rtnl; 1919 key.type != NL80211_KEYTYPE_GROUP)
1920 return -EINVAL;
1589 1921
1590 if (!rdev->ops->del_key) { 1922 if (!rdev->ops->del_key)
1591 err = -EOPNOTSUPP; 1923 return -EOPNOTSUPP;
1592 goto out;
1593 }
1594 1924
1595 wdev_lock(dev->ieee80211_ptr); 1925 wdev_lock(dev->ieee80211_ptr);
1596 err = nl80211_key_allowed(dev->ieee80211_ptr); 1926 err = nl80211_key_allowed(dev->ieee80211_ptr);
1927
1928 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
1929 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1930 err = -ENOENT;
1931
1597 if (!err) 1932 if (!err)
1598 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, mac_addr); 1933 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
1934 key.type == NL80211_KEYTYPE_PAIRWISE,
1935 mac_addr);
1599 1936
1600#ifdef CONFIG_CFG80211_WEXT 1937#ifdef CONFIG_CFG80211_WEXT
1601 if (!err) { 1938 if (!err) {
@@ -1607,13 +1944,6 @@ static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1607#endif 1944#endif
1608 wdev_unlock(dev->ieee80211_ptr); 1945 wdev_unlock(dev->ieee80211_ptr);
1609 1946
1610 out:
1611 cfg80211_unlock_rdev(rdev);
1612 dev_put(dev);
1613
1614 unlock_rtnl:
1615 rtnl_unlock();
1616
1617 return err; 1947 return err;
1618} 1948}
1619 1949
@@ -1621,35 +1951,37 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1621{ 1951{
1622 int (*call)(struct wiphy *wiphy, struct net_device *dev, 1952 int (*call)(struct wiphy *wiphy, struct net_device *dev,
1623 struct beacon_parameters *info); 1953 struct beacon_parameters *info);
1624 struct cfg80211_registered_device *rdev; 1954 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1625 int err; 1955 struct net_device *dev = info->user_ptr[1];
1626 struct net_device *dev; 1956 struct wireless_dev *wdev = dev->ieee80211_ptr;
1627 struct beacon_parameters params; 1957 struct beacon_parameters params;
1628 int haveinfo = 0; 1958 int haveinfo = 0, err;
1629 1959
1630 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) 1960 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]))
1631 return -EINVAL; 1961 return -EINVAL;
1632 1962
1633 rtnl_lock(); 1963 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1634 1964 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
1635 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); 1965 return -EOPNOTSUPP;
1636 if (err)
1637 goto unlock_rtnl;
1638 1966
1639 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { 1967 memset(&params, 0, sizeof(params));
1640 err = -EOPNOTSUPP;
1641 goto out;
1642 }
1643 1968
1644 switch (info->genlhdr->cmd) { 1969 switch (info->genlhdr->cmd) {
1645 case NL80211_CMD_NEW_BEACON: 1970 case NL80211_CMD_NEW_BEACON:
1646 /* these are required for NEW_BEACON */ 1971 /* these are required for NEW_BEACON */
1647 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || 1972 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
1648 !info->attrs[NL80211_ATTR_DTIM_PERIOD] || 1973 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
1649 !info->attrs[NL80211_ATTR_BEACON_HEAD]) { 1974 !info->attrs[NL80211_ATTR_BEACON_HEAD])
1650 err = -EINVAL; 1975 return -EINVAL;
1651 goto out; 1976
1652 } 1977 params.interval =
1978 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
1979 params.dtim_period =
1980 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
1981
1982 err = cfg80211_validate_beacon_int(rdev, params.interval);
1983 if (err)
1984 return err;
1653 1985
1654 call = rdev->ops->add_beacon; 1986 call = rdev->ops->add_beacon;
1655 break; 1987 break;
@@ -1658,28 +1990,11 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1658 break; 1990 break;
1659 default: 1991 default:
1660 WARN_ON(1); 1992 WARN_ON(1);
1661 err = -EOPNOTSUPP; 1993 return -EOPNOTSUPP;
1662 goto out;
1663 }
1664
1665 if (!call) {
1666 err = -EOPNOTSUPP;
1667 goto out;
1668 }
1669
1670 memset(&params, 0, sizeof(params));
1671
1672 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
1673 params.interval =
1674 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
1675 haveinfo = 1;
1676 } 1994 }
1677 1995
1678 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { 1996 if (!call)
1679 params.dtim_period = 1997 return -EOPNOTSUPP;
1680 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
1681 haveinfo = 1;
1682 }
1683 1998
1684 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { 1999 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1685 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); 2000 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
@@ -1695,51 +2010,32 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1695 haveinfo = 1; 2010 haveinfo = 1;
1696 } 2011 }
1697 2012
1698 if (!haveinfo) { 2013 if (!haveinfo)
1699 err = -EINVAL; 2014 return -EINVAL;
1700 goto out;
1701 }
1702 2015
1703 err = call(&rdev->wiphy, dev, &params); 2016 err = call(&rdev->wiphy, dev, &params);
1704 2017 if (!err && params.interval)
1705 out: 2018 wdev->beacon_interval = params.interval;
1706 cfg80211_unlock_rdev(rdev);
1707 dev_put(dev);
1708 unlock_rtnl:
1709 rtnl_unlock();
1710
1711 return err; 2019 return err;
1712} 2020}
1713 2021
1714static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) 2022static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
1715{ 2023{
1716 struct cfg80211_registered_device *rdev; 2024 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2025 struct net_device *dev = info->user_ptr[1];
2026 struct wireless_dev *wdev = dev->ieee80211_ptr;
1717 int err; 2027 int err;
1718 struct net_device *dev;
1719 2028
1720 rtnl_lock(); 2029 if (!rdev->ops->del_beacon)
1721 2030 return -EOPNOTSUPP;
1722 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
1723 if (err)
1724 goto unlock_rtnl;
1725 2031
1726 if (!rdev->ops->del_beacon) { 2032 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1727 err = -EOPNOTSUPP; 2033 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
1728 goto out; 2034 return -EOPNOTSUPP;
1729 }
1730 2035
1731 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1732 err = -EOPNOTSUPP;
1733 goto out;
1734 }
1735 err = rdev->ops->del_beacon(&rdev->wiphy, dev); 2036 err = rdev->ops->del_beacon(&rdev->wiphy, dev);
1736 2037 if (!err)
1737 out: 2038 wdev->beacon_interval = 0;
1738 cfg80211_unlock_rdev(rdev);
1739 dev_put(dev);
1740 unlock_rtnl:
1741 rtnl_unlock();
1742
1743 return err; 2039 return err;
1744} 2040}
1745 2041
@@ -1748,6 +2044,7 @@ static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
1748 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, 2044 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
1749 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, 2045 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
1750 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, 2046 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
2047 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
1751}; 2048};
1752 2049
1753static int parse_station_flags(struct genl_info *info, 2050static int parse_station_flags(struct genl_info *info,
@@ -1794,13 +2091,41 @@ static int parse_station_flags(struct genl_info *info,
1794 return 0; 2091 return 0;
1795} 2092}
1796 2093
2094static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2095 int attr)
2096{
2097 struct nlattr *rate;
2098 u16 bitrate;
2099
2100 rate = nla_nest_start(msg, attr);
2101 if (!rate)
2102 goto nla_put_failure;
2103
2104 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2105 bitrate = cfg80211_calculate_bitrate(info);
2106 if (bitrate > 0)
2107 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
2108
2109 if (info->flags & RATE_INFO_FLAGS_MCS)
2110 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs);
2111 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
2112 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
2113 if (info->flags & RATE_INFO_FLAGS_SHORT_GI)
2114 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
2115
2116 nla_nest_end(msg, rate);
2117 return true;
2118
2119nla_put_failure:
2120 return false;
2121}
2122
1797static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, 2123static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1798 int flags, struct net_device *dev, 2124 int flags, struct net_device *dev,
1799 const u8 *mac_addr, struct station_info *sinfo) 2125 const u8 *mac_addr, struct station_info *sinfo)
1800{ 2126{
1801 void *hdr; 2127 void *hdr;
1802 struct nlattr *sinfoattr, *txrate; 2128 struct nlattr *sinfoattr, *bss_param;
1803 u16 bitrate;
1804 2129
1805 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); 2130 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1806 if (!hdr) 2131 if (!hdr)
@@ -1814,6 +2139,9 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1814 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); 2139 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
1815 if (!sinfoattr) 2140 if (!sinfoattr)
1816 goto nla_put_failure; 2141 goto nla_put_failure;
2142 if (sinfo->filled & STATION_INFO_CONNECTED_TIME)
2143 NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2144 sinfo->connected_time);
1817 if (sinfo->filled & STATION_INFO_INACTIVE_TIME) 2145 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
1818 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, 2146 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
1819 sinfo->inactive_time); 2147 sinfo->inactive_time);
@@ -1835,25 +2163,18 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1835 if (sinfo->filled & STATION_INFO_SIGNAL) 2163 if (sinfo->filled & STATION_INFO_SIGNAL)
1836 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, 2164 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
1837 sinfo->signal); 2165 sinfo->signal);
2166 if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
2167 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2168 sinfo->signal_avg);
1838 if (sinfo->filled & STATION_INFO_TX_BITRATE) { 2169 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
1839 txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE); 2170 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
1840 if (!txrate) 2171 NL80211_STA_INFO_TX_BITRATE))
2172 goto nla_put_failure;
2173 }
2174 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2175 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2176 NL80211_STA_INFO_RX_BITRATE))
1841 goto nla_put_failure; 2177 goto nla_put_failure;
1842
1843 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
1844 bitrate = cfg80211_calculate_bitrate(&sinfo->txrate);
1845 if (bitrate > 0)
1846 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
1847
1848 if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS)
1849 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS,
1850 sinfo->txrate.mcs);
1851 if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
1852 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
1853 if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI)
1854 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
1855
1856 nla_nest_end(msg, txrate);
1857 } 2178 }
1858 if (sinfo->filled & STATION_INFO_RX_PACKETS) 2179 if (sinfo->filled & STATION_INFO_RX_PACKETS)
1859 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, 2180 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
@@ -1861,6 +2182,31 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1861 if (sinfo->filled & STATION_INFO_TX_PACKETS) 2182 if (sinfo->filled & STATION_INFO_TX_PACKETS)
1862 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, 2183 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
1863 sinfo->tx_packets); 2184 sinfo->tx_packets);
2185 if (sinfo->filled & STATION_INFO_TX_RETRIES)
2186 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES,
2187 sinfo->tx_retries);
2188 if (sinfo->filled & STATION_INFO_TX_FAILED)
2189 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED,
2190 sinfo->tx_failed);
2191 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2192 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2193 if (!bss_param)
2194 goto nla_put_failure;
2195
2196 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT)
2197 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT);
2198 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE)
2199 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE);
2200 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME)
2201 NLA_PUT_FLAG(msg,
2202 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME);
2203 NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2204 sinfo->bss_param.dtim_period);
2205 NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2206 sinfo->bss_param.beacon_interval);
2207
2208 nla_nest_end(msg, bss_param);
2209 }
1864 nla_nest_end(msg, sinfoattr); 2210 nla_nest_end(msg, sinfoattr);
1865 2211
1866 return genlmsg_end(msg, hdr); 2212 return genlmsg_end(msg, hdr);
@@ -1877,28 +2223,12 @@ static int nl80211_dump_station(struct sk_buff *skb,
1877 struct cfg80211_registered_device *dev; 2223 struct cfg80211_registered_device *dev;
1878 struct net_device *netdev; 2224 struct net_device *netdev;
1879 u8 mac_addr[ETH_ALEN]; 2225 u8 mac_addr[ETH_ALEN];
1880 int ifidx = cb->args[0];
1881 int sta_idx = cb->args[1]; 2226 int sta_idx = cb->args[1];
1882 int err; 2227 int err;
1883 2228
1884 if (!ifidx) 2229 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
1885 ifidx = nl80211_get_ifidx(cb); 2230 if (err)
1886 if (ifidx < 0) 2231 return err;
1887 return ifidx;
1888
1889 rtnl_lock();
1890
1891 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
1892 if (!netdev) {
1893 err = -ENODEV;
1894 goto out_rtnl;
1895 }
1896
1897 dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
1898 if (IS_ERR(dev)) {
1899 err = PTR_ERR(dev);
1900 goto out_rtnl;
1901 }
1902 2232
1903 if (!dev->ops->dump_station) { 2233 if (!dev->ops->dump_station) {
1904 err = -EOPNOTSUPP; 2234 err = -EOPNOTSUPP;
@@ -1928,21 +2258,19 @@ static int nl80211_dump_station(struct sk_buff *skb,
1928 cb->args[1] = sta_idx; 2258 cb->args[1] = sta_idx;
1929 err = skb->len; 2259 err = skb->len;
1930 out_err: 2260 out_err:
1931 cfg80211_unlock_rdev(dev); 2261 nl80211_finish_netdev_dump(dev);
1932 out_rtnl:
1933 rtnl_unlock();
1934 2262
1935 return err; 2263 return err;
1936} 2264}
1937 2265
1938static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) 2266static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1939{ 2267{
1940 struct cfg80211_registered_device *rdev; 2268 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1941 int err; 2269 struct net_device *dev = info->user_ptr[1];
1942 struct net_device *dev;
1943 struct station_info sinfo; 2270 struct station_info sinfo;
1944 struct sk_buff *msg; 2271 struct sk_buff *msg;
1945 u8 *mac_addr = NULL; 2272 u8 *mac_addr = NULL;
2273 int err;
1946 2274
1947 memset(&sinfo, 0, sizeof(sinfo)); 2275 memset(&sinfo, 0, sizeof(sinfo));
1948 2276
@@ -1951,41 +2279,24 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1951 2279
1952 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 2280 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1953 2281
1954 rtnl_lock(); 2282 if (!rdev->ops->get_station)
1955 2283 return -EOPNOTSUPP;
1956 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
1957 if (err)
1958 goto out_rtnl;
1959
1960 if (!rdev->ops->get_station) {
1961 err = -EOPNOTSUPP;
1962 goto out;
1963 }
1964 2284
1965 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); 2285 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
1966 if (err) 2286 if (err)
1967 goto out; 2287 return err;
1968 2288
1969 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 2289 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1970 if (!msg) 2290 if (!msg)
1971 goto out; 2291 return -ENOMEM;
1972 2292
1973 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, 2293 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
1974 dev, mac_addr, &sinfo) < 0) 2294 dev, mac_addr, &sinfo) < 0) {
1975 goto out_free; 2295 nlmsg_free(msg);
1976 2296 return -ENOBUFS;
1977 err = genlmsg_reply(msg, info); 2297 }
1978 goto out;
1979
1980 out_free:
1981 nlmsg_free(msg);
1982 out:
1983 cfg80211_unlock_rdev(rdev);
1984 dev_put(dev);
1985 out_rtnl:
1986 rtnl_unlock();
1987 2298
1988 return err; 2299 return genlmsg_reply(msg, info);
1989} 2300}
1990 2301
1991/* 2302/*
@@ -2015,15 +2326,16 @@ static int get_vlan(struct genl_info *info,
2015 2326
2016static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) 2327static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2017{ 2328{
2018 struct cfg80211_registered_device *rdev; 2329 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2019 int err; 2330 int err;
2020 struct net_device *dev; 2331 struct net_device *dev = info->user_ptr[1];
2021 struct station_parameters params; 2332 struct station_parameters params;
2022 u8 *mac_addr = NULL; 2333 u8 *mac_addr = NULL;
2023 2334
2024 memset(&params, 0, sizeof(params)); 2335 memset(&params, 0, sizeof(params));
2025 2336
2026 params.listen_interval = -1; 2337 params.listen_interval = -1;
2338 params.plink_state = -1;
2027 2339
2028 if (info->attrs[NL80211_ATTR_STA_AID]) 2340 if (info->attrs[NL80211_ATTR_STA_AID])
2029 return -EINVAL; 2341 return -EINVAL;
@@ -2055,11 +2367,9 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2055 params.plink_action = 2367 params.plink_action =
2056 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); 2368 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2057 2369
2058 rtnl_lock(); 2370 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2059 2371 params.plink_state =
2060 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); 2372 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2061 if (err)
2062 goto out_rtnl;
2063 2373
2064 err = get_vlan(info, rdev, &params.vlan); 2374 err = get_vlan(info, rdev, &params.vlan);
2065 if (err) 2375 if (err)
@@ -2071,10 +2381,12 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2071 switch (dev->ieee80211_ptr->iftype) { 2381 switch (dev->ieee80211_ptr->iftype) {
2072 case NL80211_IFTYPE_AP: 2382 case NL80211_IFTYPE_AP:
2073 case NL80211_IFTYPE_AP_VLAN: 2383 case NL80211_IFTYPE_AP_VLAN:
2384 case NL80211_IFTYPE_P2P_GO:
2074 /* disallow mesh-specific things */ 2385 /* disallow mesh-specific things */
2075 if (params.plink_action) 2386 if (params.plink_action)
2076 err = -EINVAL; 2387 err = -EINVAL;
2077 break; 2388 break;
2389 case NL80211_IFTYPE_P2P_CLIENT:
2078 case NL80211_IFTYPE_STATION: 2390 case NL80211_IFTYPE_STATION:
2079 /* disallow everything but AUTHORIZED flag */ 2391 /* disallow everything but AUTHORIZED flag */
2080 if (params.plink_action) 2392 if (params.plink_action)
@@ -2098,9 +2410,10 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2098 err = -EINVAL; 2410 err = -EINVAL;
2099 if (params.listen_interval >= 0) 2411 if (params.listen_interval >= 0)
2100 err = -EINVAL; 2412 err = -EINVAL;
2101 if (params.supported_rates) 2413 if (params.sta_flags_mask &
2102 err = -EINVAL; 2414 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2103 if (params.sta_flags_mask) 2415 BIT(NL80211_STA_FLAG_MFP) |
2416 BIT(NL80211_STA_FLAG_AUTHORIZED)))
2104 err = -EINVAL; 2417 err = -EINVAL;
2105 break; 2418 break;
2106 default: 2419 default:
@@ -2120,19 +2433,15 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2120 out: 2433 out:
2121 if (params.vlan) 2434 if (params.vlan)
2122 dev_put(params.vlan); 2435 dev_put(params.vlan);
2123 cfg80211_unlock_rdev(rdev);
2124 dev_put(dev);
2125 out_rtnl:
2126 rtnl_unlock();
2127 2436
2128 return err; 2437 return err;
2129} 2438}
2130 2439
2131static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) 2440static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2132{ 2441{
2133 struct cfg80211_registered_device *rdev; 2442 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2134 int err; 2443 int err;
2135 struct net_device *dev; 2444 struct net_device *dev = info->user_ptr[1];
2136 struct station_parameters params; 2445 struct station_parameters params;
2137 u8 *mac_addr = NULL; 2446 u8 *mac_addr = NULL;
2138 2447
@@ -2166,20 +2475,18 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2166 params.ht_capa = 2475 params.ht_capa =
2167 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 2476 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2168 2477
2478 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2479 params.plink_action =
2480 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2481
2169 if (parse_station_flags(info, &params)) 2482 if (parse_station_flags(info, &params))
2170 return -EINVAL; 2483 return -EINVAL;
2171 2484
2172 rtnl_lock();
2173
2174 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
2175 if (err)
2176 goto out_rtnl;
2177
2178 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 2485 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2179 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN) { 2486 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
2180 err = -EINVAL; 2487 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
2181 goto out; 2488 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2182 } 2489 return -EINVAL;
2183 2490
2184 err = get_vlan(info, rdev, &params.vlan); 2491 err = get_vlan(info, rdev, &params.vlan);
2185 if (err) 2492 if (err)
@@ -2193,61 +2500,33 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2193 goto out; 2500 goto out;
2194 } 2501 }
2195 2502
2196 if (!netif_running(dev)) {
2197 err = -ENETDOWN;
2198 goto out;
2199 }
2200
2201 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params); 2503 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
2202 2504
2203 out: 2505 out:
2204 if (params.vlan) 2506 if (params.vlan)
2205 dev_put(params.vlan); 2507 dev_put(params.vlan);
2206 cfg80211_unlock_rdev(rdev);
2207 dev_put(dev);
2208 out_rtnl:
2209 rtnl_unlock();
2210
2211 return err; 2508 return err;
2212} 2509}
2213 2510
2214static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) 2511static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
2215{ 2512{
2216 struct cfg80211_registered_device *rdev; 2513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2217 int err; 2514 struct net_device *dev = info->user_ptr[1];
2218 struct net_device *dev;
2219 u8 *mac_addr = NULL; 2515 u8 *mac_addr = NULL;
2220 2516
2221 if (info->attrs[NL80211_ATTR_MAC]) 2517 if (info->attrs[NL80211_ATTR_MAC])
2222 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 2518 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2223 2519
2224 rtnl_lock();
2225
2226 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
2227 if (err)
2228 goto out_rtnl;
2229
2230 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 2520 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2231 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && 2521 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
2232 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { 2522 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
2233 err = -EINVAL; 2523 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2234 goto out; 2524 return -EINVAL;
2235 }
2236
2237 if (!rdev->ops->del_station) {
2238 err = -EOPNOTSUPP;
2239 goto out;
2240 }
2241
2242 err = rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
2243 2525
2244 out: 2526 if (!rdev->ops->del_station)
2245 cfg80211_unlock_rdev(rdev); 2527 return -EOPNOTSUPP;
2246 dev_put(dev);
2247 out_rtnl:
2248 rtnl_unlock();
2249 2528
2250 return err; 2529 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
2251} 2530}
2252 2531
2253static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, 2532static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
@@ -2310,28 +2589,12 @@ static int nl80211_dump_mpath(struct sk_buff *skb,
2310 struct net_device *netdev; 2589 struct net_device *netdev;
2311 u8 dst[ETH_ALEN]; 2590 u8 dst[ETH_ALEN];
2312 u8 next_hop[ETH_ALEN]; 2591 u8 next_hop[ETH_ALEN];
2313 int ifidx = cb->args[0];
2314 int path_idx = cb->args[1]; 2592 int path_idx = cb->args[1];
2315 int err; 2593 int err;
2316 2594
2317 if (!ifidx) 2595 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2318 ifidx = nl80211_get_ifidx(cb); 2596 if (err)
2319 if (ifidx < 0) 2597 return err;
2320 return ifidx;
2321
2322 rtnl_lock();
2323
2324 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
2325 if (!netdev) {
2326 err = -ENODEV;
2327 goto out_rtnl;
2328 }
2329
2330 dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
2331 if (IS_ERR(dev)) {
2332 err = PTR_ERR(dev);
2333 goto out_rtnl;
2334 }
2335 2598
2336 if (!dev->ops->dump_mpath) { 2599 if (!dev->ops->dump_mpath) {
2337 err = -EOPNOTSUPP; 2600 err = -EOPNOTSUPP;
@@ -2365,18 +2628,15 @@ static int nl80211_dump_mpath(struct sk_buff *skb,
2365 cb->args[1] = path_idx; 2628 cb->args[1] = path_idx;
2366 err = skb->len; 2629 err = skb->len;
2367 out_err: 2630 out_err:
2368 cfg80211_unlock_rdev(dev); 2631 nl80211_finish_netdev_dump(dev);
2369 out_rtnl:
2370 rtnl_unlock();
2371
2372 return err; 2632 return err;
2373} 2633}
2374 2634
2375static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) 2635static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2376{ 2636{
2377 struct cfg80211_registered_device *rdev; 2637 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2378 int err; 2638 int err;
2379 struct net_device *dev; 2639 struct net_device *dev = info->user_ptr[1];
2380 struct mpath_info pinfo; 2640 struct mpath_info pinfo;
2381 struct sk_buff *msg; 2641 struct sk_buff *msg;
2382 u8 *dst = NULL; 2642 u8 *dst = NULL;
@@ -2389,53 +2649,33 @@ static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2389 2649
2390 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 2650 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2391 2651
2392 rtnl_lock(); 2652 if (!rdev->ops->get_mpath)
2393 2653 return -EOPNOTSUPP;
2394 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
2395 if (err)
2396 goto out_rtnl;
2397
2398 if (!rdev->ops->get_mpath) {
2399 err = -EOPNOTSUPP;
2400 goto out;
2401 }
2402 2654
2403 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { 2655 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2404 err = -EOPNOTSUPP; 2656 return -EOPNOTSUPP;
2405 goto out;
2406 }
2407 2657
2408 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo); 2658 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
2409 if (err) 2659 if (err)
2410 goto out; 2660 return err;
2411 2661
2412 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 2662 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2413 if (!msg) 2663 if (!msg)
2414 goto out; 2664 return -ENOMEM;
2415 2665
2416 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, 2666 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
2417 dev, dst, next_hop, &pinfo) < 0) 2667 dev, dst, next_hop, &pinfo) < 0) {
2418 goto out_free; 2668 nlmsg_free(msg);
2419 2669 return -ENOBUFS;
2420 err = genlmsg_reply(msg, info); 2670 }
2421 goto out;
2422
2423 out_free:
2424 nlmsg_free(msg);
2425 out:
2426 cfg80211_unlock_rdev(rdev);
2427 dev_put(dev);
2428 out_rtnl:
2429 rtnl_unlock();
2430 2671
2431 return err; 2672 return genlmsg_reply(msg, info);
2432} 2673}
2433 2674
2434static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) 2675static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2435{ 2676{
2436 struct cfg80211_registered_device *rdev; 2677 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2437 int err; 2678 struct net_device *dev = info->user_ptr[1];
2438 struct net_device *dev;
2439 u8 *dst = NULL; 2679 u8 *dst = NULL;
2440 u8 *next_hop = NULL; 2680 u8 *next_hop = NULL;
2441 2681
@@ -2448,42 +2688,19 @@ static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2448 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 2688 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2449 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 2689 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2450 2690
2451 rtnl_lock(); 2691 if (!rdev->ops->change_mpath)
2452 2692 return -EOPNOTSUPP;
2453 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
2454 if (err)
2455 goto out_rtnl;
2456
2457 if (!rdev->ops->change_mpath) {
2458 err = -EOPNOTSUPP;
2459 goto out;
2460 }
2461
2462 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2463 err = -EOPNOTSUPP;
2464 goto out;
2465 }
2466
2467 if (!netif_running(dev)) {
2468 err = -ENETDOWN;
2469 goto out;
2470 }
2471
2472 err = rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
2473 2693
2474 out: 2694 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2475 cfg80211_unlock_rdev(rdev); 2695 return -EOPNOTSUPP;
2476 dev_put(dev);
2477 out_rtnl:
2478 rtnl_unlock();
2479 2696
2480 return err; 2697 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
2481} 2698}
2699
2482static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) 2700static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2483{ 2701{
2484 struct cfg80211_registered_device *rdev; 2702 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2485 int err; 2703 struct net_device *dev = info->user_ptr[1];
2486 struct net_device *dev;
2487 u8 *dst = NULL; 2704 u8 *dst = NULL;
2488 u8 *next_hop = NULL; 2705 u8 *next_hop = NULL;
2489 2706
@@ -2496,75 +2713,34 @@ static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2496 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 2713 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2497 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 2714 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2498 2715
2499 rtnl_lock(); 2716 if (!rdev->ops->add_mpath)
2500 2717 return -EOPNOTSUPP;
2501 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
2502 if (err)
2503 goto out_rtnl;
2504
2505 if (!rdev->ops->add_mpath) {
2506 err = -EOPNOTSUPP;
2507 goto out;
2508 }
2509
2510 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2511 err = -EOPNOTSUPP;
2512 goto out;
2513 }
2514
2515 if (!netif_running(dev)) {
2516 err = -ENETDOWN;
2517 goto out;
2518 }
2519
2520 err = rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
2521 2718
2522 out: 2719 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2523 cfg80211_unlock_rdev(rdev); 2720 return -EOPNOTSUPP;
2524 dev_put(dev);
2525 out_rtnl:
2526 rtnl_unlock();
2527 2721
2528 return err; 2722 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
2529} 2723}
2530 2724
2531static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) 2725static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
2532{ 2726{
2533 struct cfg80211_registered_device *rdev; 2727 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2534 int err; 2728 struct net_device *dev = info->user_ptr[1];
2535 struct net_device *dev;
2536 u8 *dst = NULL; 2729 u8 *dst = NULL;
2537 2730
2538 if (info->attrs[NL80211_ATTR_MAC]) 2731 if (info->attrs[NL80211_ATTR_MAC])
2539 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 2732 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2540 2733
2541 rtnl_lock(); 2734 if (!rdev->ops->del_mpath)
2542 2735 return -EOPNOTSUPP;
2543 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
2544 if (err)
2545 goto out_rtnl;
2546
2547 if (!rdev->ops->del_mpath) {
2548 err = -EOPNOTSUPP;
2549 goto out;
2550 }
2551
2552 err = rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
2553
2554 out:
2555 cfg80211_unlock_rdev(rdev);
2556 dev_put(dev);
2557 out_rtnl:
2558 rtnl_unlock();
2559 2736
2560 return err; 2737 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
2561} 2738}
2562 2739
2563static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) 2740static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2564{ 2741{
2565 struct cfg80211_registered_device *rdev; 2742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2566 int err; 2743 struct net_device *dev = info->user_ptr[1];
2567 struct net_device *dev;
2568 struct bss_parameters params; 2744 struct bss_parameters params;
2569 2745
2570 memset(&params, 0, sizeof(params)); 2746 memset(&params, 0, sizeof(params));
@@ -2573,6 +2749,7 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2573 params.use_short_preamble = -1; 2749 params.use_short_preamble = -1;
2574 params.use_short_slot_time = -1; 2750 params.use_short_slot_time = -1;
2575 params.ap_isolate = -1; 2751 params.ap_isolate = -1;
2752 params.ht_opmode = -1;
2576 2753
2577 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) 2754 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
2578 params.use_cts_prot = 2755 params.use_cts_prot =
@@ -2591,32 +2768,18 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2591 } 2768 }
2592 if (info->attrs[NL80211_ATTR_AP_ISOLATE]) 2769 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
2593 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); 2770 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
2771 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
2772 params.ht_opmode =
2773 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
2594 2774
2595 rtnl_lock(); 2775 if (!rdev->ops->change_bss)
2596 2776 return -EOPNOTSUPP;
2597 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
2598 if (err)
2599 goto out_rtnl;
2600
2601 if (!rdev->ops->change_bss) {
2602 err = -EOPNOTSUPP;
2603 goto out;
2604 }
2605
2606 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
2607 err = -EOPNOTSUPP;
2608 goto out;
2609 }
2610
2611 err = rdev->ops->change_bss(&rdev->wiphy, dev, &params);
2612 2777
2613 out: 2778 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2614 cfg80211_unlock_rdev(rdev); 2779 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2615 dev_put(dev); 2780 return -EOPNOTSUPP;
2616 out_rtnl:
2617 rtnl_unlock();
2618 2781
2619 return err; 2782 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
2620} 2783}
2621 2784
2622static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { 2785static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
@@ -2692,45 +2855,45 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2692 return r; 2855 return r;
2693} 2856}
2694 2857
2695static int nl80211_get_mesh_params(struct sk_buff *skb, 2858static int nl80211_get_mesh_config(struct sk_buff *skb,
2696 struct genl_info *info) 2859 struct genl_info *info)
2697{ 2860{
2698 struct cfg80211_registered_device *rdev; 2861 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2862 struct net_device *dev = info->user_ptr[1];
2863 struct wireless_dev *wdev = dev->ieee80211_ptr;
2699 struct mesh_config cur_params; 2864 struct mesh_config cur_params;
2700 int err; 2865 int err = 0;
2701 struct net_device *dev;
2702 void *hdr; 2866 void *hdr;
2703 struct nlattr *pinfoattr; 2867 struct nlattr *pinfoattr;
2704 struct sk_buff *msg; 2868 struct sk_buff *msg;
2705 2869
2706 rtnl_lock(); 2870 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
2871 return -EOPNOTSUPP;
2707 2872
2708 /* Look up our device */ 2873 if (!rdev->ops->get_mesh_config)
2709 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); 2874 return -EOPNOTSUPP;
2710 if (err)
2711 goto out_rtnl;
2712 2875
2713 if (!rdev->ops->get_mesh_params) { 2876 wdev_lock(wdev);
2714 err = -EOPNOTSUPP; 2877 /* If not connected, get default parameters */
2715 goto out; 2878 if (!wdev->mesh_id_len)
2716 } 2879 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
2880 else
2881 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
2882 &cur_params);
2883 wdev_unlock(wdev);
2717 2884
2718 /* Get the mesh params */
2719 err = rdev->ops->get_mesh_params(&rdev->wiphy, dev, &cur_params);
2720 if (err) 2885 if (err)
2721 goto out; 2886 return err;
2722 2887
2723 /* Draw up a netlink message to send back */ 2888 /* Draw up a netlink message to send back */
2724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 2889 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2725 if (!msg) { 2890 if (!msg)
2726 err = -ENOBUFS; 2891 return -ENOMEM;
2727 goto out;
2728 }
2729 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, 2892 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2730 NL80211_CMD_GET_MESH_PARAMS); 2893 NL80211_CMD_GET_MESH_CONFIG);
2731 if (!hdr) 2894 if (!hdr)
2732 goto nla_put_failure; 2895 goto out;
2733 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS); 2896 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
2734 if (!pinfoattr) 2897 if (!pinfoattr)
2735 goto nla_put_failure; 2898 goto nla_put_failure;
2736 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); 2899 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
@@ -2746,6 +2909,8 @@ static int nl80211_get_mesh_params(struct sk_buff *skb,
2746 cur_params.dot11MeshMaxRetries); 2909 cur_params.dot11MeshMaxRetries);
2747 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, 2910 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
2748 cur_params.dot11MeshTTL); 2911 cur_params.dot11MeshTTL);
2912 NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
2913 cur_params.element_ttl);
2749 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 2914 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
2750 cur_params.auto_open_plinks); 2915 cur_params.auto_open_plinks);
2751 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 2916 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
@@ -2764,31 +2929,15 @@ static int nl80211_get_mesh_params(struct sk_buff *skb,
2764 cur_params.dot11MeshHWMPRootMode); 2929 cur_params.dot11MeshHWMPRootMode);
2765 nla_nest_end(msg, pinfoattr); 2930 nla_nest_end(msg, pinfoattr);
2766 genlmsg_end(msg, hdr); 2931 genlmsg_end(msg, hdr);
2767 err = genlmsg_reply(msg, info); 2932 return genlmsg_reply(msg, info);
2768 goto out;
2769 2933
2770 nla_put_failure: 2934 nla_put_failure:
2771 genlmsg_cancel(msg, hdr); 2935 genlmsg_cancel(msg, hdr);
2772 nlmsg_free(msg);
2773 err = -EMSGSIZE;
2774 out: 2936 out:
2775 /* Cleanup */ 2937 nlmsg_free(msg);
2776 cfg80211_unlock_rdev(rdev); 2938 return -ENOBUFS;
2777 dev_put(dev);
2778 out_rtnl:
2779 rtnl_unlock();
2780
2781 return err;
2782} 2939}
2783 2940
2784#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2785do {\
2786 if (table[attr_num]) {\
2787 cfg.param = nla_fn(table[attr_num]); \
2788 mask |= (1 << (attr_num - 1)); \
2789 } \
2790} while (0);\
2791
2792static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { 2941static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
2793 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, 2942 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
2794 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, 2943 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
@@ -2796,6 +2945,7 @@ static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_A
2796 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, 2945 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
2797 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, 2946 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
2798 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, 2947 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
2948 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
2799 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, 2949 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
2800 2950
2801 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, 2951 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
@@ -2806,40 +2956,44 @@ static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_A
2806 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, 2956 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
2807}; 2957};
2808 2958
2809static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) 2959static const struct nla_policy
2960 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
2961 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
2962 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
2963 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
2964 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
2965 .len = IEEE80211_MAX_DATA_LEN },
2966 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
2967};
2968
2969static int nl80211_parse_mesh_config(struct genl_info *info,
2970 struct mesh_config *cfg,
2971 u32 *mask_out)
2810{ 2972{
2811 int err;
2812 u32 mask;
2813 struct cfg80211_registered_device *rdev;
2814 struct net_device *dev;
2815 struct mesh_config cfg;
2816 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; 2973 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
2817 struct nlattr *parent_attr; 2974 u32 mask = 0;
2975
2976#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2977do {\
2978 if (table[attr_num]) {\
2979 cfg->param = nla_fn(table[attr_num]); \
2980 mask |= (1 << (attr_num - 1)); \
2981 } \
2982} while (0);\
2818 2983
2819 parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS]; 2984
2820 if (!parent_attr) 2985 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
2821 return -EINVAL; 2986 return -EINVAL;
2822 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, 2987 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
2823 parent_attr, nl80211_meshconf_params_policy)) 2988 info->attrs[NL80211_ATTR_MESH_CONFIG],
2989 nl80211_meshconf_params_policy))
2824 return -EINVAL; 2990 return -EINVAL;
2825 2991
2826 rtnl_lock();
2827
2828 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
2829 if (err)
2830 goto out_rtnl;
2831
2832 if (!rdev->ops->set_mesh_params) {
2833 err = -EOPNOTSUPP;
2834 goto out;
2835 }
2836
2837 /* This makes sure that there aren't more than 32 mesh config 2992 /* This makes sure that there aren't more than 32 mesh config
2838 * parameters (otherwise our bitfield scheme would not work.) */ 2993 * parameters (otherwise our bitfield scheme would not work.) */
2839 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); 2994 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
2840 2995
2841 /* Fill in the params struct */ 2996 /* Fill in the params struct */
2842 mask = 0;
2843 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 2997 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
2844 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); 2998 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
2845 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 2999 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
@@ -2852,6 +3006,8 @@ static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2852 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); 3006 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
2853 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 3007 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
2854 mask, NL80211_MESHCONF_TTL, nla_get_u8); 3008 mask, NL80211_MESHCONF_TTL, nla_get_u8);
3009 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
3010 mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
2855 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 3011 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
2856 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); 3012 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
2857 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 3013 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
@@ -2876,21 +3032,85 @@ static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2876 dot11MeshHWMPRootMode, mask, 3032 dot11MeshHWMPRootMode, mask,
2877 NL80211_MESHCONF_HWMP_ROOTMODE, 3033 NL80211_MESHCONF_HWMP_ROOTMODE,
2878 nla_get_u8); 3034 nla_get_u8);
3035 if (mask_out)
3036 *mask_out = mask;
2879 3037
2880 /* Apply changes */ 3038 return 0;
2881 err = rdev->ops->set_mesh_params(&rdev->wiphy, dev, &cfg, mask);
2882 3039
2883 out: 3040#undef FILL_IN_MESH_PARAM_IF_SET
2884 /* cleanup */ 3041}
2885 cfg80211_unlock_rdev(rdev);
2886 dev_put(dev);
2887 out_rtnl:
2888 rtnl_unlock();
2889 3042
2890 return err; 3043static int nl80211_parse_mesh_setup(struct genl_info *info,
3044 struct mesh_setup *setup)
3045{
3046 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3047
3048 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3049 return -EINVAL;
3050 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3051 info->attrs[NL80211_ATTR_MESH_SETUP],
3052 nl80211_mesh_setup_params_policy))
3053 return -EINVAL;
3054
3055 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3056 setup->path_sel_proto =
3057 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3058 IEEE80211_PATH_PROTOCOL_VENDOR :
3059 IEEE80211_PATH_PROTOCOL_HWMP;
3060
3061 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3062 setup->path_metric =
3063 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3064 IEEE80211_PATH_METRIC_VENDOR :
3065 IEEE80211_PATH_METRIC_AIRTIME;
3066
3067
3068 if (tb[NL80211_MESH_SETUP_IE]) {
3069 struct nlattr *ieattr =
3070 tb[NL80211_MESH_SETUP_IE];
3071 if (!is_valid_ie_attr(ieattr))
3072 return -EINVAL;
3073 setup->ie = nla_data(ieattr);
3074 setup->ie_len = nla_len(ieattr);
3075 }
3076 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3077 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
3078
3079 return 0;
2891} 3080}
2892 3081
2893#undef FILL_IN_MESH_PARAM_IF_SET 3082static int nl80211_update_mesh_config(struct sk_buff *skb,
3083 struct genl_info *info)
3084{
3085 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3086 struct net_device *dev = info->user_ptr[1];
3087 struct wireless_dev *wdev = dev->ieee80211_ptr;
3088 struct mesh_config cfg;
3089 u32 mask;
3090 int err;
3091
3092 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3093 return -EOPNOTSUPP;
3094
3095 if (!rdev->ops->update_mesh_config)
3096 return -EOPNOTSUPP;
3097
3098 err = nl80211_parse_mesh_config(info, &cfg, &mask);
3099 if (err)
3100 return err;
3101
3102 wdev_lock(wdev);
3103 if (!wdev->mesh_id_len)
3104 err = -ENOLINK;
3105
3106 if (!err)
3107 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
3108 mask, &cfg);
3109
3110 wdev_unlock(wdev);
3111
3112 return err;
3113}
2894 3114
2895static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) 3115static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
2896{ 3116{
@@ -2914,7 +3134,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
2914 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, 3134 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2915 NL80211_CMD_GET_REG); 3135 NL80211_CMD_GET_REG);
2916 if (!hdr) 3136 if (!hdr)
2917 goto nla_put_failure; 3137 goto put_failure;
2918 3138
2919 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, 3139 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
2920 cfg80211_regdomain->alpha2); 3140 cfg80211_regdomain->alpha2);
@@ -2961,6 +3181,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
2961 3181
2962nla_put_failure: 3182nla_put_failure:
2963 genlmsg_cancel(msg, hdr); 3183 genlmsg_cancel(msg, hdr);
3184put_failure:
2964 nlmsg_free(msg); 3185 nlmsg_free(msg);
2965 err = -EMSGSIZE; 3186 err = -EMSGSIZE;
2966out: 3187out:
@@ -3070,11 +3291,9 @@ static int validate_scan_freqs(struct nlattr *freqs)
3070 3291
3071static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) 3292static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3072{ 3293{
3073 struct cfg80211_registered_device *rdev; 3294 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3074 struct net_device *dev; 3295 struct net_device *dev = info->user_ptr[1];
3075 struct cfg80211_scan_request *request; 3296 struct cfg80211_scan_request *request;
3076 struct cfg80211_ssid *ssid;
3077 struct ieee80211_channel *channel;
3078 struct nlattr *attr; 3297 struct nlattr *attr;
3079 struct wiphy *wiphy; 3298 struct wiphy *wiphy;
3080 int err, tmp, n_ssids = 0, n_channels, i; 3299 int err, tmp, n_ssids = 0, n_channels, i;
@@ -3084,36 +3303,178 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3084 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) 3303 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3085 return -EINVAL; 3304 return -EINVAL;
3086 3305
3087 rtnl_lock(); 3306 wiphy = &rdev->wiphy;
3088 3307
3089 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); 3308 if (!rdev->ops->scan)
3090 if (err) 3309 return -EOPNOTSUPP;
3091 goto out_rtnl;
3092 3310
3093 wiphy = &rdev->wiphy; 3311 if (rdev->scan_req)
3312 return -EBUSY;
3094 3313
3095 if (!rdev->ops->scan) { 3314 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3096 err = -EOPNOTSUPP; 3315 n_channels = validate_scan_freqs(
3097 goto out; 3316 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
3317 if (!n_channels)
3318 return -EINVAL;
3319 } else {
3320 n_channels = 0;
3321
3322 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3323 if (wiphy->bands[band])
3324 n_channels += wiphy->bands[band]->n_channels;
3098 } 3325 }
3099 3326
3100 if (!netif_running(dev)) { 3327 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3101 err = -ENETDOWN; 3328 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
3102 goto out; 3329 n_ssids++;
3330
3331 if (n_ssids > wiphy->max_scan_ssids)
3332 return -EINVAL;
3333
3334 if (info->attrs[NL80211_ATTR_IE])
3335 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3336 else
3337 ie_len = 0;
3338
3339 if (ie_len > wiphy->max_scan_ie_len)
3340 return -EINVAL;
3341
3342 request = kzalloc(sizeof(*request)
3343 + sizeof(*request->ssids) * n_ssids
3344 + sizeof(*request->channels) * n_channels
3345 + ie_len, GFP_KERNEL);
3346 if (!request)
3347 return -ENOMEM;
3348
3349 if (n_ssids)
3350 request->ssids = (void *)&request->channels[n_channels];
3351 request->n_ssids = n_ssids;
3352 if (ie_len) {
3353 if (request->ssids)
3354 request->ie = (void *)(request->ssids + n_ssids);
3355 else
3356 request->ie = (void *)(request->channels + n_channels);
3103 } 3357 }
3104 3358
3105 if (rdev->scan_req) { 3359 i = 0;
3106 err = -EBUSY; 3360 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3107 goto out; 3361 /* user specified, bail out if channel not found */
3362 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
3363 struct ieee80211_channel *chan;
3364
3365 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3366
3367 if (!chan) {
3368 err = -EINVAL;
3369 goto out_free;
3370 }
3371
3372 /* ignore disabled channels */
3373 if (chan->flags & IEEE80211_CHAN_DISABLED)
3374 continue;
3375
3376 request->channels[i] = chan;
3377 i++;
3378 }
3379 } else {
3380 /* all channels */
3381 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3382 int j;
3383 if (!wiphy->bands[band])
3384 continue;
3385 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
3386 struct ieee80211_channel *chan;
3387
3388 chan = &wiphy->bands[band]->channels[j];
3389
3390 if (chan->flags & IEEE80211_CHAN_DISABLED)
3391 continue;
3392
3393 request->channels[i] = chan;
3394 i++;
3395 }
3396 }
3397 }
3398
3399 if (!i) {
3400 err = -EINVAL;
3401 goto out_free;
3402 }
3403
3404 request->n_channels = i;
3405
3406 i = 0;
3407 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3408 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
3409 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
3410 err = -EINVAL;
3411 goto out_free;
3412 }
3413 request->ssids[i].ssid_len = nla_len(attr);
3414 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
3415 i++;
3416 }
3417 }
3418
3419 if (info->attrs[NL80211_ATTR_IE]) {
3420 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3421 memcpy((void *)request->ie,
3422 nla_data(info->attrs[NL80211_ATTR_IE]),
3423 request->ie_len);
3108 } 3424 }
3109 3425
3426 request->dev = dev;
3427 request->wiphy = &rdev->wiphy;
3428
3429 rdev->scan_req = request;
3430 err = rdev->ops->scan(&rdev->wiphy, dev, request);
3431
3432 if (!err) {
3433 nl80211_send_scan_start(rdev, dev);
3434 dev_hold(dev);
3435 } else {
3436 out_free:
3437 rdev->scan_req = NULL;
3438 kfree(request);
3439 }
3440
3441 return err;
3442}
3443
3444static int nl80211_start_sched_scan(struct sk_buff *skb,
3445 struct genl_info *info)
3446{
3447 struct cfg80211_sched_scan_request *request;
3448 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3449 struct net_device *dev = info->user_ptr[1];
3450 struct nlattr *attr;
3451 struct wiphy *wiphy;
3452 int err, tmp, n_ssids = 0, n_channels, i;
3453 u32 interval;
3454 enum ieee80211_band band;
3455 size_t ie_len;
3456
3457 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3458 !rdev->ops->sched_scan_start)
3459 return -EOPNOTSUPP;
3460
3461 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3462 return -EINVAL;
3463
3464 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
3465 return -EINVAL;
3466
3467 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
3468 if (interval == 0)
3469 return -EINVAL;
3470
3471 wiphy = &rdev->wiphy;
3472
3110 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 3473 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3111 n_channels = validate_scan_freqs( 3474 n_channels = validate_scan_freqs(
3112 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); 3475 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
3113 if (!n_channels) { 3476 if (!n_channels)
3114 err = -EINVAL; 3477 return -EINVAL;
3115 goto out;
3116 }
3117 } else { 3478 } else {
3118 n_channels = 0; 3479 n_channels = 0;
3119 3480
@@ -3123,27 +3484,31 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3123 } 3484 }
3124 3485
3125 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) 3486 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3126 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) 3487 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3488 tmp)
3127 n_ssids++; 3489 n_ssids++;
3128 3490
3129 if (n_ssids > wiphy->max_scan_ssids) { 3491 if (n_ssids > wiphy->max_scan_ssids)
3130 err = -EINVAL; 3492 return -EINVAL;
3131 goto out;
3132 }
3133 3493
3134 if (info->attrs[NL80211_ATTR_IE]) 3494 if (info->attrs[NL80211_ATTR_IE])
3135 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 3495 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3136 else 3496 else
3137 ie_len = 0; 3497 ie_len = 0;
3138 3498
3139 if (ie_len > wiphy->max_scan_ie_len) { 3499 if (ie_len > wiphy->max_scan_ie_len)
3140 err = -EINVAL; 3500 return -EINVAL;
3501
3502 mutex_lock(&rdev->sched_scan_mtx);
3503
3504 if (rdev->sched_scan_req) {
3505 err = -EINPROGRESS;
3141 goto out; 3506 goto out;
3142 } 3507 }
3143 3508
3144 request = kzalloc(sizeof(*request) 3509 request = kzalloc(sizeof(*request)
3145 + sizeof(*ssid) * n_ssids 3510 + sizeof(*request->ssids) * n_ssids
3146 + sizeof(channel) * n_channels 3511 + sizeof(*request->channels) * n_channels
3147 + ie_len, GFP_KERNEL); 3512 + ie_len, GFP_KERNEL);
3148 if (!request) { 3513 if (!request) {
3149 err = -ENOMEM; 3514 err = -ENOMEM;
@@ -3163,7 +3528,9 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3163 i = 0; 3528 i = 0;
3164 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 3529 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3165 /* user specified, bail out if channel not found */ 3530 /* user specified, bail out if channel not found */
3166 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { 3531 nla_for_each_nested(attr,
3532 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
3533 tmp) {
3167 struct ieee80211_channel *chan; 3534 struct ieee80211_channel *chan;
3168 3535
3169 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); 3536 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
@@ -3209,13 +3576,15 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3209 3576
3210 i = 0; 3577 i = 0;
3211 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { 3578 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3212 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { 3579 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3213 if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) { 3580 tmp) {
3581 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
3214 err = -EINVAL; 3582 err = -EINVAL;
3215 goto out_free; 3583 goto out_free;
3216 } 3584 }
3217 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
3218 request->ssids[i].ssid_len = nla_len(attr); 3585 request->ssids[i].ssid_len = nla_len(attr);
3586 memcpy(request->ssids[i].ssid, nla_data(attr),
3587 nla_len(attr));
3219 i++; 3588 i++;
3220 } 3589 }
3221 } 3590 }
@@ -3229,25 +3598,36 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3229 3598
3230 request->dev = dev; 3599 request->dev = dev;
3231 request->wiphy = &rdev->wiphy; 3600 request->wiphy = &rdev->wiphy;
3601 request->interval = interval;
3232 3602
3233 rdev->scan_req = request; 3603 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
3234 err = rdev->ops->scan(&rdev->wiphy, dev, request);
3235
3236 if (!err) { 3604 if (!err) {
3237 nl80211_send_scan_start(rdev, dev); 3605 rdev->sched_scan_req = request;
3238 dev_hold(dev); 3606 nl80211_send_sched_scan(rdev, dev,
3607 NL80211_CMD_START_SCHED_SCAN);
3608 goto out;
3239 } 3609 }
3240 3610
3241 out_free: 3611out_free:
3242 if (err) { 3612 kfree(request);
3243 rdev->scan_req = NULL; 3613out:
3244 kfree(request); 3614 mutex_unlock(&rdev->sched_scan_mtx);
3245 } 3615 return err;
3246 out: 3616}
3247 cfg80211_unlock_rdev(rdev); 3617
3248 dev_put(dev); 3618static int nl80211_stop_sched_scan(struct sk_buff *skb,
3249 out_rtnl: 3619 struct genl_info *info)
3250 rtnl_unlock(); 3620{
3621 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3622 int err;
3623
3624 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3625 !rdev->ops->sched_scan_stop)
3626 return -EOPNOTSUPP;
3627
3628 mutex_lock(&rdev->sched_scan_mtx);
3629 err = __cfg80211_stop_sched_scan(rdev, false);
3630 mutex_unlock(&rdev->sched_scan_mtx);
3251 3631
3252 return err; 3632 return err;
3253} 3633}
@@ -3306,6 +3686,7 @@ static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags,
3306 } 3686 }
3307 3687
3308 switch (wdev->iftype) { 3688 switch (wdev->iftype) {
3689 case NL80211_IFTYPE_P2P_CLIENT:
3309 case NL80211_IFTYPE_STATION: 3690 case NL80211_IFTYPE_STATION:
3310 if (intbss == wdev->current_bss) 3691 if (intbss == wdev->current_bss)
3311 NLA_PUT_U32(msg, NL80211_BSS_STATUS, 3692 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
@@ -3343,25 +3724,12 @@ static int nl80211_dump_scan(struct sk_buff *skb,
3343 struct net_device *dev; 3724 struct net_device *dev;
3344 struct cfg80211_internal_bss *scan; 3725 struct cfg80211_internal_bss *scan;
3345 struct wireless_dev *wdev; 3726 struct wireless_dev *wdev;
3346 int ifidx = cb->args[0];
3347 int start = cb->args[1], idx = 0; 3727 int start = cb->args[1], idx = 0;
3348 int err; 3728 int err;
3349 3729
3350 if (!ifidx) 3730 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
3351 ifidx = nl80211_get_ifidx(cb); 3731 if (err)
3352 if (ifidx < 0) 3732 return err;
3353 return ifidx;
3354 cb->args[0] = ifidx;
3355
3356 dev = dev_get_by_index(sock_net(skb->sk), ifidx);
3357 if (!dev)
3358 return -ENODEV;
3359
3360 rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
3361 if (IS_ERR(rdev)) {
3362 err = PTR_ERR(rdev);
3363 goto out_put_netdev;
3364 }
3365 3733
3366 wdev = dev->ieee80211_ptr; 3734 wdev = dev->ieee80211_ptr;
3367 3735
@@ -3377,21 +3745,17 @@ static int nl80211_dump_scan(struct sk_buff *skb,
3377 cb->nlh->nlmsg_seq, NLM_F_MULTI, 3745 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3378 rdev, wdev, scan) < 0) { 3746 rdev, wdev, scan) < 0) {
3379 idx--; 3747 idx--;
3380 goto out; 3748 break;
3381 } 3749 }
3382 } 3750 }
3383 3751
3384 out:
3385 spin_unlock_bh(&rdev->bss_lock); 3752 spin_unlock_bh(&rdev->bss_lock);
3386 wdev_unlock(wdev); 3753 wdev_unlock(wdev);
3387 3754
3388 cb->args[1] = idx; 3755 cb->args[1] = idx;
3389 err = skb->len; 3756 nl80211_finish_netdev_dump(rdev);
3390 cfg80211_unlock_rdev(rdev);
3391 out_put_netdev:
3392 dev_put(dev);
3393 3757
3394 return err; 3758 return skb->len;
3395} 3759}
3396 3760
3397static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, 3761static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
@@ -3421,6 +3785,23 @@ static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
3421 if (survey->filled & SURVEY_INFO_NOISE_DBM) 3785 if (survey->filled & SURVEY_INFO_NOISE_DBM)
3422 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, 3786 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
3423 survey->noise); 3787 survey->noise);
3788 if (survey->filled & SURVEY_INFO_IN_USE)
3789 NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
3790 if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
3791 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
3792 survey->channel_time);
3793 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
3794 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
3795 survey->channel_time_busy);
3796 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
3797 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
3798 survey->channel_time_ext_busy);
3799 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
3800 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
3801 survey->channel_time_rx);
3802 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
3803 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
3804 survey->channel_time_tx);
3424 3805
3425 nla_nest_end(msg, infoattr); 3806 nla_nest_end(msg, infoattr);
3426 3807
@@ -3437,29 +3818,12 @@ static int nl80211_dump_survey(struct sk_buff *skb,
3437 struct survey_info survey; 3818 struct survey_info survey;
3438 struct cfg80211_registered_device *dev; 3819 struct cfg80211_registered_device *dev;
3439 struct net_device *netdev; 3820 struct net_device *netdev;
3440 int ifidx = cb->args[0];
3441 int survey_idx = cb->args[1]; 3821 int survey_idx = cb->args[1];
3442 int res; 3822 int res;
3443 3823
3444 if (!ifidx) 3824 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3445 ifidx = nl80211_get_ifidx(cb); 3825 if (res)
3446 if (ifidx < 0) 3826 return res;
3447 return ifidx;
3448 cb->args[0] = ifidx;
3449
3450 rtnl_lock();
3451
3452 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
3453 if (!netdev) {
3454 res = -ENODEV;
3455 goto out_rtnl;
3456 }
3457
3458 dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
3459 if (IS_ERR(dev)) {
3460 res = PTR_ERR(dev);
3461 goto out_rtnl;
3462 }
3463 3827
3464 if (!dev->ops->dump_survey) { 3828 if (!dev->ops->dump_survey) {
3465 res = -EOPNOTSUPP; 3829 res = -EOPNOTSUPP;
@@ -3487,10 +3851,7 @@ static int nl80211_dump_survey(struct sk_buff *skb,
3487 cb->args[1] = survey_idx; 3851 cb->args[1] = survey_idx;
3488 res = skb->len; 3852 res = skb->len;
3489 out_err: 3853 out_err:
3490 cfg80211_unlock_rdev(dev); 3854 nl80211_finish_netdev_dump(dev);
3491 out_rtnl:
3492 rtnl_unlock();
3493
3494 return res; 3855 return res;
3495} 3856}
3496 3857
@@ -3523,8 +3884,8 @@ static bool nl80211_valid_cipher_suite(u32 cipher)
3523 3884
3524static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) 3885static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
3525{ 3886{
3526 struct cfg80211_registered_device *rdev; 3887 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3527 struct net_device *dev; 3888 struct net_device *dev = info->user_ptr[1];
3528 struct ieee80211_channel *chan; 3889 struct ieee80211_channel *chan;
3529 const u8 *bssid, *ssid, *ie = NULL; 3890 const u8 *bssid, *ssid, *ie = NULL;
3530 int err, ssid_len, ie_len = 0; 3891 int err, ssid_len, ie_len = 0;
@@ -3552,6 +3913,8 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
3552 return err; 3913 return err;
3553 3914
3554 if (key.idx >= 0) { 3915 if (key.idx >= 0) {
3916 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
3917 return -EINVAL;
3555 if (!key.p.key || !key.p.key_len) 3918 if (!key.p.key || !key.p.key_len)
3556 return -EINVAL; 3919 return -EINVAL;
3557 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || 3920 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
@@ -3566,34 +3929,31 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
3566 key.p.key = NULL; 3929 key.p.key = NULL;
3567 } 3930 }
3568 3931
3569 rtnl_lock(); 3932 if (key.idx >= 0) {
3570 3933 int i;
3571 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); 3934 bool ok = false;
3572 if (err) 3935 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
3573 goto unlock_rtnl; 3936 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
3574 3937 ok = true;
3575 if (!rdev->ops->auth) { 3938 break;
3576 err = -EOPNOTSUPP; 3939 }
3577 goto out; 3940 }
3941 if (!ok)
3942 return -EINVAL;
3578 } 3943 }
3579 3944
3580 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { 3945 if (!rdev->ops->auth)
3581 err = -EOPNOTSUPP; 3946 return -EOPNOTSUPP;
3582 goto out;
3583 }
3584 3947
3585 if (!netif_running(dev)) { 3948 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
3586 err = -ENETDOWN; 3949 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3587 goto out; 3950 return -EOPNOTSUPP;
3588 }
3589 3951
3590 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 3952 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3591 chan = ieee80211_get_channel(&rdev->wiphy, 3953 chan = ieee80211_get_channel(&rdev->wiphy,
3592 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 3954 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3593 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) { 3955 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
3594 err = -EINVAL; 3956 return -EINVAL;
3595 goto out;
3596 }
3597 3957
3598 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 3958 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3599 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 3959 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
@@ -3604,27 +3964,19 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
3604 } 3964 }
3605 3965
3606 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 3966 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
3607 if (!nl80211_valid_auth_type(auth_type)) { 3967 if (!nl80211_valid_auth_type(auth_type))
3608 err = -EINVAL; 3968 return -EINVAL;
3609 goto out;
3610 }
3611 3969
3612 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 3970 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
3613 3971
3614 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, 3972 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
3615 ssid, ssid_len, ie, ie_len, 3973 ssid, ssid_len, ie, ie_len,
3616 key.p.key, key.p.key_len, key.idx, 3974 key.p.key, key.p.key_len, key.idx,
3617 local_state_change); 3975 local_state_change);
3618
3619out:
3620 cfg80211_unlock_rdev(rdev);
3621 dev_put(dev);
3622unlock_rtnl:
3623 rtnl_unlock();
3624 return err;
3625} 3976}
3626 3977
3627static int nl80211_crypto_settings(struct genl_info *info, 3978static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
3979 struct genl_info *info,
3628 struct cfg80211_crypto_settings *settings, 3980 struct cfg80211_crypto_settings *settings,
3629 int cipher_limit) 3981 int cipher_limit)
3630{ 3982{
@@ -3632,6 +3984,19 @@ static int nl80211_crypto_settings(struct genl_info *info,
3632 3984
3633 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; 3985 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
3634 3986
3987 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
3988 u16 proto;
3989 proto = nla_get_u16(
3990 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
3991 settings->control_port_ethertype = cpu_to_be16(proto);
3992 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
3993 proto != ETH_P_PAE)
3994 return -EINVAL;
3995 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
3996 settings->control_port_no_encrypt = true;
3997 } else
3998 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
3999
3635 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { 4000 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
3636 void *data; 4001 void *data;
3637 int len, i; 4002 int len, i;
@@ -3691,8 +4056,8 @@ static int nl80211_crypto_settings(struct genl_info *info,
3691 4056
3692static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) 4057static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
3693{ 4058{
3694 struct cfg80211_registered_device *rdev; 4059 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3695 struct net_device *dev; 4060 struct net_device *dev = info->user_ptr[1];
3696 struct cfg80211_crypto_settings crypto; 4061 struct cfg80211_crypto_settings crypto;
3697 struct ieee80211_channel *chan; 4062 struct ieee80211_channel *chan;
3698 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; 4063 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
@@ -3707,35 +4072,19 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
3707 !info->attrs[NL80211_ATTR_WIPHY_FREQ]) 4072 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
3708 return -EINVAL; 4073 return -EINVAL;
3709 4074
3710 rtnl_lock(); 4075 if (!rdev->ops->assoc)
3711 4076 return -EOPNOTSUPP;
3712 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
3713 if (err)
3714 goto unlock_rtnl;
3715
3716 if (!rdev->ops->assoc) {
3717 err = -EOPNOTSUPP;
3718 goto out;
3719 }
3720
3721 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
3722 err = -EOPNOTSUPP;
3723 goto out;
3724 }
3725 4077
3726 if (!netif_running(dev)) { 4078 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
3727 err = -ENETDOWN; 4079 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3728 goto out; 4080 return -EOPNOTSUPP;
3729 }
3730 4081
3731 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 4082 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3732 4083
3733 chan = ieee80211_get_channel(&rdev->wiphy, 4084 chan = ieee80211_get_channel(&rdev->wiphy,
3734 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 4085 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3735 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) { 4086 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
3736 err = -EINVAL; 4087 return -EINVAL;
3737 goto out;
3738 }
3739 4088
3740 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 4089 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3741 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 4090 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
@@ -3750,35 +4099,28 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
3750 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); 4099 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
3751 if (mfp == NL80211_MFP_REQUIRED) 4100 if (mfp == NL80211_MFP_REQUIRED)
3752 use_mfp = true; 4101 use_mfp = true;
3753 else if (mfp != NL80211_MFP_NO) { 4102 else if (mfp != NL80211_MFP_NO)
3754 err = -EINVAL; 4103 return -EINVAL;
3755 goto out;
3756 }
3757 } 4104 }
3758 4105
3759 if (info->attrs[NL80211_ATTR_PREV_BSSID]) 4106 if (info->attrs[NL80211_ATTR_PREV_BSSID])
3760 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); 4107 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
3761 4108
3762 err = nl80211_crypto_settings(info, &crypto, 1); 4109 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
3763 if (!err) 4110 if (!err)
3764 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, 4111 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
3765 ssid, ssid_len, ie, ie_len, use_mfp, 4112 ssid, ssid_len, ie, ie_len, use_mfp,
3766 &crypto); 4113 &crypto);
3767 4114
3768out:
3769 cfg80211_unlock_rdev(rdev);
3770 dev_put(dev);
3771unlock_rtnl:
3772 rtnl_unlock();
3773 return err; 4115 return err;
3774} 4116}
3775 4117
3776static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) 4118static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
3777{ 4119{
3778 struct cfg80211_registered_device *rdev; 4120 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3779 struct net_device *dev; 4121 struct net_device *dev = info->user_ptr[1];
3780 const u8 *ie = NULL, *bssid; 4122 const u8 *ie = NULL, *bssid;
3781 int err, ie_len = 0; 4123 int ie_len = 0;
3782 u16 reason_code; 4124 u16 reason_code;
3783 bool local_state_change; 4125 bool local_state_change;
3784 4126
@@ -3791,34 +4133,19 @@ static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
3791 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 4133 if (!info->attrs[NL80211_ATTR_REASON_CODE])
3792 return -EINVAL; 4134 return -EINVAL;
3793 4135
3794 rtnl_lock(); 4136 if (!rdev->ops->deauth)
3795 4137 return -EOPNOTSUPP;
3796 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
3797 if (err)
3798 goto unlock_rtnl;
3799
3800 if (!rdev->ops->deauth) {
3801 err = -EOPNOTSUPP;
3802 goto out;
3803 }
3804
3805 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
3806 err = -EOPNOTSUPP;
3807 goto out;
3808 }
3809 4138
3810 if (!netif_running(dev)) { 4139 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
3811 err = -ENETDOWN; 4140 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3812 goto out; 4141 return -EOPNOTSUPP;
3813 }
3814 4142
3815 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 4143 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3816 4144
3817 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 4145 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3818 if (reason_code == 0) { 4146 if (reason_code == 0) {
3819 /* Reason Code 0 is reserved */ 4147 /* Reason Code 0 is reserved */
3820 err = -EINVAL; 4148 return -EINVAL;
3821 goto out;
3822 } 4149 }
3823 4150
3824 if (info->attrs[NL80211_ATTR_IE]) { 4151 if (info->attrs[NL80211_ATTR_IE]) {
@@ -3828,23 +4155,16 @@ static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
3828 4155
3829 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 4156 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
3830 4157
3831 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, 4158 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
3832 local_state_change); 4159 local_state_change);
3833
3834out:
3835 cfg80211_unlock_rdev(rdev);
3836 dev_put(dev);
3837unlock_rtnl:
3838 rtnl_unlock();
3839 return err;
3840} 4160}
3841 4161
3842static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) 4162static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
3843{ 4163{
3844 struct cfg80211_registered_device *rdev; 4164 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3845 struct net_device *dev; 4165 struct net_device *dev = info->user_ptr[1];
3846 const u8 *ie = NULL, *bssid; 4166 const u8 *ie = NULL, *bssid;
3847 int err, ie_len = 0; 4167 int ie_len = 0;
3848 u16 reason_code; 4168 u16 reason_code;
3849 bool local_state_change; 4169 bool local_state_change;
3850 4170
@@ -3857,34 +4177,19 @@ static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
3857 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 4177 if (!info->attrs[NL80211_ATTR_REASON_CODE])
3858 return -EINVAL; 4178 return -EINVAL;
3859 4179
3860 rtnl_lock(); 4180 if (!rdev->ops->disassoc)
3861 4181 return -EOPNOTSUPP;
3862 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
3863 if (err)
3864 goto unlock_rtnl;
3865
3866 if (!rdev->ops->disassoc) {
3867 err = -EOPNOTSUPP;
3868 goto out;
3869 }
3870
3871 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
3872 err = -EOPNOTSUPP;
3873 goto out;
3874 }
3875 4182
3876 if (!netif_running(dev)) { 4183 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
3877 err = -ENETDOWN; 4184 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3878 goto out; 4185 return -EOPNOTSUPP;
3879 }
3880 4186
3881 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 4187 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3882 4188
3883 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 4189 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3884 if (reason_code == 0) { 4190 if (reason_code == 0) {
3885 /* Reason Code 0 is reserved */ 4191 /* Reason Code 0 is reserved */
3886 err = -EINVAL; 4192 return -EINVAL;
3887 goto out;
3888 } 4193 }
3889 4194
3890 if (info->attrs[NL80211_ATTR_IE]) { 4195 if (info->attrs[NL80211_ATTR_IE]) {
@@ -3894,21 +4199,42 @@ static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
3894 4199
3895 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 4200 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
3896 4201
3897 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, 4202 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
3898 local_state_change); 4203 local_state_change);
4204}
3899 4205
3900out: 4206static bool
3901 cfg80211_unlock_rdev(rdev); 4207nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
3902 dev_put(dev); 4208 int mcast_rate[IEEE80211_NUM_BANDS],
3903unlock_rtnl: 4209 int rateval)
3904 rtnl_unlock(); 4210{
3905 return err; 4211 struct wiphy *wiphy = &rdev->wiphy;
4212 bool found = false;
4213 int band, i;
4214
4215 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4216 struct ieee80211_supported_band *sband;
4217
4218 sband = wiphy->bands[band];
4219 if (!sband)
4220 continue;
4221
4222 for (i = 0; i < sband->n_bitrates; i++) {
4223 if (sband->bitrates[i].bitrate == rateval) {
4224 mcast_rate[band] = i + 1;
4225 found = true;
4226 break;
4227 }
4228 }
4229 }
4230
4231 return found;
3906} 4232}
3907 4233
3908static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) 4234static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
3909{ 4235{
3910 struct cfg80211_registered_device *rdev; 4236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3911 struct net_device *dev; 4237 struct net_device *dev = info->user_ptr[1];
3912 struct cfg80211_ibss_params ibss; 4238 struct cfg80211_ibss_params ibss;
3913 struct wiphy *wiphy; 4239 struct wiphy *wiphy;
3914 struct cfg80211_cached_keys *connkeys = NULL; 4240 struct cfg80211_cached_keys *connkeys = NULL;
@@ -3933,26 +4259,11 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
3933 return -EINVAL; 4259 return -EINVAL;
3934 } 4260 }
3935 4261
3936 rtnl_lock(); 4262 if (!rdev->ops->join_ibss)
3937 4263 return -EOPNOTSUPP;
3938 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
3939 if (err)
3940 goto unlock_rtnl;
3941
3942 if (!rdev->ops->join_ibss) {
3943 err = -EOPNOTSUPP;
3944 goto out;
3945 }
3946
3947 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) {
3948 err = -EOPNOTSUPP;
3949 goto out;
3950 }
3951 4264
3952 if (!netif_running(dev)) { 4265 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
3953 err = -ENETDOWN; 4266 return -EOPNOTSUPP;
3954 goto out;
3955 }
3956 4267
3957 wiphy = &rdev->wiphy; 4268 wiphy = &rdev->wiphy;
3958 4269
@@ -3970,24 +4281,12 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
3970 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 4281 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3971 if (!ibss.channel || 4282 if (!ibss.channel ||
3972 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || 4283 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
3973 ibss.channel->flags & IEEE80211_CHAN_DISABLED) { 4284 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
3974 err = -EINVAL; 4285 return -EINVAL;
3975 goto out;
3976 }
3977 4286
3978 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; 4287 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
3979 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; 4288 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3980 4289
3981 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
3982 connkeys = nl80211_parse_connkeys(rdev,
3983 info->attrs[NL80211_ATTR_KEYS]);
3984 if (IS_ERR(connkeys)) {
3985 err = PTR_ERR(connkeys);
3986 connkeys = NULL;
3987 goto out;
3988 }
3989 }
3990
3991 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 4290 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3992 u8 *rates = 4291 u8 *rates =
3993 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 4292 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
@@ -3997,10 +4296,8 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
3997 wiphy->bands[ibss.channel->band]; 4296 wiphy->bands[ibss.channel->band];
3998 int i, j; 4297 int i, j;
3999 4298
4000 if (n_rates == 0) { 4299 if (n_rates == 0)
4001 err = -EINVAL; 4300 return -EINVAL;
4002 goto out;
4003 }
4004 4301
4005 for (i = 0; i < n_rates; i++) { 4302 for (i = 0; i < n_rates; i++) {
4006 int rate = (rates[i] & 0x7f) * 5; 4303 int rate = (rates[i] & 0x7f) * 5;
@@ -4013,77 +4310,41 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
4013 break; 4310 break;
4014 } 4311 }
4015 } 4312 }
4016 if (!found) { 4313 if (!found)
4017 err = -EINVAL; 4314 return -EINVAL;
4018 goto out;
4019 }
4020 }
4021 } else {
4022 /*
4023 * If no rates were explicitly configured,
4024 * use the mandatory rate set for 11b or
4025 * 11a for maximum compatibility.
4026 */
4027 struct ieee80211_supported_band *sband =
4028 wiphy->bands[ibss.channel->band];
4029 int j;
4030 u32 flag = ibss.channel->band == IEEE80211_BAND_5GHZ ?
4031 IEEE80211_RATE_MANDATORY_A :
4032 IEEE80211_RATE_MANDATORY_B;
4033
4034 for (j = 0; j < sband->n_bitrates; j++) {
4035 if (sband->bitrates[j].flags & flag)
4036 ibss.basic_rates |= BIT(j);
4037 } 4315 }
4038 } 4316 }
4039 4317
4040 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); 4318 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
4319 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
4320 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
4321 return -EINVAL;
4041 4322
4042out: 4323 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4043 cfg80211_unlock_rdev(rdev); 4324 connkeys = nl80211_parse_connkeys(rdev,
4044 dev_put(dev); 4325 info->attrs[NL80211_ATTR_KEYS]);
4045unlock_rtnl: 4326 if (IS_ERR(connkeys))
4327 return PTR_ERR(connkeys);
4328 }
4329
4330 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
4046 if (err) 4331 if (err)
4047 kfree(connkeys); 4332 kfree(connkeys);
4048 rtnl_unlock();
4049 return err; 4333 return err;
4050} 4334}
4051 4335
4052static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) 4336static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
4053{ 4337{
4054 struct cfg80211_registered_device *rdev; 4338 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4055 struct net_device *dev; 4339 struct net_device *dev = info->user_ptr[1];
4056 int err;
4057 4340
4058 rtnl_lock(); 4341 if (!rdev->ops->leave_ibss)
4059 4342 return -EOPNOTSUPP;
4060 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4061 if (err)
4062 goto unlock_rtnl;
4063
4064 if (!rdev->ops->leave_ibss) {
4065 err = -EOPNOTSUPP;
4066 goto out;
4067 }
4068
4069 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) {
4070 err = -EOPNOTSUPP;
4071 goto out;
4072 }
4073
4074 if (!netif_running(dev)) {
4075 err = -ENETDOWN;
4076 goto out;
4077 }
4078 4343
4079 err = cfg80211_leave_ibss(rdev, dev, false); 4344 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4345 return -EOPNOTSUPP;
4080 4346
4081out: 4347 return cfg80211_leave_ibss(rdev, dev, false);
4082 cfg80211_unlock_rdev(rdev);
4083 dev_put(dev);
4084unlock_rtnl:
4085 rtnl_unlock();
4086 return err;
4087} 4348}
4088 4349
4089#ifdef CONFIG_NL80211_TESTMODE 4350#ifdef CONFIG_NL80211_TESTMODE
@@ -4093,20 +4354,12 @@ static struct genl_multicast_group nl80211_testmode_mcgrp = {
4093 4354
4094static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) 4355static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
4095{ 4356{
4096 struct cfg80211_registered_device *rdev; 4357 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4097 int err; 4358 int err;
4098 4359
4099 if (!info->attrs[NL80211_ATTR_TESTDATA]) 4360 if (!info->attrs[NL80211_ATTR_TESTDATA])
4100 return -EINVAL; 4361 return -EINVAL;
4101 4362
4102 rtnl_lock();
4103
4104 rdev = cfg80211_get_dev_from_info(info);
4105 if (IS_ERR(rdev)) {
4106 err = PTR_ERR(rdev);
4107 goto unlock_rtnl;
4108 }
4109
4110 err = -EOPNOTSUPP; 4363 err = -EOPNOTSUPP;
4111 if (rdev->ops->testmode_cmd) { 4364 if (rdev->ops->testmode_cmd) {
4112 rdev->testmode_info = info; 4365 rdev->testmode_info = info;
@@ -4116,10 +4369,6 @@ static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
4116 rdev->testmode_info = NULL; 4369 rdev->testmode_info = NULL;
4117 } 4370 }
4118 4371
4119 cfg80211_unlock_rdev(rdev);
4120
4121 unlock_rtnl:
4122 rtnl_unlock();
4123 return err; 4372 return err;
4124} 4373}
4125 4374
@@ -4210,8 +4459,8 @@ EXPORT_SYMBOL(cfg80211_testmode_event);
4210 4459
4211static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) 4460static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
4212{ 4461{
4213 struct cfg80211_registered_device *rdev; 4462 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4214 struct net_device *dev; 4463 struct net_device *dev = info->user_ptr[1];
4215 struct cfg80211_connect_params connect; 4464 struct cfg80211_connect_params connect;
4216 struct wiphy *wiphy; 4465 struct wiphy *wiphy;
4217 struct cfg80211_cached_keys *connkeys = NULL; 4466 struct cfg80211_cached_keys *connkeys = NULL;
@@ -4236,25 +4485,14 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
4236 4485
4237 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; 4486 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
4238 4487
4239 err = nl80211_crypto_settings(info, &connect.crypto, 4488 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
4240 NL80211_MAX_NR_CIPHER_SUITES); 4489 NL80211_MAX_NR_CIPHER_SUITES);
4241 if (err) 4490 if (err)
4242 return err; 4491 return err;
4243 rtnl_lock();
4244
4245 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4246 if (err)
4247 goto unlock_rtnl;
4248
4249 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
4250 err = -EOPNOTSUPP;
4251 goto out;
4252 }
4253 4492
4254 if (!netif_running(dev)) { 4493 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
4255 err = -ENETDOWN; 4494 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4256 goto out; 4495 return -EOPNOTSUPP;
4257 }
4258 4496
4259 wiphy = &rdev->wiphy; 4497 wiphy = &rdev->wiphy;
4260 4498
@@ -4273,39 +4511,27 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
4273 ieee80211_get_channel(wiphy, 4511 ieee80211_get_channel(wiphy,
4274 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 4512 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4275 if (!connect.channel || 4513 if (!connect.channel ||
4276 connect.channel->flags & IEEE80211_CHAN_DISABLED) { 4514 connect.channel->flags & IEEE80211_CHAN_DISABLED)
4277 err = -EINVAL; 4515 return -EINVAL;
4278 goto out;
4279 }
4280 } 4516 }
4281 4517
4282 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { 4518 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4283 connkeys = nl80211_parse_connkeys(rdev, 4519 connkeys = nl80211_parse_connkeys(rdev,
4284 info->attrs[NL80211_ATTR_KEYS]); 4520 info->attrs[NL80211_ATTR_KEYS]);
4285 if (IS_ERR(connkeys)) { 4521 if (IS_ERR(connkeys))
4286 err = PTR_ERR(connkeys); 4522 return PTR_ERR(connkeys);
4287 connkeys = NULL;
4288 goto out;
4289 }
4290 } 4523 }
4291 4524
4292 err = cfg80211_connect(rdev, dev, &connect, connkeys); 4525 err = cfg80211_connect(rdev, dev, &connect, connkeys);
4293
4294out:
4295 cfg80211_unlock_rdev(rdev);
4296 dev_put(dev);
4297unlock_rtnl:
4298 if (err) 4526 if (err)
4299 kfree(connkeys); 4527 kfree(connkeys);
4300 rtnl_unlock();
4301 return err; 4528 return err;
4302} 4529}
4303 4530
4304static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) 4531static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
4305{ 4532{
4306 struct cfg80211_registered_device *rdev; 4533 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4307 struct net_device *dev; 4534 struct net_device *dev = info->user_ptr[1];
4308 int err;
4309 u16 reason; 4535 u16 reason;
4310 4536
4311 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 4537 if (!info->attrs[NL80211_ATTR_REASON_CODE])
@@ -4316,35 +4542,16 @@ static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
4316 if (reason == 0) 4542 if (reason == 0)
4317 return -EINVAL; 4543 return -EINVAL;
4318 4544
4319 rtnl_lock(); 4545 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
4320 4546 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4321 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); 4547 return -EOPNOTSUPP;
4322 if (err)
4323 goto unlock_rtnl;
4324
4325 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
4326 err = -EOPNOTSUPP;
4327 goto out;
4328 }
4329
4330 if (!netif_running(dev)) {
4331 err = -ENETDOWN;
4332 goto out;
4333 }
4334
4335 err = cfg80211_disconnect(rdev, dev, reason, true);
4336 4548
4337out: 4549 return cfg80211_disconnect(rdev, dev, reason, true);
4338 cfg80211_unlock_rdev(rdev);
4339 dev_put(dev);
4340unlock_rtnl:
4341 rtnl_unlock();
4342 return err;
4343} 4550}
4344 4551
4345static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) 4552static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
4346{ 4553{
4347 struct cfg80211_registered_device *rdev; 4554 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4348 struct net *net; 4555 struct net *net;
4349 int err; 4556 int err;
4350 u32 pid; 4557 u32 pid;
@@ -4354,43 +4561,26 @@ static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
4354 4561
4355 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); 4562 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
4356 4563
4357 rtnl_lock();
4358
4359 rdev = cfg80211_get_dev_from_info(info);
4360 if (IS_ERR(rdev)) {
4361 err = PTR_ERR(rdev);
4362 goto out_rtnl;
4363 }
4364
4365 net = get_net_ns_by_pid(pid); 4564 net = get_net_ns_by_pid(pid);
4366 if (IS_ERR(net)) { 4565 if (IS_ERR(net))
4367 err = PTR_ERR(net); 4566 return PTR_ERR(net);
4368 goto out;
4369 }
4370 4567
4371 err = 0; 4568 err = 0;
4372 4569
4373 /* check if anything to do */ 4570 /* check if anything to do */
4374 if (net_eq(wiphy_net(&rdev->wiphy), net)) 4571 if (!net_eq(wiphy_net(&rdev->wiphy), net))
4375 goto out_put_net; 4572 err = cfg80211_switch_netns(rdev, net);
4376 4573
4377 err = cfg80211_switch_netns(rdev, net);
4378 out_put_net:
4379 put_net(net); 4574 put_net(net);
4380 out:
4381 cfg80211_unlock_rdev(rdev);
4382 out_rtnl:
4383 rtnl_unlock();
4384 return err; 4575 return err;
4385} 4576}
4386 4577
4387static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) 4578static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
4388{ 4579{
4389 struct cfg80211_registered_device *rdev; 4580 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4390 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, 4581 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
4391 struct cfg80211_pmksa *pmksa) = NULL; 4582 struct cfg80211_pmksa *pmksa) = NULL;
4392 int err; 4583 struct net_device *dev = info->user_ptr[1];
4393 struct net_device *dev;
4394 struct cfg80211_pmksa pmksa; 4584 struct cfg80211_pmksa pmksa;
4395 4585
4396 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); 4586 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
@@ -4401,19 +4591,12 @@ static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
4401 if (!info->attrs[NL80211_ATTR_PMKID]) 4591 if (!info->attrs[NL80211_ATTR_PMKID])
4402 return -EINVAL; 4592 return -EINVAL;
4403 4593
4404 rtnl_lock();
4405
4406 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4407 if (err)
4408 goto out_rtnl;
4409
4410 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); 4594 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
4411 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 4595 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4412 4596
4413 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { 4597 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
4414 err = -EOPNOTSUPP; 4598 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4415 goto out; 4599 return -EOPNOTSUPP;
4416 }
4417 4600
4418 switch (info->genlhdr->cmd) { 4601 switch (info->genlhdr->cmd) {
4419 case NL80211_CMD_SET_PMKSA: 4602 case NL80211_CMD_SET_PMKSA:
@@ -4427,61 +4610,32 @@ static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
4427 break; 4610 break;
4428 } 4611 }
4429 4612
4430 if (!rdev_ops) { 4613 if (!rdev_ops)
4431 err = -EOPNOTSUPP; 4614 return -EOPNOTSUPP;
4432 goto out;
4433 }
4434
4435 err = rdev_ops(&rdev->wiphy, dev, &pmksa);
4436
4437 out:
4438 cfg80211_unlock_rdev(rdev);
4439 dev_put(dev);
4440 out_rtnl:
4441 rtnl_unlock();
4442 4615
4443 return err; 4616 return rdev_ops(&rdev->wiphy, dev, &pmksa);
4444} 4617}
4445 4618
4446static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) 4619static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
4447{ 4620{
4448 struct cfg80211_registered_device *rdev; 4621 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4449 int err; 4622 struct net_device *dev = info->user_ptr[1];
4450 struct net_device *dev;
4451
4452 rtnl_lock();
4453
4454 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4455 if (err)
4456 goto out_rtnl;
4457
4458 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
4459 err = -EOPNOTSUPP;
4460 goto out;
4461 }
4462
4463 if (!rdev->ops->flush_pmksa) {
4464 err = -EOPNOTSUPP;
4465 goto out;
4466 }
4467
4468 err = rdev->ops->flush_pmksa(&rdev->wiphy, dev);
4469 4623
4470 out: 4624 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
4471 cfg80211_unlock_rdev(rdev); 4625 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4472 dev_put(dev); 4626 return -EOPNOTSUPP;
4473 out_rtnl:
4474 rtnl_unlock();
4475 4627
4476 return err; 4628 if (!rdev->ops->flush_pmksa)
4629 return -EOPNOTSUPP;
4477 4630
4631 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
4478} 4632}
4479 4633
4480static int nl80211_remain_on_channel(struct sk_buff *skb, 4634static int nl80211_remain_on_channel(struct sk_buff *skb,
4481 struct genl_info *info) 4635 struct genl_info *info)
4482{ 4636{
4483 struct cfg80211_registered_device *rdev; 4637 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4484 struct net_device *dev; 4638 struct net_device *dev = info->user_ptr[1];
4485 struct ieee80211_channel *chan; 4639 struct ieee80211_channel *chan;
4486 struct sk_buff *msg; 4640 struct sk_buff *msg;
4487 void *hdr; 4641 void *hdr;
@@ -4500,24 +4654,12 @@ static int nl80211_remain_on_channel(struct sk_buff *skb,
4500 * We should be on that channel for at least one jiffie, 4654 * We should be on that channel for at least one jiffie,
4501 * and more than 5 seconds seems excessive. 4655 * and more than 5 seconds seems excessive.
4502 */ 4656 */
4503 if (!duration || !msecs_to_jiffies(duration) || duration > 5000) 4657 if (!duration || !msecs_to_jiffies(duration) ||
4658 duration > rdev->wiphy.max_remain_on_channel_duration)
4504 return -EINVAL; 4659 return -EINVAL;
4505 4660
4506 rtnl_lock(); 4661 if (!rdev->ops->remain_on_channel)
4507 4662 return -EOPNOTSUPP;
4508 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4509 if (err)
4510 goto unlock_rtnl;
4511
4512 if (!rdev->ops->remain_on_channel) {
4513 err = -EOPNOTSUPP;
4514 goto out;
4515 }
4516
4517 if (!netif_running(dev)) {
4518 err = -ENETDOWN;
4519 goto out;
4520 }
4521 4663
4522 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { 4664 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4523 channel_type = nla_get_u32( 4665 channel_type = nla_get_u32(
@@ -4525,24 +4667,18 @@ static int nl80211_remain_on_channel(struct sk_buff *skb,
4525 if (channel_type != NL80211_CHAN_NO_HT && 4667 if (channel_type != NL80211_CHAN_NO_HT &&
4526 channel_type != NL80211_CHAN_HT20 && 4668 channel_type != NL80211_CHAN_HT20 &&
4527 channel_type != NL80211_CHAN_HT40PLUS && 4669 channel_type != NL80211_CHAN_HT40PLUS &&
4528 channel_type != NL80211_CHAN_HT40MINUS) { 4670 channel_type != NL80211_CHAN_HT40MINUS)
4529 err = -EINVAL; 4671 return -EINVAL;
4530 goto out;
4531 }
4532 } 4672 }
4533 4673
4534 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); 4674 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
4535 chan = rdev_freq_to_chan(rdev, freq, channel_type); 4675 chan = rdev_freq_to_chan(rdev, freq, channel_type);
4536 if (chan == NULL) { 4676 if (chan == NULL)
4537 err = -EINVAL; 4677 return -EINVAL;
4538 goto out;
4539 }
4540 4678
4541 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 4679 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4542 if (!msg) { 4680 if (!msg)
4543 err = -ENOMEM; 4681 return -ENOMEM;
4544 goto out;
4545 }
4546 4682
4547 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, 4683 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
4548 NL80211_CMD_REMAIN_ON_CHANNEL); 4684 NL80211_CMD_REMAIN_ON_CHANNEL);
@@ -4561,58 +4697,32 @@ static int nl80211_remain_on_channel(struct sk_buff *skb,
4561 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); 4697 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
4562 4698
4563 genlmsg_end(msg, hdr); 4699 genlmsg_end(msg, hdr);
4564 err = genlmsg_reply(msg, info); 4700
4565 goto out; 4701 return genlmsg_reply(msg, info);
4566 4702
4567 nla_put_failure: 4703 nla_put_failure:
4568 err = -ENOBUFS; 4704 err = -ENOBUFS;
4569 free_msg: 4705 free_msg:
4570 nlmsg_free(msg); 4706 nlmsg_free(msg);
4571 out:
4572 cfg80211_unlock_rdev(rdev);
4573 dev_put(dev);
4574 unlock_rtnl:
4575 rtnl_unlock();
4576 return err; 4707 return err;
4577} 4708}
4578 4709
4579static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, 4710static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
4580 struct genl_info *info) 4711 struct genl_info *info)
4581{ 4712{
4582 struct cfg80211_registered_device *rdev; 4713 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4583 struct net_device *dev; 4714 struct net_device *dev = info->user_ptr[1];
4584 u64 cookie; 4715 u64 cookie;
4585 int err;
4586 4716
4587 if (!info->attrs[NL80211_ATTR_COOKIE]) 4717 if (!info->attrs[NL80211_ATTR_COOKIE])
4588 return -EINVAL; 4718 return -EINVAL;
4589 4719
4590 rtnl_lock(); 4720 if (!rdev->ops->cancel_remain_on_channel)
4591 4721 return -EOPNOTSUPP;
4592 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4593 if (err)
4594 goto unlock_rtnl;
4595
4596 if (!rdev->ops->cancel_remain_on_channel) {
4597 err = -EOPNOTSUPP;
4598 goto out;
4599 }
4600
4601 if (!netif_running(dev)) {
4602 err = -ENETDOWN;
4603 goto out;
4604 }
4605 4722
4606 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 4723 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
4607 4724
4608 err = rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); 4725 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
4609
4610 out:
4611 cfg80211_unlock_rdev(rdev);
4612 dev_put(dev);
4613 unlock_rtnl:
4614 rtnl_unlock();
4615 return err;
4616} 4726}
4617 4727
4618static u32 rateset_to_mask(struct ieee80211_supported_band *sband, 4728static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
@@ -4648,26 +4758,18 @@ static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
4648 struct genl_info *info) 4758 struct genl_info *info)
4649{ 4759{
4650 struct nlattr *tb[NL80211_TXRATE_MAX + 1]; 4760 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
4651 struct cfg80211_registered_device *rdev; 4761 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4652 struct cfg80211_bitrate_mask mask; 4762 struct cfg80211_bitrate_mask mask;
4653 int err, rem, i; 4763 int rem, i;
4654 struct net_device *dev; 4764 struct net_device *dev = info->user_ptr[1];
4655 struct nlattr *tx_rates; 4765 struct nlattr *tx_rates;
4656 struct ieee80211_supported_band *sband; 4766 struct ieee80211_supported_band *sband;
4657 4767
4658 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) 4768 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
4659 return -EINVAL; 4769 return -EINVAL;
4660 4770
4661 rtnl_lock(); 4771 if (!rdev->ops->set_bitrate_mask)
4662 4772 return -EOPNOTSUPP;
4663 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4664 if (err)
4665 goto unlock_rtnl;
4666
4667 if (!rdev->ops->set_bitrate_mask) {
4668 err = -EOPNOTSUPP;
4669 goto unlock;
4670 }
4671 4773
4672 memset(&mask, 0, sizeof(mask)); 4774 memset(&mask, 0, sizeof(mask));
4673 /* Default to all rates enabled */ 4775 /* Default to all rates enabled */
@@ -4684,15 +4786,11 @@ static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
4684 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) 4786 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
4685 { 4787 {
4686 enum ieee80211_band band = nla_type(tx_rates); 4788 enum ieee80211_band band = nla_type(tx_rates);
4687 if (band < 0 || band >= IEEE80211_NUM_BANDS) { 4789 if (band < 0 || band >= IEEE80211_NUM_BANDS)
4688 err = -EINVAL; 4790 return -EINVAL;
4689 goto unlock;
4690 }
4691 sband = rdev->wiphy.bands[band]; 4791 sband = rdev->wiphy.bands[band];
4692 if (sband == NULL) { 4792 if (sband == NULL)
4693 err = -EINVAL; 4793 return -EINVAL;
4694 goto unlock;
4695 }
4696 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), 4794 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
4697 nla_len(tx_rates), nl80211_txattr_policy); 4795 nla_len(tx_rates), nl80211_txattr_policy);
4698 if (tb[NL80211_TXRATE_LEGACY]) { 4796 if (tb[NL80211_TXRATE_LEGACY]) {
@@ -4700,68 +4798,49 @@ static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
4700 sband, 4798 sband,
4701 nla_data(tb[NL80211_TXRATE_LEGACY]), 4799 nla_data(tb[NL80211_TXRATE_LEGACY]),
4702 nla_len(tb[NL80211_TXRATE_LEGACY])); 4800 nla_len(tb[NL80211_TXRATE_LEGACY]));
4703 if (mask.control[band].legacy == 0) { 4801 if (mask.control[band].legacy == 0)
4704 err = -EINVAL; 4802 return -EINVAL;
4705 goto unlock;
4706 }
4707 } 4803 }
4708 } 4804 }
4709 4805
4710 err = rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); 4806 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
4711
4712 unlock:
4713 dev_put(dev);
4714 cfg80211_unlock_rdev(rdev);
4715 unlock_rtnl:
4716 rtnl_unlock();
4717 return err;
4718} 4807}
4719 4808
4720static int nl80211_register_action(struct sk_buff *skb, struct genl_info *info) 4809static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
4721{ 4810{
4722 struct cfg80211_registered_device *rdev; 4811 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4723 struct net_device *dev; 4812 struct net_device *dev = info->user_ptr[1];
4724 int err; 4813 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
4725 4814
4726 if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) 4815 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
4727 return -EINVAL; 4816 return -EINVAL;
4728 4817
4729 if (nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]) < 1) 4818 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
4730 return -EINVAL; 4819 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
4731
4732 rtnl_lock();
4733
4734 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4735 if (err)
4736 goto unlock_rtnl;
4737 4820
4738 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 4821 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
4739 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { 4822 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
4740 err = -EOPNOTSUPP; 4823 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
4741 goto out; 4824 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4742 } 4825 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4826 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
4827 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4828 return -EOPNOTSUPP;
4743 4829
4744 /* not much point in registering if we can't reply */ 4830 /* not much point in registering if we can't reply */
4745 if (!rdev->ops->action) { 4831 if (!rdev->ops->mgmt_tx)
4746 err = -EOPNOTSUPP; 4832 return -EOPNOTSUPP;
4747 goto out;
4748 }
4749 4833
4750 err = cfg80211_mlme_register_action(dev->ieee80211_ptr, info->snd_pid, 4834 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
4835 frame_type,
4751 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), 4836 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
4752 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); 4837 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
4753 out:
4754 cfg80211_unlock_rdev(rdev);
4755 dev_put(dev);
4756 unlock_rtnl:
4757 rtnl_unlock();
4758 return err;
4759} 4838}
4760 4839
4761static int nl80211_action(struct sk_buff *skb, struct genl_info *info) 4840static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
4762{ 4841{
4763 struct cfg80211_registered_device *rdev; 4842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4764 struct net_device *dev; 4843 struct net_device *dev = info->user_ptr[1];
4765 struct ieee80211_channel *chan; 4844 struct ieee80211_channel *chan;
4766 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; 4845 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
4767 bool channel_type_valid = false; 4846 bool channel_type_valid = false;
@@ -4770,31 +4849,29 @@ static int nl80211_action(struct sk_buff *skb, struct genl_info *info)
4770 void *hdr; 4849 void *hdr;
4771 u64 cookie; 4850 u64 cookie;
4772 struct sk_buff *msg; 4851 struct sk_buff *msg;
4852 unsigned int wait = 0;
4853 bool offchan;
4773 4854
4774 if (!info->attrs[NL80211_ATTR_FRAME] || 4855 if (!info->attrs[NL80211_ATTR_FRAME] ||
4775 !info->attrs[NL80211_ATTR_WIPHY_FREQ]) 4856 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
4776 return -EINVAL; 4857 return -EINVAL;
4777 4858
4778 rtnl_lock(); 4859 if (!rdev->ops->mgmt_tx)
4779 4860 return -EOPNOTSUPP;
4780 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4781 if (err)
4782 goto unlock_rtnl;
4783
4784 if (!rdev->ops->action) {
4785 err = -EOPNOTSUPP;
4786 goto out;
4787 }
4788 4861
4789 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 4862 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
4790 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { 4863 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
4791 err = -EOPNOTSUPP; 4864 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
4792 goto out; 4865 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4793 } 4866 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4867 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
4868 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4869 return -EOPNOTSUPP;
4794 4870
4795 if (!netif_running(dev)) { 4871 if (info->attrs[NL80211_ATTR_DURATION]) {
4796 err = -ENETDOWN; 4872 if (!rdev->ops->mgmt_tx_cancel_wait)
4797 goto out; 4873 return -EINVAL;
4874 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
4798 } 4875 }
4799 4876
4800 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { 4877 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
@@ -4803,147 +4880,131 @@ static int nl80211_action(struct sk_buff *skb, struct genl_info *info)
4803 if (channel_type != NL80211_CHAN_NO_HT && 4880 if (channel_type != NL80211_CHAN_NO_HT &&
4804 channel_type != NL80211_CHAN_HT20 && 4881 channel_type != NL80211_CHAN_HT20 &&
4805 channel_type != NL80211_CHAN_HT40PLUS && 4882 channel_type != NL80211_CHAN_HT40PLUS &&
4806 channel_type != NL80211_CHAN_HT40MINUS) { 4883 channel_type != NL80211_CHAN_HT40MINUS)
4807 err = -EINVAL; 4884 return -EINVAL;
4808 goto out;
4809 }
4810 channel_type_valid = true; 4885 channel_type_valid = true;
4811 } 4886 }
4812 4887
4888 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
4889
4813 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); 4890 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
4814 chan = rdev_freq_to_chan(rdev, freq, channel_type); 4891 chan = rdev_freq_to_chan(rdev, freq, channel_type);
4815 if (chan == NULL) { 4892 if (chan == NULL)
4816 err = -EINVAL; 4893 return -EINVAL;
4817 goto out;
4818 }
4819 4894
4820 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 4895 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4821 if (!msg) { 4896 if (!msg)
4822 err = -ENOMEM; 4897 return -ENOMEM;
4823 goto out;
4824 }
4825 4898
4826 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, 4899 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
4827 NL80211_CMD_ACTION); 4900 NL80211_CMD_FRAME);
4828 4901
4829 if (IS_ERR(hdr)) { 4902 if (IS_ERR(hdr)) {
4830 err = PTR_ERR(hdr); 4903 err = PTR_ERR(hdr);
4831 goto free_msg; 4904 goto free_msg;
4832 } 4905 }
4833 err = cfg80211_mlme_action(rdev, dev, chan, channel_type, 4906 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
4834 channel_type_valid, 4907 channel_type_valid, wait,
4835 nla_data(info->attrs[NL80211_ATTR_FRAME]), 4908 nla_data(info->attrs[NL80211_ATTR_FRAME]),
4836 nla_len(info->attrs[NL80211_ATTR_FRAME]), 4909 nla_len(info->attrs[NL80211_ATTR_FRAME]),
4837 &cookie); 4910 &cookie);
4838 if (err) 4911 if (err)
4839 goto free_msg; 4912 goto free_msg;
4840 4913
4841 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); 4914 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
4842 4915
4843 genlmsg_end(msg, hdr); 4916 genlmsg_end(msg, hdr);
4844 err = genlmsg_reply(msg, info); 4917 return genlmsg_reply(msg, info);
4845 goto out;
4846 4918
4847 nla_put_failure: 4919 nla_put_failure:
4848 err = -ENOBUFS; 4920 err = -ENOBUFS;
4849 free_msg: 4921 free_msg:
4850 nlmsg_free(msg); 4922 nlmsg_free(msg);
4851 out:
4852 cfg80211_unlock_rdev(rdev);
4853 dev_put(dev);
4854unlock_rtnl:
4855 rtnl_unlock();
4856 return err; 4923 return err;
4857} 4924}
4858 4925
4926static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
4927{
4928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4929 struct net_device *dev = info->user_ptr[1];
4930 u64 cookie;
4931
4932 if (!info->attrs[NL80211_ATTR_COOKIE])
4933 return -EINVAL;
4934
4935 if (!rdev->ops->mgmt_tx_cancel_wait)
4936 return -EOPNOTSUPP;
4937
4938 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
4939 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
4940 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
4941 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4942 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4943 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4944 return -EOPNOTSUPP;
4945
4946 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
4947
4948 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
4949}
4950
4859static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) 4951static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
4860{ 4952{
4861 struct cfg80211_registered_device *rdev; 4953 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4862 struct wireless_dev *wdev; 4954 struct wireless_dev *wdev;
4863 struct net_device *dev; 4955 struct net_device *dev = info->user_ptr[1];
4864 u8 ps_state; 4956 u8 ps_state;
4865 bool state; 4957 bool state;
4866 int err; 4958 int err;
4867 4959
4868 if (!info->attrs[NL80211_ATTR_PS_STATE]) { 4960 if (!info->attrs[NL80211_ATTR_PS_STATE])
4869 err = -EINVAL; 4961 return -EINVAL;
4870 goto out;
4871 }
4872 4962
4873 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); 4963 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
4874 4964
4875 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) { 4965 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
4876 err = -EINVAL; 4966 return -EINVAL;
4877 goto out;
4878 }
4879
4880 rtnl_lock();
4881
4882 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4883 if (err)
4884 goto unlock_rdev;
4885 4967
4886 wdev = dev->ieee80211_ptr; 4968 wdev = dev->ieee80211_ptr;
4887 4969
4888 if (!rdev->ops->set_power_mgmt) { 4970 if (!rdev->ops->set_power_mgmt)
4889 err = -EOPNOTSUPP; 4971 return -EOPNOTSUPP;
4890 goto unlock_rdev;
4891 }
4892 4972
4893 state = (ps_state == NL80211_PS_ENABLED) ? true : false; 4973 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
4894 4974
4895 if (state == wdev->ps) 4975 if (state == wdev->ps)
4896 goto unlock_rdev; 4976 return 0;
4897
4898 wdev->ps = state;
4899
4900 if (rdev->ops->set_power_mgmt(wdev->wiphy, dev, wdev->ps,
4901 wdev->ps_timeout))
4902 /* assume this means it's off */
4903 wdev->ps = false;
4904
4905unlock_rdev:
4906 cfg80211_unlock_rdev(rdev);
4907 dev_put(dev);
4908 rtnl_unlock();
4909 4977
4910out: 4978 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
4979 wdev->ps_timeout);
4980 if (!err)
4981 wdev->ps = state;
4911 return err; 4982 return err;
4912} 4983}
4913 4984
4914static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) 4985static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
4915{ 4986{
4916 struct cfg80211_registered_device *rdev; 4987 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4917 enum nl80211_ps_state ps_state; 4988 enum nl80211_ps_state ps_state;
4918 struct wireless_dev *wdev; 4989 struct wireless_dev *wdev;
4919 struct net_device *dev; 4990 struct net_device *dev = info->user_ptr[1];
4920 struct sk_buff *msg; 4991 struct sk_buff *msg;
4921 void *hdr; 4992 void *hdr;
4922 int err; 4993 int err;
4923 4994
4924 rtnl_lock();
4925
4926 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4927 if (err)
4928 goto unlock_rtnl;
4929
4930 wdev = dev->ieee80211_ptr; 4995 wdev = dev->ieee80211_ptr;
4931 4996
4932 if (!rdev->ops->set_power_mgmt) { 4997 if (!rdev->ops->set_power_mgmt)
4933 err = -EOPNOTSUPP; 4998 return -EOPNOTSUPP;
4934 goto out;
4935 }
4936 4999
4937 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 5000 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4938 if (!msg) { 5001 if (!msg)
4939 err = -ENOMEM; 5002 return -ENOMEM;
4940 goto out;
4941 }
4942 5003
4943 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, 5004 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
4944 NL80211_CMD_GET_POWER_SAVE); 5005 NL80211_CMD_GET_POWER_SAVE);
4945 if (!hdr) { 5006 if (!hdr) {
4946 err = -ENOMEM; 5007 err = -ENOBUFS;
4947 goto free_msg; 5008 goto free_msg;
4948 } 5009 }
4949 5010
@@ -4955,22 +5016,12 @@ static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
4955 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); 5016 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
4956 5017
4957 genlmsg_end(msg, hdr); 5018 genlmsg_end(msg, hdr);
4958 err = genlmsg_reply(msg, info); 5019 return genlmsg_reply(msg, info);
4959 goto out;
4960 5020
4961nla_put_failure: 5021 nla_put_failure:
4962 err = -ENOBUFS; 5022 err = -ENOBUFS;
4963 5023 free_msg:
4964free_msg:
4965 nlmsg_free(msg); 5024 nlmsg_free(msg);
4966
4967out:
4968 cfg80211_unlock_rdev(rdev);
4969 dev_put(dev);
4970
4971unlock_rtnl:
4972 rtnl_unlock();
4973
4974 return err; 5025 return err;
4975} 5026}
4976 5027
@@ -4984,41 +5035,24 @@ nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
4984static int nl80211_set_cqm_rssi(struct genl_info *info, 5035static int nl80211_set_cqm_rssi(struct genl_info *info,
4985 s32 threshold, u32 hysteresis) 5036 s32 threshold, u32 hysteresis)
4986{ 5037{
4987 struct cfg80211_registered_device *rdev; 5038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4988 struct wireless_dev *wdev; 5039 struct wireless_dev *wdev;
4989 struct net_device *dev; 5040 struct net_device *dev = info->user_ptr[1];
4990 int err;
4991 5041
4992 if (threshold > 0) 5042 if (threshold > 0)
4993 return -EINVAL; 5043 return -EINVAL;
4994 5044
4995 rtnl_lock();
4996
4997 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4998 if (err)
4999 goto unlock_rdev;
5000
5001 wdev = dev->ieee80211_ptr; 5045 wdev = dev->ieee80211_ptr;
5002 5046
5003 if (!rdev->ops->set_cqm_rssi_config) { 5047 if (!rdev->ops->set_cqm_rssi_config)
5004 err = -EOPNOTSUPP; 5048 return -EOPNOTSUPP;
5005 goto unlock_rdev;
5006 }
5007
5008 if (wdev->iftype != NL80211_IFTYPE_STATION) {
5009 err = -EOPNOTSUPP;
5010 goto unlock_rdev;
5011 }
5012
5013 err = rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
5014 threshold, hysteresis);
5015 5049
5016unlock_rdev: 5050 if (wdev->iftype != NL80211_IFTYPE_STATION &&
5017 cfg80211_unlock_rdev(rdev); 5051 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
5018 dev_put(dev); 5052 return -EOPNOTSUPP;
5019 rtnl_unlock();
5020 5053
5021 return err; 5054 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
5055 threshold, hysteresis);
5022} 5056}
5023 5057
5024static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) 5058static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
@@ -5052,6 +5086,297 @@ out:
5052 return err; 5086 return err;
5053} 5087}
5054 5088
5089static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
5090{
5091 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5092 struct net_device *dev = info->user_ptr[1];
5093 struct mesh_config cfg;
5094 struct mesh_setup setup;
5095 int err;
5096
5097 /* start with default */
5098 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
5099 memcpy(&setup, &default_mesh_setup, sizeof(setup));
5100
5101 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
5102 /* and parse parameters if given */
5103 err = nl80211_parse_mesh_config(info, &cfg, NULL);
5104 if (err)
5105 return err;
5106 }
5107
5108 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
5109 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
5110 return -EINVAL;
5111
5112 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
5113 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
5114
5115 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
5116 /* parse additional setup parameters if given */
5117 err = nl80211_parse_mesh_setup(info, &setup);
5118 if (err)
5119 return err;
5120 }
5121
5122 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
5123}
5124
5125static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
5126{
5127 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5128 struct net_device *dev = info->user_ptr[1];
5129
5130 return cfg80211_leave_mesh(rdev, dev);
5131}
5132
5133static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
5134{
5135 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5136 struct sk_buff *msg;
5137 void *hdr;
5138
5139 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5140 return -EOPNOTSUPP;
5141
5142 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5143 if (!msg)
5144 return -ENOMEM;
5145
5146 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5147 NL80211_CMD_GET_WOWLAN);
5148 if (!hdr)
5149 goto nla_put_failure;
5150
5151 if (rdev->wowlan) {
5152 struct nlattr *nl_wowlan;
5153
5154 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
5155 if (!nl_wowlan)
5156 goto nla_put_failure;
5157
5158 if (rdev->wowlan->any)
5159 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
5160 if (rdev->wowlan->disconnect)
5161 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
5162 if (rdev->wowlan->magic_pkt)
5163 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
5164 if (rdev->wowlan->n_patterns) {
5165 struct nlattr *nl_pats, *nl_pat;
5166 int i, pat_len;
5167
5168 nl_pats = nla_nest_start(msg,
5169 NL80211_WOWLAN_TRIG_PKT_PATTERN);
5170 if (!nl_pats)
5171 goto nla_put_failure;
5172
5173 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
5174 nl_pat = nla_nest_start(msg, i + 1);
5175 if (!nl_pat)
5176 goto nla_put_failure;
5177 pat_len = rdev->wowlan->patterns[i].pattern_len;
5178 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK,
5179 DIV_ROUND_UP(pat_len, 8),
5180 rdev->wowlan->patterns[i].mask);
5181 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
5182 pat_len,
5183 rdev->wowlan->patterns[i].pattern);
5184 nla_nest_end(msg, nl_pat);
5185 }
5186 nla_nest_end(msg, nl_pats);
5187 }
5188
5189 nla_nest_end(msg, nl_wowlan);
5190 }
5191
5192 genlmsg_end(msg, hdr);
5193 return genlmsg_reply(msg, info);
5194
5195nla_put_failure:
5196 nlmsg_free(msg);
5197 return -ENOBUFS;
5198}
5199
5200static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
5201{
5202 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5203 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
5204 struct cfg80211_wowlan no_triggers = {};
5205 struct cfg80211_wowlan new_triggers = {};
5206 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
5207 int err, i;
5208
5209 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5210 return -EOPNOTSUPP;
5211
5212 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
5213 goto no_triggers;
5214
5215 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
5216 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5217 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5218 nl80211_wowlan_policy);
5219 if (err)
5220 return err;
5221
5222 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
5223 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
5224 return -EINVAL;
5225 new_triggers.any = true;
5226 }
5227
5228 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
5229 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
5230 return -EINVAL;
5231 new_triggers.disconnect = true;
5232 }
5233
5234 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
5235 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
5236 return -EINVAL;
5237 new_triggers.magic_pkt = true;
5238 }
5239
5240 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
5241 struct nlattr *pat;
5242 int n_patterns = 0;
5243 int rem, pat_len, mask_len;
5244 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
5245
5246 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5247 rem)
5248 n_patterns++;
5249 if (n_patterns > wowlan->n_patterns)
5250 return -EINVAL;
5251
5252 new_triggers.patterns = kcalloc(n_patterns,
5253 sizeof(new_triggers.patterns[0]),
5254 GFP_KERNEL);
5255 if (!new_triggers.patterns)
5256 return -ENOMEM;
5257
5258 new_triggers.n_patterns = n_patterns;
5259 i = 0;
5260
5261 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5262 rem) {
5263 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
5264 nla_data(pat), nla_len(pat), NULL);
5265 err = -EINVAL;
5266 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
5267 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
5268 goto error;
5269 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
5270 mask_len = DIV_ROUND_UP(pat_len, 8);
5271 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
5272 mask_len)
5273 goto error;
5274 if (pat_len > wowlan->pattern_max_len ||
5275 pat_len < wowlan->pattern_min_len)
5276 goto error;
5277
5278 new_triggers.patterns[i].mask =
5279 kmalloc(mask_len + pat_len, GFP_KERNEL);
5280 if (!new_triggers.patterns[i].mask) {
5281 err = -ENOMEM;
5282 goto error;
5283 }
5284 new_triggers.patterns[i].pattern =
5285 new_triggers.patterns[i].mask + mask_len;
5286 memcpy(new_triggers.patterns[i].mask,
5287 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
5288 mask_len);
5289 new_triggers.patterns[i].pattern_len = pat_len;
5290 memcpy(new_triggers.patterns[i].pattern,
5291 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
5292 pat_len);
5293 i++;
5294 }
5295 }
5296
5297 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
5298 struct cfg80211_wowlan *ntrig;
5299 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
5300 GFP_KERNEL);
5301 if (!ntrig) {
5302 err = -ENOMEM;
5303 goto error;
5304 }
5305 cfg80211_rdev_free_wowlan(rdev);
5306 rdev->wowlan = ntrig;
5307 } else {
5308 no_triggers:
5309 cfg80211_rdev_free_wowlan(rdev);
5310 rdev->wowlan = NULL;
5311 }
5312
5313 return 0;
5314 error:
5315 for (i = 0; i < new_triggers.n_patterns; i++)
5316 kfree(new_triggers.patterns[i].mask);
5317 kfree(new_triggers.patterns);
5318 return err;
5319}
5320
5321#define NL80211_FLAG_NEED_WIPHY 0x01
5322#define NL80211_FLAG_NEED_NETDEV 0x02
5323#define NL80211_FLAG_NEED_RTNL 0x04
5324#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
5325#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
5326 NL80211_FLAG_CHECK_NETDEV_UP)
5327
5328static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
5329 struct genl_info *info)
5330{
5331 struct cfg80211_registered_device *rdev;
5332 struct net_device *dev;
5333 int err;
5334 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
5335
5336 if (rtnl)
5337 rtnl_lock();
5338
5339 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
5340 rdev = cfg80211_get_dev_from_info(info);
5341 if (IS_ERR(rdev)) {
5342 if (rtnl)
5343 rtnl_unlock();
5344 return PTR_ERR(rdev);
5345 }
5346 info->user_ptr[0] = rdev;
5347 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
5348 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
5349 if (err) {
5350 if (rtnl)
5351 rtnl_unlock();
5352 return err;
5353 }
5354 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
5355 !netif_running(dev)) {
5356 cfg80211_unlock_rdev(rdev);
5357 dev_put(dev);
5358 if (rtnl)
5359 rtnl_unlock();
5360 return -ENETDOWN;
5361 }
5362 info->user_ptr[0] = rdev;
5363 info->user_ptr[1] = dev;
5364 }
5365
5366 return 0;
5367}
5368
5369static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
5370 struct genl_info *info)
5371{
5372 if (info->user_ptr[0])
5373 cfg80211_unlock_rdev(info->user_ptr[0]);
5374 if (info->user_ptr[1])
5375 dev_put(info->user_ptr[1]);
5376 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
5377 rtnl_unlock();
5378}
5379
5055static struct genl_ops nl80211_ops[] = { 5380static struct genl_ops nl80211_ops[] = {
5056 { 5381 {
5057 .cmd = NL80211_CMD_GET_WIPHY, 5382 .cmd = NL80211_CMD_GET_WIPHY,
@@ -5059,12 +5384,14 @@ static struct genl_ops nl80211_ops[] = {
5059 .dumpit = nl80211_dump_wiphy, 5384 .dumpit = nl80211_dump_wiphy,
5060 .policy = nl80211_policy, 5385 .policy = nl80211_policy,
5061 /* can be retrieved by unprivileged users */ 5386 /* can be retrieved by unprivileged users */
5387 .internal_flags = NL80211_FLAG_NEED_WIPHY,
5062 }, 5388 },
5063 { 5389 {
5064 .cmd = NL80211_CMD_SET_WIPHY, 5390 .cmd = NL80211_CMD_SET_WIPHY,
5065 .doit = nl80211_set_wiphy, 5391 .doit = nl80211_set_wiphy,
5066 .policy = nl80211_policy, 5392 .policy = nl80211_policy,
5067 .flags = GENL_ADMIN_PERM, 5393 .flags = GENL_ADMIN_PERM,
5394 .internal_flags = NL80211_FLAG_NEED_RTNL,
5068 }, 5395 },
5069 { 5396 {
5070 .cmd = NL80211_CMD_GET_INTERFACE, 5397 .cmd = NL80211_CMD_GET_INTERFACE,
@@ -5072,90 +5399,119 @@ static struct genl_ops nl80211_ops[] = {
5072 .dumpit = nl80211_dump_interface, 5399 .dumpit = nl80211_dump_interface,
5073 .policy = nl80211_policy, 5400 .policy = nl80211_policy,
5074 /* can be retrieved by unprivileged users */ 5401 /* can be retrieved by unprivileged users */
5402 .internal_flags = NL80211_FLAG_NEED_NETDEV,
5075 }, 5403 },
5076 { 5404 {
5077 .cmd = NL80211_CMD_SET_INTERFACE, 5405 .cmd = NL80211_CMD_SET_INTERFACE,
5078 .doit = nl80211_set_interface, 5406 .doit = nl80211_set_interface,
5079 .policy = nl80211_policy, 5407 .policy = nl80211_policy,
5080 .flags = GENL_ADMIN_PERM, 5408 .flags = GENL_ADMIN_PERM,
5409 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5410 NL80211_FLAG_NEED_RTNL,
5081 }, 5411 },
5082 { 5412 {
5083 .cmd = NL80211_CMD_NEW_INTERFACE, 5413 .cmd = NL80211_CMD_NEW_INTERFACE,
5084 .doit = nl80211_new_interface, 5414 .doit = nl80211_new_interface,
5085 .policy = nl80211_policy, 5415 .policy = nl80211_policy,
5086 .flags = GENL_ADMIN_PERM, 5416 .flags = GENL_ADMIN_PERM,
5417 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5418 NL80211_FLAG_NEED_RTNL,
5087 }, 5419 },
5088 { 5420 {
5089 .cmd = NL80211_CMD_DEL_INTERFACE, 5421 .cmd = NL80211_CMD_DEL_INTERFACE,
5090 .doit = nl80211_del_interface, 5422 .doit = nl80211_del_interface,
5091 .policy = nl80211_policy, 5423 .policy = nl80211_policy,
5092 .flags = GENL_ADMIN_PERM, 5424 .flags = GENL_ADMIN_PERM,
5425 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5426 NL80211_FLAG_NEED_RTNL,
5093 }, 5427 },
5094 { 5428 {
5095 .cmd = NL80211_CMD_GET_KEY, 5429 .cmd = NL80211_CMD_GET_KEY,
5096 .doit = nl80211_get_key, 5430 .doit = nl80211_get_key,
5097 .policy = nl80211_policy, 5431 .policy = nl80211_policy,
5098 .flags = GENL_ADMIN_PERM, 5432 .flags = GENL_ADMIN_PERM,
5433 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5434 NL80211_FLAG_NEED_RTNL,
5099 }, 5435 },
5100 { 5436 {
5101 .cmd = NL80211_CMD_SET_KEY, 5437 .cmd = NL80211_CMD_SET_KEY,
5102 .doit = nl80211_set_key, 5438 .doit = nl80211_set_key,
5103 .policy = nl80211_policy, 5439 .policy = nl80211_policy,
5104 .flags = GENL_ADMIN_PERM, 5440 .flags = GENL_ADMIN_PERM,
5441 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5442 NL80211_FLAG_NEED_RTNL,
5105 }, 5443 },
5106 { 5444 {
5107 .cmd = NL80211_CMD_NEW_KEY, 5445 .cmd = NL80211_CMD_NEW_KEY,
5108 .doit = nl80211_new_key, 5446 .doit = nl80211_new_key,
5109 .policy = nl80211_policy, 5447 .policy = nl80211_policy,
5110 .flags = GENL_ADMIN_PERM, 5448 .flags = GENL_ADMIN_PERM,
5449 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5450 NL80211_FLAG_NEED_RTNL,
5111 }, 5451 },
5112 { 5452 {
5113 .cmd = NL80211_CMD_DEL_KEY, 5453 .cmd = NL80211_CMD_DEL_KEY,
5114 .doit = nl80211_del_key, 5454 .doit = nl80211_del_key,
5115 .policy = nl80211_policy, 5455 .policy = nl80211_policy,
5116 .flags = GENL_ADMIN_PERM, 5456 .flags = GENL_ADMIN_PERM,
5457 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5458 NL80211_FLAG_NEED_RTNL,
5117 }, 5459 },
5118 { 5460 {
5119 .cmd = NL80211_CMD_SET_BEACON, 5461 .cmd = NL80211_CMD_SET_BEACON,
5120 .policy = nl80211_policy, 5462 .policy = nl80211_policy,
5121 .flags = GENL_ADMIN_PERM, 5463 .flags = GENL_ADMIN_PERM,
5122 .doit = nl80211_addset_beacon, 5464 .doit = nl80211_addset_beacon,
5465 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5466 NL80211_FLAG_NEED_RTNL,
5123 }, 5467 },
5124 { 5468 {
5125 .cmd = NL80211_CMD_NEW_BEACON, 5469 .cmd = NL80211_CMD_NEW_BEACON,
5126 .policy = nl80211_policy, 5470 .policy = nl80211_policy,
5127 .flags = GENL_ADMIN_PERM, 5471 .flags = GENL_ADMIN_PERM,
5128 .doit = nl80211_addset_beacon, 5472 .doit = nl80211_addset_beacon,
5473 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5474 NL80211_FLAG_NEED_RTNL,
5129 }, 5475 },
5130 { 5476 {
5131 .cmd = NL80211_CMD_DEL_BEACON, 5477 .cmd = NL80211_CMD_DEL_BEACON,
5132 .policy = nl80211_policy, 5478 .policy = nl80211_policy,
5133 .flags = GENL_ADMIN_PERM, 5479 .flags = GENL_ADMIN_PERM,
5134 .doit = nl80211_del_beacon, 5480 .doit = nl80211_del_beacon,
5481 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5482 NL80211_FLAG_NEED_RTNL,
5135 }, 5483 },
5136 { 5484 {
5137 .cmd = NL80211_CMD_GET_STATION, 5485 .cmd = NL80211_CMD_GET_STATION,
5138 .doit = nl80211_get_station, 5486 .doit = nl80211_get_station,
5139 .dumpit = nl80211_dump_station, 5487 .dumpit = nl80211_dump_station,
5140 .policy = nl80211_policy, 5488 .policy = nl80211_policy,
5489 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5490 NL80211_FLAG_NEED_RTNL,
5141 }, 5491 },
5142 { 5492 {
5143 .cmd = NL80211_CMD_SET_STATION, 5493 .cmd = NL80211_CMD_SET_STATION,
5144 .doit = nl80211_set_station, 5494 .doit = nl80211_set_station,
5145 .policy = nl80211_policy, 5495 .policy = nl80211_policy,
5146 .flags = GENL_ADMIN_PERM, 5496 .flags = GENL_ADMIN_PERM,
5497 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5498 NL80211_FLAG_NEED_RTNL,
5147 }, 5499 },
5148 { 5500 {
5149 .cmd = NL80211_CMD_NEW_STATION, 5501 .cmd = NL80211_CMD_NEW_STATION,
5150 .doit = nl80211_new_station, 5502 .doit = nl80211_new_station,
5151 .policy = nl80211_policy, 5503 .policy = nl80211_policy,
5152 .flags = GENL_ADMIN_PERM, 5504 .flags = GENL_ADMIN_PERM,
5505 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5506 NL80211_FLAG_NEED_RTNL,
5153 }, 5507 },
5154 { 5508 {
5155 .cmd = NL80211_CMD_DEL_STATION, 5509 .cmd = NL80211_CMD_DEL_STATION,
5156 .doit = nl80211_del_station, 5510 .doit = nl80211_del_station,
5157 .policy = nl80211_policy, 5511 .policy = nl80211_policy,
5158 .flags = GENL_ADMIN_PERM, 5512 .flags = GENL_ADMIN_PERM,
5513 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5514 NL80211_FLAG_NEED_RTNL,
5159 }, 5515 },
5160 { 5516 {
5161 .cmd = NL80211_CMD_GET_MPATH, 5517 .cmd = NL80211_CMD_GET_MPATH,
@@ -5163,30 +5519,40 @@ static struct genl_ops nl80211_ops[] = {
5163 .dumpit = nl80211_dump_mpath, 5519 .dumpit = nl80211_dump_mpath,
5164 .policy = nl80211_policy, 5520 .policy = nl80211_policy,
5165 .flags = GENL_ADMIN_PERM, 5521 .flags = GENL_ADMIN_PERM,
5522 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5523 NL80211_FLAG_NEED_RTNL,
5166 }, 5524 },
5167 { 5525 {
5168 .cmd = NL80211_CMD_SET_MPATH, 5526 .cmd = NL80211_CMD_SET_MPATH,
5169 .doit = nl80211_set_mpath, 5527 .doit = nl80211_set_mpath,
5170 .policy = nl80211_policy, 5528 .policy = nl80211_policy,
5171 .flags = GENL_ADMIN_PERM, 5529 .flags = GENL_ADMIN_PERM,
5530 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5531 NL80211_FLAG_NEED_RTNL,
5172 }, 5532 },
5173 { 5533 {
5174 .cmd = NL80211_CMD_NEW_MPATH, 5534 .cmd = NL80211_CMD_NEW_MPATH,
5175 .doit = nl80211_new_mpath, 5535 .doit = nl80211_new_mpath,
5176 .policy = nl80211_policy, 5536 .policy = nl80211_policy,
5177 .flags = GENL_ADMIN_PERM, 5537 .flags = GENL_ADMIN_PERM,
5538 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5539 NL80211_FLAG_NEED_RTNL,
5178 }, 5540 },
5179 { 5541 {
5180 .cmd = NL80211_CMD_DEL_MPATH, 5542 .cmd = NL80211_CMD_DEL_MPATH,
5181 .doit = nl80211_del_mpath, 5543 .doit = nl80211_del_mpath,
5182 .policy = nl80211_policy, 5544 .policy = nl80211_policy,
5183 .flags = GENL_ADMIN_PERM, 5545 .flags = GENL_ADMIN_PERM,
5546 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5547 NL80211_FLAG_NEED_RTNL,
5184 }, 5548 },
5185 { 5549 {
5186 .cmd = NL80211_CMD_SET_BSS, 5550 .cmd = NL80211_CMD_SET_BSS,
5187 .doit = nl80211_set_bss, 5551 .doit = nl80211_set_bss,
5188 .policy = nl80211_policy, 5552 .policy = nl80211_policy,
5189 .flags = GENL_ADMIN_PERM, 5553 .flags = GENL_ADMIN_PERM,
5554 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5555 NL80211_FLAG_NEED_RTNL,
5190 }, 5556 },
5191 { 5557 {
5192 .cmd = NL80211_CMD_GET_REG, 5558 .cmd = NL80211_CMD_GET_REG,
@@ -5207,22 +5573,28 @@ static struct genl_ops nl80211_ops[] = {
5207 .flags = GENL_ADMIN_PERM, 5573 .flags = GENL_ADMIN_PERM,
5208 }, 5574 },
5209 { 5575 {
5210 .cmd = NL80211_CMD_GET_MESH_PARAMS, 5576 .cmd = NL80211_CMD_GET_MESH_CONFIG,
5211 .doit = nl80211_get_mesh_params, 5577 .doit = nl80211_get_mesh_config,
5212 .policy = nl80211_policy, 5578 .policy = nl80211_policy,
5213 /* can be retrieved by unprivileged users */ 5579 /* can be retrieved by unprivileged users */
5580 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5581 NL80211_FLAG_NEED_RTNL,
5214 }, 5582 },
5215 { 5583 {
5216 .cmd = NL80211_CMD_SET_MESH_PARAMS, 5584 .cmd = NL80211_CMD_SET_MESH_CONFIG,
5217 .doit = nl80211_set_mesh_params, 5585 .doit = nl80211_update_mesh_config,
5218 .policy = nl80211_policy, 5586 .policy = nl80211_policy,
5219 .flags = GENL_ADMIN_PERM, 5587 .flags = GENL_ADMIN_PERM,
5588 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5589 NL80211_FLAG_NEED_RTNL,
5220 }, 5590 },
5221 { 5591 {
5222 .cmd = NL80211_CMD_TRIGGER_SCAN, 5592 .cmd = NL80211_CMD_TRIGGER_SCAN,
5223 .doit = nl80211_trigger_scan, 5593 .doit = nl80211_trigger_scan,
5224 .policy = nl80211_policy, 5594 .policy = nl80211_policy,
5225 .flags = GENL_ADMIN_PERM, 5595 .flags = GENL_ADMIN_PERM,
5596 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5597 NL80211_FLAG_NEED_RTNL,
5226 }, 5598 },
5227 { 5599 {
5228 .cmd = NL80211_CMD_GET_SCAN, 5600 .cmd = NL80211_CMD_GET_SCAN,
@@ -5230,40 +5602,68 @@ static struct genl_ops nl80211_ops[] = {
5230 .dumpit = nl80211_dump_scan, 5602 .dumpit = nl80211_dump_scan,
5231 }, 5603 },
5232 { 5604 {
5605 .cmd = NL80211_CMD_START_SCHED_SCAN,
5606 .doit = nl80211_start_sched_scan,
5607 .policy = nl80211_policy,
5608 .flags = GENL_ADMIN_PERM,
5609 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5610 NL80211_FLAG_NEED_RTNL,
5611 },
5612 {
5613 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
5614 .doit = nl80211_stop_sched_scan,
5615 .policy = nl80211_policy,
5616 .flags = GENL_ADMIN_PERM,
5617 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5618 NL80211_FLAG_NEED_RTNL,
5619 },
5620 {
5233 .cmd = NL80211_CMD_AUTHENTICATE, 5621 .cmd = NL80211_CMD_AUTHENTICATE,
5234 .doit = nl80211_authenticate, 5622 .doit = nl80211_authenticate,
5235 .policy = nl80211_policy, 5623 .policy = nl80211_policy,
5236 .flags = GENL_ADMIN_PERM, 5624 .flags = GENL_ADMIN_PERM,
5625 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5626 NL80211_FLAG_NEED_RTNL,
5237 }, 5627 },
5238 { 5628 {
5239 .cmd = NL80211_CMD_ASSOCIATE, 5629 .cmd = NL80211_CMD_ASSOCIATE,
5240 .doit = nl80211_associate, 5630 .doit = nl80211_associate,
5241 .policy = nl80211_policy, 5631 .policy = nl80211_policy,
5242 .flags = GENL_ADMIN_PERM, 5632 .flags = GENL_ADMIN_PERM,
5633 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5634 NL80211_FLAG_NEED_RTNL,
5243 }, 5635 },
5244 { 5636 {
5245 .cmd = NL80211_CMD_DEAUTHENTICATE, 5637 .cmd = NL80211_CMD_DEAUTHENTICATE,
5246 .doit = nl80211_deauthenticate, 5638 .doit = nl80211_deauthenticate,
5247 .policy = nl80211_policy, 5639 .policy = nl80211_policy,
5248 .flags = GENL_ADMIN_PERM, 5640 .flags = GENL_ADMIN_PERM,
5641 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5642 NL80211_FLAG_NEED_RTNL,
5249 }, 5643 },
5250 { 5644 {
5251 .cmd = NL80211_CMD_DISASSOCIATE, 5645 .cmd = NL80211_CMD_DISASSOCIATE,
5252 .doit = nl80211_disassociate, 5646 .doit = nl80211_disassociate,
5253 .policy = nl80211_policy, 5647 .policy = nl80211_policy,
5254 .flags = GENL_ADMIN_PERM, 5648 .flags = GENL_ADMIN_PERM,
5649 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5650 NL80211_FLAG_NEED_RTNL,
5255 }, 5651 },
5256 { 5652 {
5257 .cmd = NL80211_CMD_JOIN_IBSS, 5653 .cmd = NL80211_CMD_JOIN_IBSS,
5258 .doit = nl80211_join_ibss, 5654 .doit = nl80211_join_ibss,
5259 .policy = nl80211_policy, 5655 .policy = nl80211_policy,
5260 .flags = GENL_ADMIN_PERM, 5656 .flags = GENL_ADMIN_PERM,
5657 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5658 NL80211_FLAG_NEED_RTNL,
5261 }, 5659 },
5262 { 5660 {
5263 .cmd = NL80211_CMD_LEAVE_IBSS, 5661 .cmd = NL80211_CMD_LEAVE_IBSS,
5264 .doit = nl80211_leave_ibss, 5662 .doit = nl80211_leave_ibss,
5265 .policy = nl80211_policy, 5663 .policy = nl80211_policy,
5266 .flags = GENL_ADMIN_PERM, 5664 .flags = GENL_ADMIN_PERM,
5665 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5666 NL80211_FLAG_NEED_RTNL,
5267 }, 5667 },
5268#ifdef CONFIG_NL80211_TESTMODE 5668#ifdef CONFIG_NL80211_TESTMODE
5269 { 5669 {
@@ -5271,6 +5671,8 @@ static struct genl_ops nl80211_ops[] = {
5271 .doit = nl80211_testmode_do, 5671 .doit = nl80211_testmode_do,
5272 .policy = nl80211_policy, 5672 .policy = nl80211_policy,
5273 .flags = GENL_ADMIN_PERM, 5673 .flags = GENL_ADMIN_PERM,
5674 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5675 NL80211_FLAG_NEED_RTNL,
5274 }, 5676 },
5275#endif 5677#endif
5276 { 5678 {
@@ -5278,18 +5680,24 @@ static struct genl_ops nl80211_ops[] = {
5278 .doit = nl80211_connect, 5680 .doit = nl80211_connect,
5279 .policy = nl80211_policy, 5681 .policy = nl80211_policy,
5280 .flags = GENL_ADMIN_PERM, 5682 .flags = GENL_ADMIN_PERM,
5683 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5684 NL80211_FLAG_NEED_RTNL,
5281 }, 5685 },
5282 { 5686 {
5283 .cmd = NL80211_CMD_DISCONNECT, 5687 .cmd = NL80211_CMD_DISCONNECT,
5284 .doit = nl80211_disconnect, 5688 .doit = nl80211_disconnect,
5285 .policy = nl80211_policy, 5689 .policy = nl80211_policy,
5286 .flags = GENL_ADMIN_PERM, 5690 .flags = GENL_ADMIN_PERM,
5691 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5692 NL80211_FLAG_NEED_RTNL,
5287 }, 5693 },
5288 { 5694 {
5289 .cmd = NL80211_CMD_SET_WIPHY_NETNS, 5695 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
5290 .doit = nl80211_wiphy_netns, 5696 .doit = nl80211_wiphy_netns,
5291 .policy = nl80211_policy, 5697 .policy = nl80211_policy,
5292 .flags = GENL_ADMIN_PERM, 5698 .flags = GENL_ADMIN_PERM,
5699 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5700 NL80211_FLAG_NEED_RTNL,
5293 }, 5701 },
5294 { 5702 {
5295 .cmd = NL80211_CMD_GET_SURVEY, 5703 .cmd = NL80211_CMD_GET_SURVEY,
@@ -5301,72 +5709,144 @@ static struct genl_ops nl80211_ops[] = {
5301 .doit = nl80211_setdel_pmksa, 5709 .doit = nl80211_setdel_pmksa,
5302 .policy = nl80211_policy, 5710 .policy = nl80211_policy,
5303 .flags = GENL_ADMIN_PERM, 5711 .flags = GENL_ADMIN_PERM,
5712 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5713 NL80211_FLAG_NEED_RTNL,
5304 }, 5714 },
5305 { 5715 {
5306 .cmd = NL80211_CMD_DEL_PMKSA, 5716 .cmd = NL80211_CMD_DEL_PMKSA,
5307 .doit = nl80211_setdel_pmksa, 5717 .doit = nl80211_setdel_pmksa,
5308 .policy = nl80211_policy, 5718 .policy = nl80211_policy,
5309 .flags = GENL_ADMIN_PERM, 5719 .flags = GENL_ADMIN_PERM,
5720 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5721 NL80211_FLAG_NEED_RTNL,
5310 }, 5722 },
5311 { 5723 {
5312 .cmd = NL80211_CMD_FLUSH_PMKSA, 5724 .cmd = NL80211_CMD_FLUSH_PMKSA,
5313 .doit = nl80211_flush_pmksa, 5725 .doit = nl80211_flush_pmksa,
5314 .policy = nl80211_policy, 5726 .policy = nl80211_policy,
5315 .flags = GENL_ADMIN_PERM, 5727 .flags = GENL_ADMIN_PERM,
5728 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5729 NL80211_FLAG_NEED_RTNL,
5316 }, 5730 },
5317 { 5731 {
5318 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, 5732 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
5319 .doit = nl80211_remain_on_channel, 5733 .doit = nl80211_remain_on_channel,
5320 .policy = nl80211_policy, 5734 .policy = nl80211_policy,
5321 .flags = GENL_ADMIN_PERM, 5735 .flags = GENL_ADMIN_PERM,
5736 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5737 NL80211_FLAG_NEED_RTNL,
5322 }, 5738 },
5323 { 5739 {
5324 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 5740 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
5325 .doit = nl80211_cancel_remain_on_channel, 5741 .doit = nl80211_cancel_remain_on_channel,
5326 .policy = nl80211_policy, 5742 .policy = nl80211_policy,
5327 .flags = GENL_ADMIN_PERM, 5743 .flags = GENL_ADMIN_PERM,
5744 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5745 NL80211_FLAG_NEED_RTNL,
5328 }, 5746 },
5329 { 5747 {
5330 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, 5748 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
5331 .doit = nl80211_set_tx_bitrate_mask, 5749 .doit = nl80211_set_tx_bitrate_mask,
5332 .policy = nl80211_policy, 5750 .policy = nl80211_policy,
5333 .flags = GENL_ADMIN_PERM, 5751 .flags = GENL_ADMIN_PERM,
5752 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5753 NL80211_FLAG_NEED_RTNL,
5334 }, 5754 },
5335 { 5755 {
5336 .cmd = NL80211_CMD_REGISTER_ACTION, 5756 .cmd = NL80211_CMD_REGISTER_FRAME,
5337 .doit = nl80211_register_action, 5757 .doit = nl80211_register_mgmt,
5338 .policy = nl80211_policy, 5758 .policy = nl80211_policy,
5339 .flags = GENL_ADMIN_PERM, 5759 .flags = GENL_ADMIN_PERM,
5760 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5761 NL80211_FLAG_NEED_RTNL,
5340 }, 5762 },
5341 { 5763 {
5342 .cmd = NL80211_CMD_ACTION, 5764 .cmd = NL80211_CMD_FRAME,
5343 .doit = nl80211_action, 5765 .doit = nl80211_tx_mgmt,
5344 .policy = nl80211_policy, 5766 .policy = nl80211_policy,
5345 .flags = GENL_ADMIN_PERM, 5767 .flags = GENL_ADMIN_PERM,
5768 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5769 NL80211_FLAG_NEED_RTNL,
5770 },
5771 {
5772 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
5773 .doit = nl80211_tx_mgmt_cancel_wait,
5774 .policy = nl80211_policy,
5775 .flags = GENL_ADMIN_PERM,
5776 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5777 NL80211_FLAG_NEED_RTNL,
5346 }, 5778 },
5347 { 5779 {
5348 .cmd = NL80211_CMD_SET_POWER_SAVE, 5780 .cmd = NL80211_CMD_SET_POWER_SAVE,
5349 .doit = nl80211_set_power_save, 5781 .doit = nl80211_set_power_save,
5350 .policy = nl80211_policy, 5782 .policy = nl80211_policy,
5351 .flags = GENL_ADMIN_PERM, 5783 .flags = GENL_ADMIN_PERM,
5784 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5785 NL80211_FLAG_NEED_RTNL,
5352 }, 5786 },
5353 { 5787 {
5354 .cmd = NL80211_CMD_GET_POWER_SAVE, 5788 .cmd = NL80211_CMD_GET_POWER_SAVE,
5355 .doit = nl80211_get_power_save, 5789 .doit = nl80211_get_power_save,
5356 .policy = nl80211_policy, 5790 .policy = nl80211_policy,
5357 /* can be retrieved by unprivileged users */ 5791 /* can be retrieved by unprivileged users */
5792 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5793 NL80211_FLAG_NEED_RTNL,
5358 }, 5794 },
5359 { 5795 {
5360 .cmd = NL80211_CMD_SET_CQM, 5796 .cmd = NL80211_CMD_SET_CQM,
5361 .doit = nl80211_set_cqm, 5797 .doit = nl80211_set_cqm,
5362 .policy = nl80211_policy, 5798 .policy = nl80211_policy,
5363 .flags = GENL_ADMIN_PERM, 5799 .flags = GENL_ADMIN_PERM,
5800 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5801 NL80211_FLAG_NEED_RTNL,
5364 }, 5802 },
5365 { 5803 {
5366 .cmd = NL80211_CMD_SET_CHANNEL, 5804 .cmd = NL80211_CMD_SET_CHANNEL,
5367 .doit = nl80211_set_channel, 5805 .doit = nl80211_set_channel,
5368 .policy = nl80211_policy, 5806 .policy = nl80211_policy,
5369 .flags = GENL_ADMIN_PERM, 5807 .flags = GENL_ADMIN_PERM,
5808 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5809 NL80211_FLAG_NEED_RTNL,
5810 },
5811 {
5812 .cmd = NL80211_CMD_SET_WDS_PEER,
5813 .doit = nl80211_set_wds_peer,
5814 .policy = nl80211_policy,
5815 .flags = GENL_ADMIN_PERM,
5816 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5817 NL80211_FLAG_NEED_RTNL,
5818 },
5819 {
5820 .cmd = NL80211_CMD_JOIN_MESH,
5821 .doit = nl80211_join_mesh,
5822 .policy = nl80211_policy,
5823 .flags = GENL_ADMIN_PERM,
5824 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5825 NL80211_FLAG_NEED_RTNL,
5826 },
5827 {
5828 .cmd = NL80211_CMD_LEAVE_MESH,
5829 .doit = nl80211_leave_mesh,
5830 .policy = nl80211_policy,
5831 .flags = GENL_ADMIN_PERM,
5832 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5833 NL80211_FLAG_NEED_RTNL,
5834 },
5835 {
5836 .cmd = NL80211_CMD_GET_WOWLAN,
5837 .doit = nl80211_get_wowlan,
5838 .policy = nl80211_policy,
5839 /* can be retrieved by unprivileged users */
5840 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5841 NL80211_FLAG_NEED_RTNL,
5842 },
5843 {
5844 .cmd = NL80211_CMD_SET_WOWLAN,
5845 .doit = nl80211_set_wowlan,
5846 .policy = nl80211_policy,
5847 .flags = GENL_ADMIN_PERM,
5848 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5849 NL80211_FLAG_NEED_RTNL,
5370 }, 5850 },
5371}; 5851};
5372 5852
@@ -5463,6 +5943,28 @@ static int nl80211_send_scan_msg(struct sk_buff *msg,
5463 return -EMSGSIZE; 5943 return -EMSGSIZE;
5464} 5944}
5465 5945
5946static int
5947nl80211_send_sched_scan_msg(struct sk_buff *msg,
5948 struct cfg80211_registered_device *rdev,
5949 struct net_device *netdev,
5950 u32 pid, u32 seq, int flags, u32 cmd)
5951{
5952 void *hdr;
5953
5954 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
5955 if (!hdr)
5956 return -1;
5957
5958 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5959 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5960
5961 return genlmsg_end(msg, hdr);
5962
5963 nla_put_failure:
5964 genlmsg_cancel(msg, hdr);
5965 return -EMSGSIZE;
5966}
5967
5466void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, 5968void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
5467 struct net_device *netdev) 5969 struct net_device *netdev)
5468{ 5970{
@@ -5520,6 +6022,43 @@ void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
5520 nl80211_scan_mcgrp.id, GFP_KERNEL); 6022 nl80211_scan_mcgrp.id, GFP_KERNEL);
5521} 6023}
5522 6024
6025void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
6026 struct net_device *netdev)
6027{
6028 struct sk_buff *msg;
6029
6030 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6031 if (!msg)
6032 return;
6033
6034 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
6035 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
6036 nlmsg_free(msg);
6037 return;
6038 }
6039
6040 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6041 nl80211_scan_mcgrp.id, GFP_KERNEL);
6042}
6043
6044void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
6045 struct net_device *netdev, u32 cmd)
6046{
6047 struct sk_buff *msg;
6048
6049 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6050 if (!msg)
6051 return;
6052
6053 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
6054 nlmsg_free(msg);
6055 return;
6056 }
6057
6058 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6059 nl80211_scan_mcgrp.id, GFP_KERNEL);
6060}
6061
5523/* 6062/*
5524 * This can happen on global regulatory changes or device specific settings 6063 * This can happen on global regulatory changes or device specific settings
5525 * based on custom world regulatory domains. 6064 * based on custom world regulatory domains.
@@ -5646,6 +6185,22 @@ void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
5646 NL80211_CMD_DISASSOCIATE, gfp); 6185 NL80211_CMD_DISASSOCIATE, gfp);
5647} 6186}
5648 6187
6188void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
6189 struct net_device *netdev, const u8 *buf,
6190 size_t len, gfp_t gfp)
6191{
6192 nl80211_send_mlme_event(rdev, netdev, buf, len,
6193 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
6194}
6195
6196void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
6197 struct net_device *netdev, const u8 *buf,
6198 size_t len, gfp_t gfp)
6199{
6200 nl80211_send_mlme_event(rdev, netdev, buf, len,
6201 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
6202}
6203
5649static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, 6204static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
5650 struct net_device *netdev, int cmd, 6205 struct net_device *netdev, int cmd,
5651 const u8 *addr, gfp_t gfp) 6206 const u8 *addr, gfp_t gfp)
@@ -5859,6 +6414,44 @@ void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
5859 nlmsg_free(msg); 6414 nlmsg_free(msg);
5860} 6415}
5861 6416
6417void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
6418 struct net_device *netdev,
6419 const u8 *macaddr, const u8* ie, u8 ie_len,
6420 gfp_t gfp)
6421{
6422 struct sk_buff *msg;
6423 void *hdr;
6424
6425 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6426 if (!msg)
6427 return;
6428
6429 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
6430 if (!hdr) {
6431 nlmsg_free(msg);
6432 return;
6433 }
6434
6435 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6436 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6437 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr);
6438 if (ie_len && ie)
6439 NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie);
6440
6441 if (genlmsg_end(msg, hdr) < 0) {
6442 nlmsg_free(msg);
6443 return;
6444 }
6445
6446 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6447 nl80211_mlme_mcgrp.id, gfp);
6448 return;
6449
6450 nla_put_failure:
6451 genlmsg_cancel(msg, hdr);
6452 nlmsg_free(msg);
6453}
6454
5862void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, 6455void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
5863 struct net_device *netdev, const u8 *addr, 6456 struct net_device *netdev, const u8 *addr,
5864 enum nl80211_key_type key_type, int key_id, 6457 enum nl80211_key_type key_type, int key_id,
@@ -5882,7 +6475,8 @@ void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
5882 if (addr) 6475 if (addr)
5883 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); 6476 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
5884 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); 6477 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
5885 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); 6478 if (key_id != -1)
6479 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
5886 if (tsc) 6480 if (tsc)
5887 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); 6481 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
5888 6482
@@ -6040,9 +6634,43 @@ void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
6040 nl80211_mlme_mcgrp.id, gfp); 6634 nl80211_mlme_mcgrp.id, gfp);
6041} 6635}
6042 6636
6043int nl80211_send_action(struct cfg80211_registered_device *rdev, 6637void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
6044 struct net_device *netdev, u32 nlpid, 6638 struct net_device *dev, const u8 *mac_addr,
6045 int freq, const u8 *buf, size_t len, gfp_t gfp) 6639 gfp_t gfp)
6640{
6641 struct sk_buff *msg;
6642 void *hdr;
6643
6644 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6645 if (!msg)
6646 return;
6647
6648 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
6649 if (!hdr) {
6650 nlmsg_free(msg);
6651 return;
6652 }
6653
6654 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
6655 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
6656
6657 if (genlmsg_end(msg, hdr) < 0) {
6658 nlmsg_free(msg);
6659 return;
6660 }
6661
6662 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6663 nl80211_mlme_mcgrp.id, gfp);
6664 return;
6665
6666 nla_put_failure:
6667 genlmsg_cancel(msg, hdr);
6668 nlmsg_free(msg);
6669}
6670
6671int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
6672 struct net_device *netdev, u32 nlpid,
6673 int freq, const u8 *buf, size_t len, gfp_t gfp)
6046{ 6674{
6047 struct sk_buff *msg; 6675 struct sk_buff *msg;
6048 void *hdr; 6676 void *hdr;
@@ -6052,7 +6680,7 @@ int nl80211_send_action(struct cfg80211_registered_device *rdev,
6052 if (!msg) 6680 if (!msg)
6053 return -ENOMEM; 6681 return -ENOMEM;
6054 6682
6055 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ACTION); 6683 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
6056 if (!hdr) { 6684 if (!hdr) {
6057 nlmsg_free(msg); 6685 nlmsg_free(msg);
6058 return -ENOMEM; 6686 return -ENOMEM;
@@ -6080,10 +6708,10 @@ int nl80211_send_action(struct cfg80211_registered_device *rdev,
6080 return -ENOBUFS; 6708 return -ENOBUFS;
6081} 6709}
6082 6710
6083void nl80211_send_action_tx_status(struct cfg80211_registered_device *rdev, 6711void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
6084 struct net_device *netdev, u64 cookie, 6712 struct net_device *netdev, u64 cookie,
6085 const u8 *buf, size_t len, bool ack, 6713 const u8 *buf, size_t len, bool ack,
6086 gfp_t gfp) 6714 gfp_t gfp)
6087{ 6715{
6088 struct sk_buff *msg; 6716 struct sk_buff *msg;
6089 void *hdr; 6717 void *hdr;
@@ -6092,7 +6720,7 @@ void nl80211_send_action_tx_status(struct cfg80211_registered_device *rdev,
6092 if (!msg) 6720 if (!msg)
6093 return; 6721 return;
6094 6722
6095 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ACTION_TX_STATUS); 6723 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
6096 if (!hdr) { 6724 if (!hdr) {
6097 nlmsg_free(msg); 6725 nlmsg_free(msg);
6098 return; 6726 return;
@@ -6164,6 +6792,51 @@ nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
6164 nlmsg_free(msg); 6792 nlmsg_free(msg);
6165} 6793}
6166 6794
6795void
6796nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
6797 struct net_device *netdev, const u8 *peer,
6798 u32 num_packets, gfp_t gfp)
6799{
6800 struct sk_buff *msg;
6801 struct nlattr *pinfoattr;
6802 void *hdr;
6803
6804 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6805 if (!msg)
6806 return;
6807
6808 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
6809 if (!hdr) {
6810 nlmsg_free(msg);
6811 return;
6812 }
6813
6814 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6815 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6816 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
6817
6818 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
6819 if (!pinfoattr)
6820 goto nla_put_failure;
6821
6822 NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets);
6823
6824 nla_nest_end(msg, pinfoattr);
6825
6826 if (genlmsg_end(msg, hdr) < 0) {
6827 nlmsg_free(msg);
6828 return;
6829 }
6830
6831 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6832 nl80211_mlme_mcgrp.id, gfp);
6833 return;
6834
6835 nla_put_failure:
6836 genlmsg_cancel(msg, hdr);
6837 nlmsg_free(msg);
6838}
6839
6167static int nl80211_netlink_notify(struct notifier_block * nb, 6840static int nl80211_netlink_notify(struct notifier_block * nb,
6168 unsigned long state, 6841 unsigned long state,
6169 void *_notify) 6842 void *_notify)
@@ -6179,7 +6852,7 @@ static int nl80211_netlink_notify(struct notifier_block * nb,
6179 6852
6180 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) 6853 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list)
6181 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) 6854 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
6182 cfg80211_mlme_unregister_actions(wdev, notify->pid); 6855 cfg80211_mlme_unregister_socket(wdev, notify->pid);
6183 6856
6184 rcu_read_unlock(); 6857 rcu_read_unlock();
6185 6858
diff --git a/net/wireless/nl80211.h b/net/wireless/nl80211.h
index 2ad7fbc7d9f1..2f1bfb87a651 100644
--- a/net/wireless/nl80211.h
+++ b/net/wireless/nl80211.h
@@ -12,6 +12,10 @@ void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
12 struct net_device *netdev); 12 struct net_device *netdev);
13void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, 13void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
14 struct net_device *netdev); 14 struct net_device *netdev);
15void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
16 struct net_device *netdev, u32 cmd);
17void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
18 struct net_device *netdev);
15void nl80211_send_reg_change_event(struct regulatory_request *request); 19void nl80211_send_reg_change_event(struct regulatory_request *request);
16void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, 20void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
17 struct net_device *netdev, 21 struct net_device *netdev,
@@ -25,6 +29,12 @@ void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
25void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, 29void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
26 struct net_device *netdev, 30 struct net_device *netdev,
27 const u8 *buf, size_t len, gfp_t gfp); 31 const u8 *buf, size_t len, gfp_t gfp);
32void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
33 struct net_device *netdev,
34 const u8 *buf, size_t len, gfp_t gfp);
35void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
36 struct net_device *netdev,
37 const u8 *buf, size_t len, gfp_t gfp);
28void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, 38void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
29 struct net_device *netdev, 39 struct net_device *netdev,
30 const u8 *addr, gfp_t gfp); 40 const u8 *addr, gfp_t gfp);
@@ -44,6 +54,10 @@ void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
44 struct net_device *netdev, u16 reason, 54 struct net_device *netdev, u16 reason,
45 const u8 *ie, size_t ie_len, bool from_ap); 55 const u8 *ie, size_t ie_len, bool from_ap);
46 56
57void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
58 struct net_device *netdev,
59 const u8 *macaddr, const u8* ie, u8 ie_len,
60 gfp_t gfp);
47void 61void
48nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, 62nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
49 struct net_device *netdev, const u8 *addr, 63 struct net_device *netdev, const u8 *addr,
@@ -73,19 +87,26 @@ void nl80211_send_remain_on_channel_cancel(
73void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, 87void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
74 struct net_device *dev, const u8 *mac_addr, 88 struct net_device *dev, const u8 *mac_addr,
75 struct station_info *sinfo, gfp_t gfp); 89 struct station_info *sinfo, gfp_t gfp);
90void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
91 struct net_device *dev, const u8 *mac_addr,
92 gfp_t gfp);
76 93
77int nl80211_send_action(struct cfg80211_registered_device *rdev, 94int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
78 struct net_device *netdev, u32 nlpid, int freq, 95 struct net_device *netdev, u32 nlpid, int freq,
79 const u8 *buf, size_t len, gfp_t gfp); 96 const u8 *buf, size_t len, gfp_t gfp);
80void nl80211_send_action_tx_status(struct cfg80211_registered_device *rdev, 97void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
81 struct net_device *netdev, u64 cookie, 98 struct net_device *netdev, u64 cookie,
82 const u8 *buf, size_t len, bool ack, 99 const u8 *buf, size_t len, bool ack,
83 gfp_t gfp); 100 gfp_t gfp);
84 101
85void 102void
86nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, 103nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
87 struct net_device *netdev, 104 struct net_device *netdev,
88 enum nl80211_cqm_rssi_threshold_event rssi_event, 105 enum nl80211_cqm_rssi_threshold_event rssi_event,
89 gfp_t gfp); 106 gfp_t gfp);
107void
108nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
109 struct net_device *netdev, const u8 *peer,
110 u32 num_packets, gfp_t gfp);
90 111
91#endif /* __NET_WIRELESS_NL80211_H */ 112#endif /* __NET_WIRELESS_NL80211_H */
diff --git a/net/wireless/radiotap.c b/net/wireless/radiotap.c
index 1332c445d1c7..dbe35e138e94 100644
--- a/net/wireless/radiotap.c
+++ b/net/wireless/radiotap.c
@@ -14,6 +14,7 @@
14 * See COPYING for more details. 14 * See COPYING for more details.
15 */ 15 */
16 16
17#include <linux/kernel.h>
17#include <net/cfg80211.h> 18#include <net/cfg80211.h>
18#include <net/ieee80211_radiotap.h> 19#include <net/ieee80211_radiotap.h>
19#include <asm/unaligned.h> 20#include <asm/unaligned.h>
@@ -45,7 +46,7 @@ static const struct radiotap_align_size rtap_namespace_sizes[] = {
45}; 46};
46 47
47static const struct ieee80211_radiotap_namespace radiotap_ns = { 48static const struct ieee80211_radiotap_namespace radiotap_ns = {
48 .n_bits = sizeof(rtap_namespace_sizes) / sizeof(rtap_namespace_sizes[0]), 49 .n_bits = ARRAY_SIZE(rtap_namespace_sizes),
49 .align_size = rtap_namespace_sizes, 50 .align_size = rtap_namespace_sizes,
50}; 51};
51 52
@@ -200,7 +201,7 @@ int ieee80211_radiotap_iterator_next(
200{ 201{
201 while (1) { 202 while (1) {
202 int hit = 0; 203 int hit = 0;
203 int pad, align, size, subns, vnslen; 204 int pad, align, size, subns;
204 uint32_t oui; 205 uint32_t oui;
205 206
206 /* if no more EXT bits, that's it */ 207 /* if no more EXT bits, that's it */
@@ -260,6 +261,27 @@ int ieee80211_radiotap_iterator_next(
260 if (pad) 261 if (pad)
261 iterator->_arg += align - pad; 262 iterator->_arg += align - pad;
262 263
264 if (iterator->_arg_index % 32 == IEEE80211_RADIOTAP_VENDOR_NAMESPACE) {
265 int vnslen;
266
267 if ((unsigned long)iterator->_arg + size -
268 (unsigned long)iterator->_rtheader >
269 (unsigned long)iterator->_max_length)
270 return -EINVAL;
271
272 oui = (*iterator->_arg << 16) |
273 (*(iterator->_arg + 1) << 8) |
274 *(iterator->_arg + 2);
275 subns = *(iterator->_arg + 3);
276
277 find_ns(iterator, oui, subns);
278
279 vnslen = get_unaligned_le16(iterator->_arg + 4);
280 iterator->_next_ns_data = iterator->_arg + size + vnslen;
281 if (!iterator->current_namespace)
282 size += vnslen;
283 }
284
263 /* 285 /*
264 * this is what we will return to user, but we need to 286 * this is what we will return to user, but we need to
265 * move on first so next call has something fresh to test 287 * move on first so next call has something fresh to test
@@ -286,40 +308,25 @@ int ieee80211_radiotap_iterator_next(
286 /* these special ones are valid in each bitmap word */ 308 /* these special ones are valid in each bitmap word */
287 switch (iterator->_arg_index % 32) { 309 switch (iterator->_arg_index % 32) {
288 case IEEE80211_RADIOTAP_VENDOR_NAMESPACE: 310 case IEEE80211_RADIOTAP_VENDOR_NAMESPACE:
289 iterator->_bitmap_shifter >>= 1;
290 iterator->_arg_index++;
291
292 iterator->_reset_on_ext = 1; 311 iterator->_reset_on_ext = 1;
293 312
294 vnslen = get_unaligned_le16(iterator->this_arg + 4);
295 iterator->_next_ns_data = iterator->_arg + vnslen;
296 oui = (*iterator->this_arg << 16) |
297 (*(iterator->this_arg + 1) << 8) |
298 *(iterator->this_arg + 2);
299 subns = *(iterator->this_arg + 3);
300
301 find_ns(iterator, oui, subns);
302
303 iterator->is_radiotap_ns = 0; 313 iterator->is_radiotap_ns = 0;
304 /* allow parsers to show this information */ 314 /*
315 * If parser didn't register this vendor
316 * namespace with us, allow it to show it
317 * as 'raw. Do do that, set argument index
318 * to vendor namespace.
319 */
305 iterator->this_arg_index = 320 iterator->this_arg_index =
306 IEEE80211_RADIOTAP_VENDOR_NAMESPACE; 321 IEEE80211_RADIOTAP_VENDOR_NAMESPACE;
307 iterator->this_arg_size += vnslen; 322 if (!iterator->current_namespace)
308 if ((unsigned long)iterator->this_arg + 323 hit = 1;
309 iterator->this_arg_size - 324 goto next_entry;
310 (unsigned long)iterator->_rtheader >
311 (unsigned long)(unsigned long)iterator->_max_length)
312 return -EINVAL;
313 hit = 1;
314 break;
315 case IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE: 325 case IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE:
316 iterator->_bitmap_shifter >>= 1;
317 iterator->_arg_index++;
318
319 iterator->_reset_on_ext = 1; 326 iterator->_reset_on_ext = 1;
320 iterator->current_namespace = &radiotap_ns; 327 iterator->current_namespace = &radiotap_ns;
321 iterator->is_radiotap_ns = 1; 328 iterator->is_radiotap_ns = 1;
322 break; 329 goto next_entry;
323 case IEEE80211_RADIOTAP_EXT: 330 case IEEE80211_RADIOTAP_EXT:
324 /* 331 /*
325 * bit 31 was set, there is more 332 * bit 31 was set, there is more
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index f180db0de66c..1ad0f39fe091 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -32,10 +32,14 @@
32 * rely on some SHA1 checksum of the regdomain for example. 32 * rely on some SHA1 checksum of the regdomain for example.
33 * 33 *
34 */ 34 */
35
36#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37
35#include <linux/kernel.h> 38#include <linux/kernel.h>
36#include <linux/slab.h> 39#include <linux/slab.h>
37#include <linux/list.h> 40#include <linux/list.h>
38#include <linux/random.h> 41#include <linux/random.h>
42#include <linux/ctype.h>
39#include <linux/nl80211.h> 43#include <linux/nl80211.h>
40#include <linux/platform_device.h> 44#include <linux/platform_device.h>
41#include <net/cfg80211.h> 45#include <net/cfg80211.h>
@@ -47,7 +51,7 @@
47#ifdef CONFIG_CFG80211_REG_DEBUG 51#ifdef CONFIG_CFG80211_REG_DEBUG
48#define REG_DBG_PRINT(format, args...) \ 52#define REG_DBG_PRINT(format, args...) \
49 do { \ 53 do { \
50 printk(KERN_DEBUG format , ## args); \ 54 printk(KERN_DEBUG pr_fmt(format), ##args); \
51 } while (0) 55 } while (0)
52#else 56#else
53#define REG_DBG_PRINT(args...) 57#define REG_DBG_PRINT(args...)
@@ -59,6 +63,10 @@ static struct regulatory_request *last_request;
59/* To trigger userspace events */ 63/* To trigger userspace events */
60static struct platform_device *reg_pdev; 64static struct platform_device *reg_pdev;
61 65
66static struct device_type reg_device_type = {
67 .uevent = reg_device_uevent,
68};
69
62/* 70/*
63 * Central wireless core regulatory domains, we only need two, 71 * Central wireless core regulatory domains, we only need two,
64 * the current one and a world regulatory domain in case we have no 72 * the current one and a world regulatory domain in case we have no
@@ -73,7 +81,11 @@ const struct ieee80211_regdomain *cfg80211_regdomain;
73 * - last_request 81 * - last_request
74 */ 82 */
75static DEFINE_MUTEX(reg_mutex); 83static DEFINE_MUTEX(reg_mutex);
76#define assert_reg_lock() WARN_ON(!mutex_is_locked(&reg_mutex)) 84
85static inline void assert_reg_lock(void)
86{
87 lockdep_assert_held(&reg_mutex);
88}
77 89
78/* Used to queue up regulatory hints */ 90/* Used to queue up regulatory hints */
79static LIST_HEAD(reg_requests_list); 91static LIST_HEAD(reg_requests_list);
@@ -91,6 +103,12 @@ struct reg_beacon {
91 struct ieee80211_channel chan; 103 struct ieee80211_channel chan;
92}; 104};
93 105
106static void reg_todo(struct work_struct *work);
107static DECLARE_WORK(reg_work, reg_todo);
108
109static void reg_timeout_work(struct work_struct *work);
110static DECLARE_DELAYED_WORK(reg_timeout, reg_timeout_work);
111
94/* We keep a static world regulatory domain in case of the absence of CRDA */ 112/* We keep a static world regulatory domain in case of the absence of CRDA */
95static const struct ieee80211_regdomain world_regdom = { 113static const struct ieee80211_regdomain world_regdom = {
96 .n_reg_rules = 5, 114 .n_reg_rules = 5,
@@ -181,14 +199,6 @@ static bool is_alpha2_set(const char *alpha2)
181 return false; 199 return false;
182} 200}
183 201
184static bool is_alpha_upper(char letter)
185{
186 /* ASCII A - Z */
187 if (letter >= 65 && letter <= 90)
188 return true;
189 return false;
190}
191
192static bool is_unknown_alpha2(const char *alpha2) 202static bool is_unknown_alpha2(const char *alpha2)
193{ 203{
194 if (!alpha2) 204 if (!alpha2)
@@ -220,7 +230,7 @@ static bool is_an_alpha2(const char *alpha2)
220{ 230{
221 if (!alpha2) 231 if (!alpha2)
222 return false; 232 return false;
223 if (is_alpha_upper(alpha2[0]) && is_alpha_upper(alpha2[1])) 233 if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
224 return true; 234 return true;
225 return false; 235 return false;
226} 236}
@@ -359,30 +369,21 @@ static inline void reg_regdb_query(const char *alpha2) {}
359 369
360/* 370/*
361 * This lets us keep regulatory code which is updated on a regulatory 371 * This lets us keep regulatory code which is updated on a regulatory
362 * basis in userspace. 372 * basis in userspace. Country information is filled in by
373 * reg_device_uevent
363 */ 374 */
364static int call_crda(const char *alpha2) 375static int call_crda(const char *alpha2)
365{ 376{
366 char country_env[9 + 2] = "COUNTRY=";
367 char *envp[] = {
368 country_env,
369 NULL
370 };
371
372 if (!is_world_regdom((char *) alpha2)) 377 if (!is_world_regdom((char *) alpha2))
373 printk(KERN_INFO "cfg80211: Calling CRDA for country: %c%c\n", 378 pr_info("Calling CRDA for country: %c%c\n",
374 alpha2[0], alpha2[1]); 379 alpha2[0], alpha2[1]);
375 else 380 else
376 printk(KERN_INFO "cfg80211: Calling CRDA to update world " 381 pr_info("Calling CRDA to update world regulatory domain\n");
377 "regulatory domain\n");
378 382
379 /* query internal regulatory database (if it exists) */ 383 /* query internal regulatory database (if it exists) */
380 reg_regdb_query(alpha2); 384 reg_regdb_query(alpha2);
381 385
382 country_env[8] = alpha2[0]; 386 return kobject_uevent(&reg_pdev->dev.kobj, KOBJ_CHANGE);
383 country_env[9] = alpha2[1];
384
385 return kobject_uevent_env(&reg_pdev->dev.kobj, KOBJ_CHANGE, envp);
386} 387}
387 388
388/* Used by nl80211 before kmalloc'ing our regulatory domain */ 389/* Used by nl80211 before kmalloc'ing our regulatory domain */
@@ -659,7 +660,8 @@ static int freq_reg_info_regd(struct wiphy *wiphy,
659 * Follow the driver's regulatory domain, if present, unless a country 660 * Follow the driver's regulatory domain, if present, unless a country
660 * IE has been processed or a user wants to help complaince further 661 * IE has been processed or a user wants to help complaince further
661 */ 662 */
662 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && 663 if (!custom_regd &&
664 last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
663 last_request->initiator != NL80211_REGDOM_SET_BY_USER && 665 last_request->initiator != NL80211_REGDOM_SET_BY_USER &&
664 wiphy->regd) 666 wiphy->regd)
665 regd = wiphy->regd; 667 regd = wiphy->regd;
@@ -670,11 +672,9 @@ static int freq_reg_info_regd(struct wiphy *wiphy,
670 for (i = 0; i < regd->n_reg_rules; i++) { 672 for (i = 0; i < regd->n_reg_rules; i++) {
671 const struct ieee80211_reg_rule *rr; 673 const struct ieee80211_reg_rule *rr;
672 const struct ieee80211_freq_range *fr = NULL; 674 const struct ieee80211_freq_range *fr = NULL;
673 const struct ieee80211_power_rule *pr = NULL;
674 675
675 rr = &regd->reg_rules[i]; 676 rr = &regd->reg_rules[i];
676 fr = &rr->freq_range; 677 fr = &rr->freq_range;
677 pr = &rr->power_rule;
678 678
679 /* 679 /*
680 * We only need to know if one frequency rule was 680 * We only need to know if one frequency rule was
@@ -714,6 +714,60 @@ int freq_reg_info(struct wiphy *wiphy,
714} 714}
715EXPORT_SYMBOL(freq_reg_info); 715EXPORT_SYMBOL(freq_reg_info);
716 716
717#ifdef CONFIG_CFG80211_REG_DEBUG
718static const char *reg_initiator_name(enum nl80211_reg_initiator initiator)
719{
720 switch (initiator) {
721 case NL80211_REGDOM_SET_BY_CORE:
722 return "Set by core";
723 case NL80211_REGDOM_SET_BY_USER:
724 return "Set by user";
725 case NL80211_REGDOM_SET_BY_DRIVER:
726 return "Set by driver";
727 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
728 return "Set by country IE";
729 default:
730 WARN_ON(1);
731 return "Set by bug";
732 }
733}
734
735static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan,
736 u32 desired_bw_khz,
737 const struct ieee80211_reg_rule *reg_rule)
738{
739 const struct ieee80211_power_rule *power_rule;
740 const struct ieee80211_freq_range *freq_range;
741 char max_antenna_gain[32];
742
743 power_rule = &reg_rule->power_rule;
744 freq_range = &reg_rule->freq_range;
745
746 if (!power_rule->max_antenna_gain)
747 snprintf(max_antenna_gain, 32, "N/A");
748 else
749 snprintf(max_antenna_gain, 32, "%d", power_rule->max_antenna_gain);
750
751 REG_DBG_PRINT("Updating information on frequency %d MHz "
752 "for a %d MHz width channel with regulatory rule:\n",
753 chan->center_freq,
754 KHZ_TO_MHZ(desired_bw_khz));
755
756 REG_DBG_PRINT("%d KHz - %d KHz @ KHz), (%s mBi, %d mBm)\n",
757 freq_range->start_freq_khz,
758 freq_range->end_freq_khz,
759 max_antenna_gain,
760 power_rule->max_eirp);
761}
762#else
763static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan,
764 u32 desired_bw_khz,
765 const struct ieee80211_reg_rule *reg_rule)
766{
767 return;
768}
769#endif
770
717/* 771/*
718 * Note that right now we assume the desired channel bandwidth 772 * Note that right now we assume the desired channel bandwidth
719 * is always 20 MHz for each individual channel (HT40 uses 20 MHz 773 * is always 20 MHz for each individual channel (HT40 uses 20 MHz
@@ -723,7 +777,9 @@ EXPORT_SYMBOL(freq_reg_info);
723 * on the wiphy with the target_bw specified. Then we can simply use 777 * on the wiphy with the target_bw specified. Then we can simply use
724 * that below for the desired_bw_khz below. 778 * that below for the desired_bw_khz below.
725 */ 779 */
726static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band, 780static void handle_channel(struct wiphy *wiphy,
781 enum nl80211_reg_initiator initiator,
782 enum ieee80211_band band,
727 unsigned int chan_idx) 783 unsigned int chan_idx)
728{ 784{
729 int r; 785 int r;
@@ -751,8 +807,27 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
751 desired_bw_khz, 807 desired_bw_khz,
752 &reg_rule); 808 &reg_rule);
753 809
754 if (r) 810 if (r) {
811 /*
812 * We will disable all channels that do not match our
813 * received regulatory rule unless the hint is coming
814 * from a Country IE and the Country IE had no information
815 * about a band. The IEEE 802.11 spec allows for an AP
816 * to send only a subset of the regulatory rules allowed,
817 * so an AP in the US that only supports 2.4 GHz may only send
818 * a country IE with information for the 2.4 GHz band
819 * while 5 GHz is still supported.
820 */
821 if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE &&
822 r == -ERANGE)
823 return;
824
825 REG_DBG_PRINT("Disabling freq %d MHz\n", chan->center_freq);
826 chan->flags = IEEE80211_CHAN_DISABLED;
755 return; 827 return;
828 }
829
830 chan_reg_rule_print_dbg(chan, desired_bw_khz, reg_rule);
756 831
757 power_rule = &reg_rule->power_rule; 832 power_rule = &reg_rule->power_rule;
758 freq_range = &reg_rule->freq_range; 833 freq_range = &reg_rule->freq_range;
@@ -764,7 +839,7 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
764 request_wiphy && request_wiphy == wiphy && 839 request_wiphy && request_wiphy == wiphy &&
765 request_wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) { 840 request_wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) {
766 /* 841 /*
767 * This gaurantees the driver's requested regulatory domain 842 * This guarantees the driver's requested regulatory domain
768 * will always be used as a base for further regulatory 843 * will always be used as a base for further regulatory
769 * settings 844 * settings
770 */ 845 */
@@ -787,7 +862,9 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
787 chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp); 862 chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp);
788} 863}
789 864
790static void handle_band(struct wiphy *wiphy, enum ieee80211_band band) 865static void handle_band(struct wiphy *wiphy,
866 enum ieee80211_band band,
867 enum nl80211_reg_initiator initiator)
791{ 868{
792 unsigned int i; 869 unsigned int i;
793 struct ieee80211_supported_band *sband; 870 struct ieee80211_supported_band *sband;
@@ -796,24 +873,42 @@ static void handle_band(struct wiphy *wiphy, enum ieee80211_band band)
796 sband = wiphy->bands[band]; 873 sband = wiphy->bands[band];
797 874
798 for (i = 0; i < sband->n_channels; i++) 875 for (i = 0; i < sband->n_channels; i++)
799 handle_channel(wiphy, band, i); 876 handle_channel(wiphy, initiator, band, i);
800} 877}
801 878
802static bool ignore_reg_update(struct wiphy *wiphy, 879static bool ignore_reg_update(struct wiphy *wiphy,
803 enum nl80211_reg_initiator initiator) 880 enum nl80211_reg_initiator initiator)
804{ 881{
805 if (!last_request) 882 if (!last_request) {
883 REG_DBG_PRINT("Ignoring regulatory request %s since "
884 "last_request is not set\n",
885 reg_initiator_name(initiator));
806 return true; 886 return true;
887 }
888
807 if (initiator == NL80211_REGDOM_SET_BY_CORE && 889 if (initiator == NL80211_REGDOM_SET_BY_CORE &&
808 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY) 890 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY) {
891 REG_DBG_PRINT("Ignoring regulatory request %s "
892 "since the driver uses its own custom "
893 "regulatory domain ",
894 reg_initiator_name(initiator));
809 return true; 895 return true;
896 }
897
810 /* 898 /*
811 * wiphy->regd will be set once the device has its own 899 * wiphy->regd will be set once the device has its own
812 * desired regulatory domain set 900 * desired regulatory domain set
813 */ 901 */
814 if (wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY && !wiphy->regd && 902 if (wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY && !wiphy->regd &&
815 !is_world_regdom(last_request->alpha2)) 903 initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
904 !is_world_regdom(last_request->alpha2)) {
905 REG_DBG_PRINT("Ignoring regulatory request %s "
906 "since the driver requires its own regulaotry "
907 "domain to be set first",
908 reg_initiator_name(initiator));
816 return true; 909 return true;
910 }
911
817 return false; 912 return false;
818} 913}
819 914
@@ -1033,7 +1128,7 @@ void wiphy_update_regulatory(struct wiphy *wiphy,
1033 goto out; 1128 goto out;
1034 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 1129 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1035 if (wiphy->bands[band]) 1130 if (wiphy->bands[band])
1036 handle_band(wiphy, band); 1131 handle_band(wiphy, band, initiator);
1037 } 1132 }
1038out: 1133out:
1039 reg_process_beacons(wiphy); 1134 reg_process_beacons(wiphy);
@@ -1069,10 +1164,17 @@ static void handle_channel_custom(struct wiphy *wiphy,
1069 regd); 1164 regd);
1070 1165
1071 if (r) { 1166 if (r) {
1167 REG_DBG_PRINT("Disabling freq %d MHz as custom "
1168 "regd has no rule that fits a %d MHz "
1169 "wide channel\n",
1170 chan->center_freq,
1171 KHZ_TO_MHZ(desired_bw_khz));
1072 chan->flags = IEEE80211_CHAN_DISABLED; 1172 chan->flags = IEEE80211_CHAN_DISABLED;
1073 return; 1173 return;
1074 } 1174 }
1075 1175
1176 chan_reg_rule_print_dbg(chan, desired_bw_khz, reg_rule);
1177
1076 power_rule = &reg_rule->power_rule; 1178 power_rule = &reg_rule->power_rule;
1077 freq_range = &reg_rule->freq_range; 1179 freq_range = &reg_rule->freq_range;
1078 1180
@@ -1170,7 +1272,7 @@ static int ignore_request(struct wiphy *wiphy,
1170 return 0; 1272 return 0;
1171 return -EALREADY; 1273 return -EALREADY;
1172 } 1274 }
1173 return REG_INTERSECT; 1275 return 0;
1174 case NL80211_REGDOM_SET_BY_DRIVER: 1276 case NL80211_REGDOM_SET_BY_DRIVER:
1175 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE) { 1277 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE) {
1176 if (regdom_changes(pending_request->alpha2)) 1278 if (regdom_changes(pending_request->alpha2))
@@ -1218,6 +1320,24 @@ static int ignore_request(struct wiphy *wiphy,
1218 return -EINVAL; 1320 return -EINVAL;
1219} 1321}
1220 1322
1323static void reg_set_request_processed(void)
1324{
1325 bool need_more_processing = false;
1326
1327 last_request->processed = true;
1328
1329 spin_lock(&reg_requests_lock);
1330 if (!list_empty(&reg_requests_list))
1331 need_more_processing = true;
1332 spin_unlock(&reg_requests_lock);
1333
1334 if (last_request->initiator == NL80211_REGDOM_SET_BY_USER)
1335 cancel_delayed_work_sync(&reg_timeout);
1336
1337 if (need_more_processing)
1338 schedule_work(&reg_work);
1339}
1340
1221/** 1341/**
1222 * __regulatory_hint - hint to the wireless core a regulatory domain 1342 * __regulatory_hint - hint to the wireless core a regulatory domain
1223 * @wiphy: if the hint comes from country information from an AP, this 1343 * @wiphy: if the hint comes from country information from an AP, this
@@ -1293,8 +1413,10 @@ new_request:
1293 * have applied the requested regulatory domain before we just 1413 * have applied the requested regulatory domain before we just
1294 * inform userspace we have processed the request 1414 * inform userspace we have processed the request
1295 */ 1415 */
1296 if (r == -EALREADY) 1416 if (r == -EALREADY) {
1297 nl80211_send_reg_change_event(last_request); 1417 nl80211_send_reg_change_event(last_request);
1418 reg_set_request_processed();
1419 }
1298 return r; 1420 return r;
1299 } 1421 }
1300 1422
@@ -1310,45 +1432,70 @@ static void reg_process_hint(struct regulatory_request *reg_request)
1310 1432
1311 BUG_ON(!reg_request->alpha2); 1433 BUG_ON(!reg_request->alpha2);
1312 1434
1313 mutex_lock(&cfg80211_mutex);
1314 mutex_lock(&reg_mutex);
1315
1316 if (wiphy_idx_valid(reg_request->wiphy_idx)) 1435 if (wiphy_idx_valid(reg_request->wiphy_idx))
1317 wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx); 1436 wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx);
1318 1437
1319 if (reg_request->initiator == NL80211_REGDOM_SET_BY_DRIVER && 1438 if (reg_request->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
1320 !wiphy) { 1439 !wiphy) {
1321 kfree(reg_request); 1440 kfree(reg_request);
1322 goto out; 1441 return;
1323 } 1442 }
1324 1443
1325 r = __regulatory_hint(wiphy, reg_request); 1444 r = __regulatory_hint(wiphy, reg_request);
1326 /* This is required so that the orig_* parameters are saved */ 1445 /* This is required so that the orig_* parameters are saved */
1327 if (r == -EALREADY && wiphy && 1446 if (r == -EALREADY && wiphy &&
1328 wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) 1447 wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) {
1329 wiphy_update_regulatory(wiphy, initiator); 1448 wiphy_update_regulatory(wiphy, initiator);
1330out: 1449 return;
1331 mutex_unlock(&reg_mutex); 1450 }
1332 mutex_unlock(&cfg80211_mutex); 1451
1452 /*
1453 * We only time out user hints, given that they should be the only
1454 * source of bogus requests.
1455 */
1456 if (r != -EALREADY &&
1457 reg_request->initiator == NL80211_REGDOM_SET_BY_USER)
1458 schedule_delayed_work(&reg_timeout, msecs_to_jiffies(3142));
1333} 1459}
1334 1460
1335/* Processes regulatory hints, this is all the NL80211_REGDOM_SET_BY_* */ 1461/*
1462 * Processes regulatory hints, this is all the NL80211_REGDOM_SET_BY_*
1463 * Regulatory hints come on a first come first serve basis and we
1464 * must process each one atomically.
1465 */
1336static void reg_process_pending_hints(void) 1466static void reg_process_pending_hints(void)
1337 { 1467{
1338 struct regulatory_request *reg_request; 1468 struct regulatory_request *reg_request;
1339 1469
1470 mutex_lock(&cfg80211_mutex);
1471 mutex_lock(&reg_mutex);
1472
1473 /* When last_request->processed becomes true this will be rescheduled */
1474 if (last_request && !last_request->processed) {
1475 REG_DBG_PRINT("Pending regulatory request, waiting "
1476 "for it to be processed...");
1477 goto out;
1478 }
1479
1340 spin_lock(&reg_requests_lock); 1480 spin_lock(&reg_requests_lock);
1341 while (!list_empty(&reg_requests_list)) {
1342 reg_request = list_first_entry(&reg_requests_list,
1343 struct regulatory_request,
1344 list);
1345 list_del_init(&reg_request->list);
1346 1481
1482 if (list_empty(&reg_requests_list)) {
1347 spin_unlock(&reg_requests_lock); 1483 spin_unlock(&reg_requests_lock);
1348 reg_process_hint(reg_request); 1484 goto out;
1349 spin_lock(&reg_requests_lock);
1350 } 1485 }
1486
1487 reg_request = list_first_entry(&reg_requests_list,
1488 struct regulatory_request,
1489 list);
1490 list_del_init(&reg_request->list);
1491
1351 spin_unlock(&reg_requests_lock); 1492 spin_unlock(&reg_requests_lock);
1493
1494 reg_process_hint(reg_request);
1495
1496out:
1497 mutex_unlock(&reg_mutex);
1498 mutex_unlock(&cfg80211_mutex);
1352} 1499}
1353 1500
1354/* Processes beacon hints -- this has nothing to do with country IEs */ 1501/* Processes beacon hints -- this has nothing to do with country IEs */
@@ -1395,10 +1542,13 @@ static void reg_todo(struct work_struct *work)
1395 reg_process_pending_beacon_hints(); 1542 reg_process_pending_beacon_hints();
1396} 1543}
1397 1544
1398static DECLARE_WORK(reg_work, reg_todo);
1399
1400static void queue_regulatory_request(struct regulatory_request *request) 1545static void queue_regulatory_request(struct regulatory_request *request)
1401{ 1546{
1547 if (isalpha(request->alpha2[0]))
1548 request->alpha2[0] = toupper(request->alpha2[0]);
1549 if (isalpha(request->alpha2[1]))
1550 request->alpha2[1] = toupper(request->alpha2[1]);
1551
1402 spin_lock(&reg_requests_lock); 1552 spin_lock(&reg_requests_lock);
1403 list_add_tail(&request->list, &reg_requests_list); 1553 list_add_tail(&request->list, &reg_requests_list);
1404 spin_unlock(&reg_requests_lock); 1554 spin_unlock(&reg_requests_lock);
@@ -1426,12 +1576,7 @@ static int regulatory_hint_core(const char *alpha2)
1426 request->alpha2[1] = alpha2[1]; 1576 request->alpha2[1] = alpha2[1];
1427 request->initiator = NL80211_REGDOM_SET_BY_CORE; 1577 request->initiator = NL80211_REGDOM_SET_BY_CORE;
1428 1578
1429 /* 1579 queue_regulatory_request(request);
1430 * This ensures last_request is populated once modules
1431 * come swinging in and calling regulatory hints and
1432 * wiphy_apply_custom_regulatory().
1433 */
1434 reg_process_hint(request);
1435 1580
1436 return 0; 1581 return 0;
1437} 1582}
@@ -1557,7 +1702,7 @@ static void restore_alpha2(char *alpha2, bool reset_user)
1557 if (is_user_regdom_saved()) { 1702 if (is_user_regdom_saved()) {
1558 /* Unless we're asked to ignore it and reset it */ 1703 /* Unless we're asked to ignore it and reset it */
1559 if (reset_user) { 1704 if (reset_user) {
1560 REG_DBG_PRINT("cfg80211: Restoring regulatory settings " 1705 REG_DBG_PRINT("Restoring regulatory settings "
1561 "including user preference\n"); 1706 "including user preference\n");
1562 user_alpha2[0] = '9'; 1707 user_alpha2[0] = '9';
1563 user_alpha2[1] = '7'; 1708 user_alpha2[1] = '7';
@@ -1568,7 +1713,7 @@ static void restore_alpha2(char *alpha2, bool reset_user)
1568 * back as they were for a full restore. 1713 * back as they were for a full restore.
1569 */ 1714 */
1570 if (!is_world_regdom(ieee80211_regdom)) { 1715 if (!is_world_regdom(ieee80211_regdom)) {
1571 REG_DBG_PRINT("cfg80211: Keeping preference on " 1716 REG_DBG_PRINT("Keeping preference on "
1572 "module parameter ieee80211_regdom: %c%c\n", 1717 "module parameter ieee80211_regdom: %c%c\n",
1573 ieee80211_regdom[0], 1718 ieee80211_regdom[0],
1574 ieee80211_regdom[1]); 1719 ieee80211_regdom[1]);
@@ -1576,7 +1721,7 @@ static void restore_alpha2(char *alpha2, bool reset_user)
1576 alpha2[1] = ieee80211_regdom[1]; 1721 alpha2[1] = ieee80211_regdom[1];
1577 } 1722 }
1578 } else { 1723 } else {
1579 REG_DBG_PRINT("cfg80211: Restoring regulatory settings " 1724 REG_DBG_PRINT("Restoring regulatory settings "
1580 "while preserving user preference for: %c%c\n", 1725 "while preserving user preference for: %c%c\n",
1581 user_alpha2[0], 1726 user_alpha2[0],
1582 user_alpha2[1]); 1727 user_alpha2[1]);
@@ -1584,14 +1729,14 @@ static void restore_alpha2(char *alpha2, bool reset_user)
1584 alpha2[1] = user_alpha2[1]; 1729 alpha2[1] = user_alpha2[1];
1585 } 1730 }
1586 } else if (!is_world_regdom(ieee80211_regdom)) { 1731 } else if (!is_world_regdom(ieee80211_regdom)) {
1587 REG_DBG_PRINT("cfg80211: Keeping preference on " 1732 REG_DBG_PRINT("Keeping preference on "
1588 "module parameter ieee80211_regdom: %c%c\n", 1733 "module parameter ieee80211_regdom: %c%c\n",
1589 ieee80211_regdom[0], 1734 ieee80211_regdom[0],
1590 ieee80211_regdom[1]); 1735 ieee80211_regdom[1]);
1591 alpha2[0] = ieee80211_regdom[0]; 1736 alpha2[0] = ieee80211_regdom[0];
1592 alpha2[1] = ieee80211_regdom[1]; 1737 alpha2[1] = ieee80211_regdom[1];
1593 } else 1738 } else
1594 REG_DBG_PRINT("cfg80211: Restoring regulatory settings\n"); 1739 REG_DBG_PRINT("Restoring regulatory settings\n");
1595} 1740}
1596 1741
1597/* 1742/*
@@ -1613,6 +1758,8 @@ static void restore_regulatory_settings(bool reset_user)
1613{ 1758{
1614 char alpha2[2]; 1759 char alpha2[2];
1615 struct reg_beacon *reg_beacon, *btmp; 1760 struct reg_beacon *reg_beacon, *btmp;
1761 struct regulatory_request *reg_request, *tmp;
1762 LIST_HEAD(tmp_reg_req_list);
1616 1763
1617 mutex_lock(&cfg80211_mutex); 1764 mutex_lock(&cfg80211_mutex);
1618 mutex_lock(&reg_mutex); 1765 mutex_lock(&reg_mutex);
@@ -1620,6 +1767,25 @@ static void restore_regulatory_settings(bool reset_user)
1620 reset_regdomains(); 1767 reset_regdomains();
1621 restore_alpha2(alpha2, reset_user); 1768 restore_alpha2(alpha2, reset_user);
1622 1769
1770 /*
1771 * If there's any pending requests we simply
1772 * stash them to a temporary pending queue and
1773 * add then after we've restored regulatory
1774 * settings.
1775 */
1776 spin_lock(&reg_requests_lock);
1777 if (!list_empty(&reg_requests_list)) {
1778 list_for_each_entry_safe(reg_request, tmp,
1779 &reg_requests_list, list) {
1780 if (reg_request->initiator !=
1781 NL80211_REGDOM_SET_BY_USER)
1782 continue;
1783 list_del(&reg_request->list);
1784 list_add_tail(&reg_request->list, &tmp_reg_req_list);
1785 }
1786 }
1787 spin_unlock(&reg_requests_lock);
1788
1623 /* Clear beacon hints */ 1789 /* Clear beacon hints */
1624 spin_lock_bh(&reg_pending_beacons_lock); 1790 spin_lock_bh(&reg_pending_beacons_lock);
1625 if (!list_empty(&reg_pending_beacons)) { 1791 if (!list_empty(&reg_pending_beacons)) {
@@ -1654,21 +1820,44 @@ static void restore_regulatory_settings(bool reset_user)
1654 */ 1820 */
1655 if (is_an_alpha2(alpha2)) 1821 if (is_an_alpha2(alpha2))
1656 regulatory_hint_user(user_alpha2); 1822 regulatory_hint_user(user_alpha2);
1657}
1658 1823
1824 if (list_empty(&tmp_reg_req_list))
1825 return;
1826
1827 mutex_lock(&cfg80211_mutex);
1828 mutex_lock(&reg_mutex);
1829
1830 spin_lock(&reg_requests_lock);
1831 list_for_each_entry_safe(reg_request, tmp, &tmp_reg_req_list, list) {
1832 REG_DBG_PRINT("Adding request for country %c%c back "
1833 "into the queue\n",
1834 reg_request->alpha2[0],
1835 reg_request->alpha2[1]);
1836 list_del(&reg_request->list);
1837 list_add_tail(&reg_request->list, &reg_requests_list);
1838 }
1839 spin_unlock(&reg_requests_lock);
1840
1841 mutex_unlock(&reg_mutex);
1842 mutex_unlock(&cfg80211_mutex);
1843
1844 REG_DBG_PRINT("Kicking the queue\n");
1845
1846 schedule_work(&reg_work);
1847}
1659 1848
1660void regulatory_hint_disconnect(void) 1849void regulatory_hint_disconnect(void)
1661{ 1850{
1662 REG_DBG_PRINT("cfg80211: All devices are disconnected, going to " 1851 REG_DBG_PRINT("All devices are disconnected, going to "
1663 "restore regulatory settings\n"); 1852 "restore regulatory settings\n");
1664 restore_regulatory_settings(false); 1853 restore_regulatory_settings(false);
1665} 1854}
1666 1855
1667static bool freq_is_chan_12_13_14(u16 freq) 1856static bool freq_is_chan_12_13_14(u16 freq)
1668{ 1857{
1669 if (freq == ieee80211_channel_to_frequency(12) || 1858 if (freq == ieee80211_channel_to_frequency(12, IEEE80211_BAND_2GHZ) ||
1670 freq == ieee80211_channel_to_frequency(13) || 1859 freq == ieee80211_channel_to_frequency(13, IEEE80211_BAND_2GHZ) ||
1671 freq == ieee80211_channel_to_frequency(14)) 1860 freq == ieee80211_channel_to_frequency(14, IEEE80211_BAND_2GHZ))
1672 return true; 1861 return true;
1673 return false; 1862 return false;
1674} 1863}
@@ -1689,7 +1878,7 @@ int regulatory_hint_found_beacon(struct wiphy *wiphy,
1689 if (!reg_beacon) 1878 if (!reg_beacon)
1690 return -ENOMEM; 1879 return -ENOMEM;
1691 1880
1692 REG_DBG_PRINT("cfg80211: Found new beacon on " 1881 REG_DBG_PRINT("Found new beacon on "
1693 "frequency: %d MHz (Ch %d) on %s\n", 1882 "frequency: %d MHz (Ch %d) on %s\n",
1694 beacon_chan->center_freq, 1883 beacon_chan->center_freq,
1695 ieee80211_frequency_to_channel(beacon_chan->center_freq), 1884 ieee80211_frequency_to_channel(beacon_chan->center_freq),
@@ -1719,8 +1908,7 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
1719 const struct ieee80211_freq_range *freq_range = NULL; 1908 const struct ieee80211_freq_range *freq_range = NULL;
1720 const struct ieee80211_power_rule *power_rule = NULL; 1909 const struct ieee80211_power_rule *power_rule = NULL;
1721 1910
1722 printk(KERN_INFO " (start_freq - end_freq @ bandwidth), " 1911 pr_info(" (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)\n");
1723 "(max_antenna_gain, max_eirp)\n");
1724 1912
1725 for (i = 0; i < rd->n_reg_rules; i++) { 1913 for (i = 0; i < rd->n_reg_rules; i++) {
1726 reg_rule = &rd->reg_rules[i]; 1914 reg_rule = &rd->reg_rules[i];
@@ -1732,16 +1920,14 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
1732 * in certain regions 1920 * in certain regions
1733 */ 1921 */
1734 if (power_rule->max_antenna_gain) 1922 if (power_rule->max_antenna_gain)
1735 printk(KERN_INFO " (%d KHz - %d KHz @ %d KHz), " 1923 pr_info(" (%d KHz - %d KHz @ %d KHz), (%d mBi, %d mBm)\n",
1736 "(%d mBi, %d mBm)\n",
1737 freq_range->start_freq_khz, 1924 freq_range->start_freq_khz,
1738 freq_range->end_freq_khz, 1925 freq_range->end_freq_khz,
1739 freq_range->max_bandwidth_khz, 1926 freq_range->max_bandwidth_khz,
1740 power_rule->max_antenna_gain, 1927 power_rule->max_antenna_gain,
1741 power_rule->max_eirp); 1928 power_rule->max_eirp);
1742 else 1929 else
1743 printk(KERN_INFO " (%d KHz - %d KHz @ %d KHz), " 1930 pr_info(" (%d KHz - %d KHz @ %d KHz), (N/A, %d mBm)\n",
1744 "(N/A, %d mBm)\n",
1745 freq_range->start_freq_khz, 1931 freq_range->start_freq_khz,
1746 freq_range->end_freq_khz, 1932 freq_range->end_freq_khz,
1747 freq_range->max_bandwidth_khz, 1933 freq_range->max_bandwidth_khz,
@@ -1760,27 +1946,20 @@ static void print_regdomain(const struct ieee80211_regdomain *rd)
1760 rdev = cfg80211_rdev_by_wiphy_idx( 1946 rdev = cfg80211_rdev_by_wiphy_idx(
1761 last_request->wiphy_idx); 1947 last_request->wiphy_idx);
1762 if (rdev) { 1948 if (rdev) {
1763 printk(KERN_INFO "cfg80211: Current regulatory " 1949 pr_info("Current regulatory domain updated by AP to: %c%c\n",
1764 "domain updated by AP to: %c%c\n",
1765 rdev->country_ie_alpha2[0], 1950 rdev->country_ie_alpha2[0],
1766 rdev->country_ie_alpha2[1]); 1951 rdev->country_ie_alpha2[1]);
1767 } else 1952 } else
1768 printk(KERN_INFO "cfg80211: Current regulatory " 1953 pr_info("Current regulatory domain intersected:\n");
1769 "domain intersected:\n");
1770 } else 1954 } else
1771 printk(KERN_INFO "cfg80211: Current regulatory " 1955 pr_info("Current regulatory domain intersected:\n");
1772 "domain intersected:\n");
1773 } else if (is_world_regdom(rd->alpha2)) 1956 } else if (is_world_regdom(rd->alpha2))
1774 printk(KERN_INFO "cfg80211: World regulatory " 1957 pr_info("World regulatory domain updated:\n");
1775 "domain updated:\n");
1776 else { 1958 else {
1777 if (is_unknown_alpha2(rd->alpha2)) 1959 if (is_unknown_alpha2(rd->alpha2))
1778 printk(KERN_INFO "cfg80211: Regulatory domain " 1960 pr_info("Regulatory domain changed to driver built-in settings (unknown country)\n");
1779 "changed to driver built-in settings "
1780 "(unknown country)\n");
1781 else 1961 else
1782 printk(KERN_INFO "cfg80211: Regulatory domain " 1962 pr_info("Regulatory domain changed to country: %c%c\n",
1783 "changed to country: %c%c\n",
1784 rd->alpha2[0], rd->alpha2[1]); 1963 rd->alpha2[0], rd->alpha2[1]);
1785 } 1964 }
1786 print_rd_rules(rd); 1965 print_rd_rules(rd);
@@ -1788,8 +1967,7 @@ static void print_regdomain(const struct ieee80211_regdomain *rd)
1788 1967
1789static void print_regdomain_info(const struct ieee80211_regdomain *rd) 1968static void print_regdomain_info(const struct ieee80211_regdomain *rd)
1790{ 1969{
1791 printk(KERN_INFO "cfg80211: Regulatory domain: %c%c\n", 1970 pr_info("Regulatory domain: %c%c\n", rd->alpha2[0], rd->alpha2[1]);
1792 rd->alpha2[0], rd->alpha2[1]);
1793 print_rd_rules(rd); 1971 print_rd_rules(rd);
1794} 1972}
1795 1973
@@ -1840,8 +2018,7 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
1840 return -EINVAL; 2018 return -EINVAL;
1841 2019
1842 if (!is_valid_rd(rd)) { 2020 if (!is_valid_rd(rd)) {
1843 printk(KERN_ERR "cfg80211: Invalid " 2021 pr_err("Invalid regulatory domain detected:\n");
1844 "regulatory domain detected:\n");
1845 print_regdomain_info(rd); 2022 print_regdomain_info(rd);
1846 return -EINVAL; 2023 return -EINVAL;
1847 } 2024 }
@@ -1957,11 +2134,32 @@ int set_regdom(const struct ieee80211_regdomain *rd)
1957 2134
1958 nl80211_send_reg_change_event(last_request); 2135 nl80211_send_reg_change_event(last_request);
1959 2136
2137 reg_set_request_processed();
2138
1960 mutex_unlock(&reg_mutex); 2139 mutex_unlock(&reg_mutex);
1961 2140
1962 return r; 2141 return r;
1963} 2142}
1964 2143
2144#ifdef CONFIG_HOTPLUG
2145int reg_device_uevent(struct device *dev, struct kobj_uevent_env *env)
2146{
2147 if (last_request && !last_request->processed) {
2148 if (add_uevent_var(env, "COUNTRY=%c%c",
2149 last_request->alpha2[0],
2150 last_request->alpha2[1]))
2151 return -ENOMEM;
2152 }
2153
2154 return 0;
2155}
2156#else
2157int reg_device_uevent(struct device *dev, struct kobj_uevent_env *env)
2158{
2159 return -ENODEV;
2160}
2161#endif /* CONFIG_HOTPLUG */
2162
1965/* Caller must hold cfg80211_mutex */ 2163/* Caller must hold cfg80211_mutex */
1966void reg_device_remove(struct wiphy *wiphy) 2164void reg_device_remove(struct wiphy *wiphy)
1967{ 2165{
@@ -1985,6 +2183,13 @@ out:
1985 mutex_unlock(&reg_mutex); 2183 mutex_unlock(&reg_mutex);
1986} 2184}
1987 2185
2186static void reg_timeout_work(struct work_struct *work)
2187{
2188 REG_DBG_PRINT("Timeout while waiting for CRDA to reply, "
2189 "restoring regulatory settings");
2190 restore_regulatory_settings(true);
2191}
2192
1988int __init regulatory_init(void) 2193int __init regulatory_init(void)
1989{ 2194{
1990 int err = 0; 2195 int err = 0;
@@ -1993,6 +2198,8 @@ int __init regulatory_init(void)
1993 if (IS_ERR(reg_pdev)) 2198 if (IS_ERR(reg_pdev))
1994 return PTR_ERR(reg_pdev); 2199 return PTR_ERR(reg_pdev);
1995 2200
2201 reg_pdev->dev.type = &reg_device_type;
2202
1996 spin_lock_init(&reg_requests_lock); 2203 spin_lock_init(&reg_requests_lock);
1997 spin_lock_init(&reg_pending_beacons_lock); 2204 spin_lock_init(&reg_pending_beacons_lock);
1998 2205
@@ -2013,8 +2220,7 @@ int __init regulatory_init(void)
2013 * early boot for call_usermodehelper(). For now treat these 2220 * early boot for call_usermodehelper(). For now treat these
2014 * errors as non-fatal. 2221 * errors as non-fatal.
2015 */ 2222 */
2016 printk(KERN_ERR "cfg80211: kobject_uevent_env() was unable " 2223 pr_err("kobject_uevent_env() was unable to call CRDA during init\n");
2017 "to call CRDA during init");
2018#ifdef CONFIG_CFG80211_REG_DEBUG 2224#ifdef CONFIG_CFG80211_REG_DEBUG
2019 /* We want to find out exactly why when debugging */ 2225 /* We want to find out exactly why when debugging */
2020 WARN_ON(err); 2226 WARN_ON(err);
@@ -2037,6 +2243,7 @@ void /* __init_or_exit */ regulatory_exit(void)
2037 struct reg_beacon *reg_beacon, *btmp; 2243 struct reg_beacon *reg_beacon, *btmp;
2038 2244
2039 cancel_work_sync(&reg_work); 2245 cancel_work_sync(&reg_work);
2246 cancel_delayed_work_sync(&reg_timeout);
2040 2247
2041 mutex_lock(&cfg80211_mutex); 2248 mutex_lock(&cfg80211_mutex);
2042 mutex_lock(&reg_mutex); 2249 mutex_lock(&reg_mutex);
diff --git a/net/wireless/reg.h b/net/wireless/reg.h
index c4695d07af23..b67d1c3a2fb9 100644
--- a/net/wireless/reg.h
+++ b/net/wireless/reg.h
@@ -8,6 +8,7 @@ bool reg_is_valid_request(const char *alpha2);
8 8
9int regulatory_hint_user(const char *alpha2); 9int regulatory_hint_user(const char *alpha2);
10 10
11int reg_device_uevent(struct device *dev, struct kobj_uevent_env *env);
11void reg_device_remove(struct wiphy *wiphy); 12void reg_device_remove(struct wiphy *wiphy);
12 13
13int __init regulatory_init(void); 14int __init regulatory_init(void);
diff --git a/net/wireless/scan.c b/net/wireless/scan.c
index 5ca8c7180141..ae0c2256ba3b 100644
--- a/net/wireless/scan.c
+++ b/net/wireless/scan.c
@@ -93,6 +93,69 @@ void cfg80211_scan_done(struct cfg80211_scan_request *request, bool aborted)
93} 93}
94EXPORT_SYMBOL(cfg80211_scan_done); 94EXPORT_SYMBOL(cfg80211_scan_done);
95 95
96void __cfg80211_sched_scan_results(struct work_struct *wk)
97{
98 struct cfg80211_registered_device *rdev;
99
100 rdev = container_of(wk, struct cfg80211_registered_device,
101 sched_scan_results_wk);
102
103 mutex_lock(&rdev->sched_scan_mtx);
104
105 /* we don't have sched_scan_req anymore if the scan is stopping */
106 if (rdev->sched_scan_req)
107 nl80211_send_sched_scan_results(rdev,
108 rdev->sched_scan_req->dev);
109
110 mutex_unlock(&rdev->sched_scan_mtx);
111}
112
113void cfg80211_sched_scan_results(struct wiphy *wiphy)
114{
115 /* ignore if we're not scanning */
116 if (wiphy_to_dev(wiphy)->sched_scan_req)
117 queue_work(cfg80211_wq,
118 &wiphy_to_dev(wiphy)->sched_scan_results_wk);
119}
120EXPORT_SYMBOL(cfg80211_sched_scan_results);
121
122void cfg80211_sched_scan_stopped(struct wiphy *wiphy)
123{
124 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
125
126 mutex_lock(&rdev->sched_scan_mtx);
127 __cfg80211_stop_sched_scan(rdev, true);
128 mutex_unlock(&rdev->sched_scan_mtx);
129}
130EXPORT_SYMBOL(cfg80211_sched_scan_stopped);
131
132int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
133 bool driver_initiated)
134{
135 int err;
136 struct net_device *dev;
137
138 lockdep_assert_held(&rdev->sched_scan_mtx);
139
140 if (!rdev->sched_scan_req)
141 return 0;
142
143 dev = rdev->sched_scan_req->dev;
144
145 if (!driver_initiated) {
146 err = rdev->ops->sched_scan_stop(&rdev->wiphy, dev);
147 if (err)
148 return err;
149 }
150
151 nl80211_send_sched_scan(rdev, dev, NL80211_CMD_SCHED_SCAN_STOPPED);
152
153 kfree(rdev->sched_scan_req);
154 rdev->sched_scan_req = NULL;
155
156 return err;
157}
158
96static void bss_release(struct kref *ref) 159static void bss_release(struct kref *ref)
97{ 160{
98 struct cfg80211_internal_bss *bss; 161 struct cfg80211_internal_bss *bss;
@@ -124,6 +187,15 @@ void cfg80211_bss_age(struct cfg80211_registered_device *dev,
124} 187}
125 188
126/* must hold dev->bss_lock! */ 189/* must hold dev->bss_lock! */
190static void __cfg80211_unlink_bss(struct cfg80211_registered_device *dev,
191 struct cfg80211_internal_bss *bss)
192{
193 list_del_init(&bss->list);
194 rb_erase(&bss->rbn, &dev->bss_tree);
195 kref_put(&bss->ref, bss_release);
196}
197
198/* must hold dev->bss_lock! */
127void cfg80211_bss_expire(struct cfg80211_registered_device *dev) 199void cfg80211_bss_expire(struct cfg80211_registered_device *dev)
128{ 200{
129 struct cfg80211_internal_bss *bss, *tmp; 201 struct cfg80211_internal_bss *bss, *tmp;
@@ -134,9 +206,7 @@ void cfg80211_bss_expire(struct cfg80211_registered_device *dev)
134 continue; 206 continue;
135 if (!time_after(jiffies, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE)) 207 if (!time_after(jiffies, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE))
136 continue; 208 continue;
137 list_del(&bss->list); 209 __cfg80211_unlink_bss(dev, bss);
138 rb_erase(&bss->rbn, &dev->bss_tree);
139 kref_put(&bss->ref, bss_release);
140 expired = true; 210 expired = true;
141 } 211 }
142 212
@@ -197,13 +267,35 @@ static bool is_bss(struct cfg80211_bss *a,
197 return memcmp(ssidie + 2, ssid, ssid_len) == 0; 267 return memcmp(ssidie + 2, ssid, ssid_len) == 0;
198} 268}
199 269
270static bool is_mesh_bss(struct cfg80211_bss *a)
271{
272 const u8 *ie;
273
274 if (!WLAN_CAPABILITY_IS_STA_BSS(a->capability))
275 return false;
276
277 ie = cfg80211_find_ie(WLAN_EID_MESH_ID,
278 a->information_elements,
279 a->len_information_elements);
280 if (!ie)
281 return false;
282
283 ie = cfg80211_find_ie(WLAN_EID_MESH_CONFIG,
284 a->information_elements,
285 a->len_information_elements);
286 if (!ie)
287 return false;
288
289 return true;
290}
291
200static bool is_mesh(struct cfg80211_bss *a, 292static bool is_mesh(struct cfg80211_bss *a,
201 const u8 *meshid, size_t meshidlen, 293 const u8 *meshid, size_t meshidlen,
202 const u8 *meshcfg) 294 const u8 *meshcfg)
203{ 295{
204 const u8 *ie; 296 const u8 *ie;
205 297
206 if (!is_zero_ether_addr(a->bssid)) 298 if (!WLAN_CAPABILITY_IS_STA_BSS(a->capability))
207 return false; 299 return false;
208 300
209 ie = cfg80211_find_ie(WLAN_EID_MESH_ID, 301 ie = cfg80211_find_ie(WLAN_EID_MESH_ID,
@@ -241,11 +333,7 @@ static int cmp_bss(struct cfg80211_bss *a,
241 if (a->channel != b->channel) 333 if (a->channel != b->channel)
242 return b->channel->center_freq - a->channel->center_freq; 334 return b->channel->center_freq - a->channel->center_freq;
243 335
244 r = memcmp(a->bssid, b->bssid, ETH_ALEN); 336 if (is_mesh_bss(a) && is_mesh_bss(b)) {
245 if (r)
246 return r;
247
248 if (is_zero_ether_addr(a->bssid)) {
249 r = cmp_ies(WLAN_EID_MESH_ID, 337 r = cmp_ies(WLAN_EID_MESH_ID,
250 a->information_elements, 338 a->information_elements,
251 a->len_information_elements, 339 a->len_information_elements,
@@ -260,6 +348,10 @@ static int cmp_bss(struct cfg80211_bss *a,
260 b->len_information_elements); 348 b->len_information_elements);
261 } 349 }
262 350
351 r = memcmp(a->bssid, b->bssid, ETH_ALEN);
352 if (r)
353 return r;
354
263 return cmp_ies(WLAN_EID_SSID, 355 return cmp_ies(WLAN_EID_SSID,
264 a->information_elements, 356 a->information_elements,
265 a->len_information_elements, 357 a->len_information_elements,
@@ -387,7 +479,6 @@ cfg80211_bss_update(struct cfg80211_registered_device *dev,
387 struct cfg80211_internal_bss *res) 479 struct cfg80211_internal_bss *res)
388{ 480{
389 struct cfg80211_internal_bss *found = NULL; 481 struct cfg80211_internal_bss *found = NULL;
390 const u8 *meshid, *meshcfg;
391 482
392 /* 483 /*
393 * The reference to "res" is donated to this function. 484 * The reference to "res" is donated to this function.
@@ -400,22 +491,6 @@ cfg80211_bss_update(struct cfg80211_registered_device *dev,
400 491
401 res->ts = jiffies; 492 res->ts = jiffies;
402 493
403 if (is_zero_ether_addr(res->pub.bssid)) {
404 /* must be mesh, verify */
405 meshid = cfg80211_find_ie(WLAN_EID_MESH_ID,
406 res->pub.information_elements,
407 res->pub.len_information_elements);
408 meshcfg = cfg80211_find_ie(WLAN_EID_MESH_CONFIG,
409 res->pub.information_elements,
410 res->pub.len_information_elements);
411 if (!meshid || !meshcfg ||
412 meshcfg[1] != sizeof(struct ieee80211_meshconf_ie)) {
413 /* bogus mesh */
414 kref_put(&res->ref, bss_release);
415 return NULL;
416 }
417 }
418
419 spin_lock_bh(&dev->bss_lock); 494 spin_lock_bh(&dev->bss_lock);
420 495
421 found = rb_find_bss(dev, res); 496 found = rb_find_bss(dev, res);
@@ -464,6 +539,9 @@ cfg80211_bss_update(struct cfg80211_registered_device *dev,
464 if (res->pub.beacon_ies) { 539 if (res->pub.beacon_ies) {
465 size_t used = dev->wiphy.bss_priv_size + sizeof(*res); 540 size_t used = dev->wiphy.bss_priv_size + sizeof(*res);
466 size_t ielen = res->pub.len_beacon_ies; 541 size_t ielen = res->pub.len_beacon_ies;
542 bool information_elements_is_beacon_ies =
543 (found->pub.information_elements ==
544 found->pub.beacon_ies);
467 545
468 if (found->pub.beacon_ies && 546 if (found->pub.beacon_ies &&
469 !found->beacon_ies_allocated && 547 !found->beacon_ies_allocated &&
@@ -487,6 +565,14 @@ cfg80211_bss_update(struct cfg80211_registered_device *dev,
487 found->pub.len_beacon_ies = ielen; 565 found->pub.len_beacon_ies = ielen;
488 } 566 }
489 } 567 }
568
569 /* Override IEs if they were from a beacon before */
570 if (information_elements_is_beacon_ies) {
571 found->pub.information_elements =
572 found->pub.beacon_ies;
573 found->pub.len_information_elements =
574 found->pub.len_beacon_ies;
575 }
490 } 576 }
491 577
492 kref_put(&res->ref, bss_release); 578 kref_put(&res->ref, bss_release);
@@ -574,16 +660,23 @@ cfg80211_inform_bss_frame(struct wiphy *wiphy,
574 struct cfg80211_internal_bss *res; 660 struct cfg80211_internal_bss *res;
575 size_t ielen = len - offsetof(struct ieee80211_mgmt, 661 size_t ielen = len - offsetof(struct ieee80211_mgmt,
576 u.probe_resp.variable); 662 u.probe_resp.variable);
577 size_t privsz = wiphy->bss_priv_size; 663 size_t privsz;
664
665 if (WARN_ON(!mgmt))
666 return NULL;
667
668 if (WARN_ON(!wiphy))
669 return NULL;
578 670
579 if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC && 671 if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC &&
580 (signal < 0 || signal > 100))) 672 (signal < 0 || signal > 100)))
581 return NULL; 673 return NULL;
582 674
583 if (WARN_ON(!mgmt || !wiphy || 675 if (WARN_ON(len < offsetof(struct ieee80211_mgmt, u.probe_resp.variable)))
584 len < offsetof(struct ieee80211_mgmt, u.probe_resp.variable)))
585 return NULL; 676 return NULL;
586 677
678 privsz = wiphy->bss_priv_size;
679
587 res = kzalloc(sizeof(*res) + privsz + ielen, gfp); 680 res = kzalloc(sizeof(*res) + privsz + ielen, gfp);
588 if (!res) 681 if (!res)
589 return NULL; 682 return NULL;
@@ -650,14 +743,11 @@ void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
650 bss = container_of(pub, struct cfg80211_internal_bss, pub); 743 bss = container_of(pub, struct cfg80211_internal_bss, pub);
651 744
652 spin_lock_bh(&dev->bss_lock); 745 spin_lock_bh(&dev->bss_lock);
653 746 if (!list_empty(&bss->list)) {
654 list_del(&bss->list); 747 __cfg80211_unlink_bss(dev, bss);
655 dev->bss_generation++; 748 dev->bss_generation++;
656 rb_erase(&bss->rbn, &dev->bss_tree); 749 }
657
658 spin_unlock_bh(&dev->bss_lock); 750 spin_unlock_bh(&dev->bss_lock);
659
660 kref_put(&bss->ref, bss_release);
661} 751}
662EXPORT_SYMBOL(cfg80211_unlink_bss); 752EXPORT_SYMBOL(cfg80211_unlink_bss);
663 753
diff --git a/net/wireless/sme.c b/net/wireless/sme.c
index a8c2d6b877ae..b7b6ff8be553 100644
--- a/net/wireless/sme.c
+++ b/net/wireless/sme.c
@@ -250,7 +250,8 @@ static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev)
250 if (wdev->conn->params.privacy) 250 if (wdev->conn->params.privacy)
251 capa |= WLAN_CAPABILITY_PRIVACY; 251 capa |= WLAN_CAPABILITY_PRIVACY;
252 252
253 bss = cfg80211_get_bss(wdev->wiphy, NULL, wdev->conn->params.bssid, 253 bss = cfg80211_get_bss(wdev->wiphy, wdev->conn->params.channel,
254 wdev->conn->params.bssid,
254 wdev->conn->params.ssid, 255 wdev->conn->params.ssid,
255 wdev->conn->params.ssid_len, 256 wdev->conn->params.ssid_len,
256 WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY, 257 WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY,
@@ -411,7 +412,8 @@ void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
411 412
412 ASSERT_WDEV_LOCK(wdev); 413 ASSERT_WDEV_LOCK(wdev);
413 414
414 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) 415 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
416 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
415 return; 417 return;
416 418
417 if (wdev->sme_state != CFG80211_SME_CONNECTING) 419 if (wdev->sme_state != CFG80211_SME_CONNECTING)
@@ -469,7 +471,10 @@ void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
469 } 471 }
470 472
471 if (!bss) 473 if (!bss)
472 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, 474 bss = cfg80211_get_bss(wdev->wiphy,
475 wdev->conn ? wdev->conn->params.channel :
476 NULL,
477 bssid,
473 wdev->ssid, wdev->ssid_len, 478 wdev->ssid, wdev->ssid_len,
474 WLAN_CAPABILITY_ESS, 479 WLAN_CAPABILITY_ESS,
475 WLAN_CAPABILITY_ESS); 480 WLAN_CAPABILITY_ESS);
@@ -537,7 +542,9 @@ void cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
537} 542}
538EXPORT_SYMBOL(cfg80211_connect_result); 543EXPORT_SYMBOL(cfg80211_connect_result);
539 544
540void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid, 545void __cfg80211_roamed(struct wireless_dev *wdev,
546 struct ieee80211_channel *channel,
547 const u8 *bssid,
541 const u8 *req_ie, size_t req_ie_len, 548 const u8 *req_ie, size_t req_ie_len,
542 const u8 *resp_ie, size_t resp_ie_len) 549 const u8 *resp_ie, size_t resp_ie_len)
543{ 550{
@@ -548,7 +555,8 @@ void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid,
548 555
549 ASSERT_WDEV_LOCK(wdev); 556 ASSERT_WDEV_LOCK(wdev);
550 557
551 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) 558 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
559 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
552 return; 560 return;
553 561
554 if (wdev->sme_state != CFG80211_SME_CONNECTED) 562 if (wdev->sme_state != CFG80211_SME_CONNECTED)
@@ -563,7 +571,7 @@ void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid,
563 cfg80211_put_bss(&wdev->current_bss->pub); 571 cfg80211_put_bss(&wdev->current_bss->pub);
564 wdev->current_bss = NULL; 572 wdev->current_bss = NULL;
565 573
566 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, 574 bss = cfg80211_get_bss(wdev->wiphy, channel, bssid,
567 wdev->ssid, wdev->ssid_len, 575 wdev->ssid, wdev->ssid_len,
568 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); 576 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
569 577
@@ -601,7 +609,9 @@ void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid,
601#endif 609#endif
602} 610}
603 611
604void cfg80211_roamed(struct net_device *dev, const u8 *bssid, 612void cfg80211_roamed(struct net_device *dev,
613 struct ieee80211_channel *channel,
614 const u8 *bssid,
605 const u8 *req_ie, size_t req_ie_len, 615 const u8 *req_ie, size_t req_ie_len,
606 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) 616 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
607{ 617{
@@ -617,6 +627,7 @@ void cfg80211_roamed(struct net_device *dev, const u8 *bssid,
617 return; 627 return;
618 628
619 ev->type = EVENT_ROAMED; 629 ev->type = EVENT_ROAMED;
630 ev->rm.channel = channel;
620 memcpy(ev->rm.bssid, bssid, ETH_ALEN); 631 memcpy(ev->rm.bssid, bssid, ETH_ALEN);
621 ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev); 632 ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev);
622 ev->rm.req_ie_len = req_ie_len; 633 ev->rm.req_ie_len = req_ie_len;
@@ -644,7 +655,8 @@ void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
644 655
645 ASSERT_WDEV_LOCK(wdev); 656 ASSERT_WDEV_LOCK(wdev);
646 657
647 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) 658 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
659 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
648 return; 660 return;
649 661
650 if (wdev->sme_state != CFG80211_SME_CONNECTED) 662 if (wdev->sme_state != CFG80211_SME_CONNECTED)
@@ -695,7 +707,7 @@ void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
695 */ 707 */
696 if (rdev->ops->del_key) 708 if (rdev->ops->del_key)
697 for (i = 0; i < 6; i++) 709 for (i = 0; i < 6; i++)
698 rdev->ops->del_key(wdev->wiphy, dev, i, NULL); 710 rdev->ops->del_key(wdev->wiphy, dev, i, false, NULL);
699 711
700#ifdef CONFIG_CFG80211_WEXT 712#ifdef CONFIG_CFG80211_WEXT
701 memset(&wrqu, 0, sizeof(wrqu)); 713 memset(&wrqu, 0, sizeof(wrqu));
diff --git a/net/wireless/sysfs.c b/net/wireless/sysfs.c
index 9f2cef3e0ca0..c6e4ca6a7d2e 100644
--- a/net/wireless/sysfs.c
+++ b/net/wireless/sysfs.c
@@ -35,6 +35,14 @@ SHOW_FMT(index, "%d", wiphy_idx);
35SHOW_FMT(macaddress, "%pM", wiphy.perm_addr); 35SHOW_FMT(macaddress, "%pM", wiphy.perm_addr);
36SHOW_FMT(address_mask, "%pM", wiphy.addr_mask); 36SHOW_FMT(address_mask, "%pM", wiphy.addr_mask);
37 37
38static ssize_t name_show(struct device *dev,
39 struct device_attribute *attr,
40 char *buf) {
41 struct wiphy *wiphy = &dev_to_rdev(dev)->wiphy;
42 return sprintf(buf, "%s\n", dev_name(&wiphy->dev));
43}
44
45
38static ssize_t addresses_show(struct device *dev, 46static ssize_t addresses_show(struct device *dev,
39 struct device_attribute *attr, 47 struct device_attribute *attr,
40 char *buf) 48 char *buf)
@@ -57,6 +65,7 @@ static struct device_attribute ieee80211_dev_attrs[] = {
57 __ATTR_RO(macaddress), 65 __ATTR_RO(macaddress),
58 __ATTR_RO(address_mask), 66 __ATTR_RO(address_mask),
59 __ATTR_RO(addresses), 67 __ATTR_RO(addresses),
68 __ATTR_RO(name),
60 {} 69 {}
61}; 70};
62 71
@@ -84,7 +93,7 @@ static int wiphy_suspend(struct device *dev, pm_message_t state)
84 93
85 if (rdev->ops->suspend) { 94 if (rdev->ops->suspend) {
86 rtnl_lock(); 95 rtnl_lock();
87 ret = rdev->ops->suspend(&rdev->wiphy); 96 ret = rdev->ops->suspend(&rdev->wiphy, rdev->wowlan);
88 rtnl_unlock(); 97 rtnl_unlock();
89 } 98 }
90 99
@@ -110,6 +119,13 @@ static int wiphy_resume(struct device *dev)
110 return ret; 119 return ret;
111} 120}
112 121
122static const void *wiphy_namespace(struct device *d)
123{
124 struct wiphy *wiphy = container_of(d, struct wiphy, dev);
125
126 return wiphy_net(wiphy);
127}
128
113struct class ieee80211_class = { 129struct class ieee80211_class = {
114 .name = "ieee80211", 130 .name = "ieee80211",
115 .owner = THIS_MODULE, 131 .owner = THIS_MODULE,
@@ -120,6 +136,8 @@ struct class ieee80211_class = {
120#endif 136#endif
121 .suspend = wiphy_suspend, 137 .suspend = wiphy_suspend,
122 .resume = wiphy_resume, 138 .resume = wiphy_resume,
139 .ns_type = &net_ns_type_operations,
140 .namespace = wiphy_namespace,
123}; 141};
124 142
125int wiphy_sysfs_init(void) 143int wiphy_sysfs_init(void)
diff --git a/net/wireless/util.c b/net/wireless/util.c
index 0c8a1e8b7690..4d7b83fbc32f 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -29,29 +29,37 @@ ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
29} 29}
30EXPORT_SYMBOL(ieee80211_get_response_rate); 30EXPORT_SYMBOL(ieee80211_get_response_rate);
31 31
32int ieee80211_channel_to_frequency(int chan) 32int ieee80211_channel_to_frequency(int chan, enum ieee80211_band band)
33{ 33{
34 if (chan < 14) 34 /* see 802.11 17.3.8.3.2 and Annex J
35 return 2407 + chan * 5; 35 * there are overlapping channel numbers in 5GHz and 2GHz bands */
36 36 if (band == IEEE80211_BAND_5GHZ) {
37 if (chan == 14) 37 if (chan >= 182 && chan <= 196)
38 return 2484; 38 return 4000 + chan * 5;
39 39 else
40 /* FIXME: 802.11j 17.3.8.3.2 */ 40 return 5000 + chan * 5;
41 return (chan + 1000) * 5; 41 } else { /* IEEE80211_BAND_2GHZ */
42 if (chan == 14)
43 return 2484;
44 else if (chan < 14)
45 return 2407 + chan * 5;
46 else
47 return 0; /* not supported */
48 }
42} 49}
43EXPORT_SYMBOL(ieee80211_channel_to_frequency); 50EXPORT_SYMBOL(ieee80211_channel_to_frequency);
44 51
45int ieee80211_frequency_to_channel(int freq) 52int ieee80211_frequency_to_channel(int freq)
46{ 53{
54 /* see 802.11 17.3.8.3.2 and Annex J */
47 if (freq == 2484) 55 if (freq == 2484)
48 return 14; 56 return 14;
49 57 else if (freq < 2484)
50 if (freq < 2484)
51 return (freq - 2407) / 5; 58 return (freq - 2407) / 5;
52 59 else if (freq >= 4910 && freq <= 4980)
53 /* FIXME: 802.11j 17.3.8.3.2 */ 60 return (freq - 4000) / 5;
54 return freq/5 - 1000; 61 else
62 return (freq - 5000) / 5;
55} 63}
56EXPORT_SYMBOL(ieee80211_frequency_to_channel); 64EXPORT_SYMBOL(ieee80211_frequency_to_channel);
57 65
@@ -144,21 +152,30 @@ void ieee80211_set_bitrate_flags(struct wiphy *wiphy)
144 152
145int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev, 153int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
146 struct key_params *params, int key_idx, 154 struct key_params *params, int key_idx,
147 const u8 *mac_addr) 155 bool pairwise, const u8 *mac_addr)
148{ 156{
149 int i; 157 int i;
150 158
151 if (key_idx > 5) 159 if (key_idx > 5)
152 return -EINVAL; 160 return -EINVAL;
153 161
162 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
163 return -EINVAL;
164
165 if (pairwise && !mac_addr)
166 return -EINVAL;
167
154 /* 168 /*
155 * Disallow pairwise keys with non-zero index unless it's WEP 169 * Disallow pairwise keys with non-zero index unless it's WEP
156 * (because current deployments use pairwise WEP keys with 170 * or a vendor specific cipher (because current deployments use
157 * non-zero indizes but 802.11i clearly specifies to use zero) 171 * pairwise WEP keys with non-zero indices and for vendor specific
172 * ciphers this should be validated in the driver or hardware level
173 * - but 802.11i clearly specifies to use zero)
158 */ 174 */
159 if (mac_addr && key_idx && 175 if (pairwise && key_idx &&
160 params->cipher != WLAN_CIPHER_SUITE_WEP40 && 176 ((params->cipher == WLAN_CIPHER_SUITE_TKIP) ||
161 params->cipher != WLAN_CIPHER_SUITE_WEP104) 177 (params->cipher == WLAN_CIPHER_SUITE_CCMP) ||
178 (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC)))
162 return -EINVAL; 179 return -EINVAL;
163 180
164 switch (params->cipher) { 181 switch (params->cipher) {
@@ -183,7 +200,14 @@ int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
183 return -EINVAL; 200 return -EINVAL;
184 break; 201 break;
185 default: 202 default:
186 return -EINVAL; 203 /*
204 * We don't know anything about this algorithm,
205 * allow using it -- but the driver must check
206 * all parameters! We still check below whether
207 * or not the driver supports this algorithm,
208 * of course.
209 */
210 break;
187 } 211 }
188 212
189 if (params->seq) { 213 if (params->seq) {
@@ -221,7 +245,7 @@ const unsigned char bridge_tunnel_header[] __aligned(2) =
221 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; 245 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
222EXPORT_SYMBOL(bridge_tunnel_header); 246EXPORT_SYMBOL(bridge_tunnel_header);
223 247
224unsigned int ieee80211_hdrlen(__le16 fc) 248unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc)
225{ 249{
226 unsigned int hdrlen = 24; 250 unsigned int hdrlen = 24;
227 251
@@ -319,7 +343,8 @@ int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
319 cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) { 343 cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
320 case cpu_to_le16(IEEE80211_FCTL_TODS): 344 case cpu_to_le16(IEEE80211_FCTL_TODS):
321 if (unlikely(iftype != NL80211_IFTYPE_AP && 345 if (unlikely(iftype != NL80211_IFTYPE_AP &&
322 iftype != NL80211_IFTYPE_AP_VLAN)) 346 iftype != NL80211_IFTYPE_AP_VLAN &&
347 iftype != NL80211_IFTYPE_P2P_GO))
323 return -1; 348 return -1;
324 break; 349 break;
325 case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS): 350 case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
@@ -347,7 +372,8 @@ int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
347 break; 372 break;
348 case cpu_to_le16(IEEE80211_FCTL_FROMDS): 373 case cpu_to_le16(IEEE80211_FCTL_FROMDS):
349 if ((iftype != NL80211_IFTYPE_STATION && 374 if ((iftype != NL80211_IFTYPE_STATION &&
350 iftype != NL80211_IFTYPE_MESH_POINT) || 375 iftype != NL80211_IFTYPE_P2P_CLIENT &&
376 iftype != NL80211_IFTYPE_MESH_POINT) ||
351 (is_multicast_ether_addr(dst) && 377 (is_multicast_ether_addr(dst) &&
352 !compare_ether_addr(src, addr))) 378 !compare_ether_addr(src, addr)))
353 return -1; 379 return -1;
@@ -424,6 +450,7 @@ int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,
424 switch (iftype) { 450 switch (iftype) {
425 case NL80211_IFTYPE_AP: 451 case NL80211_IFTYPE_AP:
426 case NL80211_IFTYPE_AP_VLAN: 452 case NL80211_IFTYPE_AP_VLAN:
453 case NL80211_IFTYPE_P2P_GO:
427 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); 454 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
428 /* DA BSSID SA */ 455 /* DA BSSID SA */
429 memcpy(hdr.addr1, skb->data, ETH_ALEN); 456 memcpy(hdr.addr1, skb->data, ETH_ALEN);
@@ -432,6 +459,7 @@ int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,
432 hdrlen = 24; 459 hdrlen = 24;
433 break; 460 break;
434 case NL80211_IFTYPE_STATION: 461 case NL80211_IFTYPE_STATION:
462 case NL80211_IFTYPE_P2P_CLIENT:
435 fc |= cpu_to_le16(IEEE80211_FCTL_TODS); 463 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
436 /* BSSID SA DA */ 464 /* BSSID SA DA */
437 memcpy(hdr.addr1, bssid, ETH_ALEN); 465 memcpy(hdr.addr1, bssid, ETH_ALEN);
@@ -485,7 +513,7 @@ int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,
485 skb_orphan(skb); 513 skb_orphan(skb);
486 514
487 if (pskb_expand_head(skb, head_need, 0, GFP_ATOMIC)) { 515 if (pskb_expand_head(skb, head_need, 0, GFP_ATOMIC)) {
488 printk(KERN_ERR "failed to reallocate Tx buffer\n"); 516 pr_err("failed to reallocate Tx buffer\n");
489 return -ENOMEM; 517 return -ENOMEM;
490 } 518 }
491 skb->truesize += head_need; 519 skb->truesize += head_need;
@@ -516,7 +544,8 @@ EXPORT_SYMBOL(ieee80211_data_from_8023);
516 544
517void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list, 545void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
518 const u8 *addr, enum nl80211_iftype iftype, 546 const u8 *addr, enum nl80211_iftype iftype,
519 const unsigned int extra_headroom) 547 const unsigned int extra_headroom,
548 bool has_80211_header)
520{ 549{
521 struct sk_buff *frame = NULL; 550 struct sk_buff *frame = NULL;
522 u16 ethertype; 551 u16 ethertype;
@@ -525,14 +554,18 @@ void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
525 int remaining, err; 554 int remaining, err;
526 u8 dst[ETH_ALEN], src[ETH_ALEN]; 555 u8 dst[ETH_ALEN], src[ETH_ALEN];
527 556
528 err = ieee80211_data_to_8023(skb, addr, iftype); 557 if (has_80211_header) {
529 if (err) 558 err = ieee80211_data_to_8023(skb, addr, iftype);
530 goto out; 559 if (err)
560 goto out;
531 561
532 /* skip the wrapping header */ 562 /* skip the wrapping header */
533 eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr)); 563 eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
534 if (!eth) 564 if (!eth)
535 goto out; 565 goto out;
566 } else {
567 eth = (struct ethhdr *) skb->data;
568 }
536 569
537 while (skb != frame) { 570 while (skb != frame) {
538 u8 padding; 571 u8 padding;
@@ -666,22 +699,20 @@ void cfg80211_upload_connect_keys(struct wireless_dev *wdev)
666 for (i = 0; i < 6; i++) { 699 for (i = 0; i < 6; i++) {
667 if (!wdev->connect_keys->params[i].cipher) 700 if (!wdev->connect_keys->params[i].cipher)
668 continue; 701 continue;
669 if (rdev->ops->add_key(wdev->wiphy, dev, i, NULL, 702 if (rdev->ops->add_key(wdev->wiphy, dev, i, false, NULL,
670 &wdev->connect_keys->params[i])) { 703 &wdev->connect_keys->params[i])) {
671 printk(KERN_ERR "%s: failed to set key %d\n", 704 netdev_err(dev, "failed to set key %d\n", i);
672 dev->name, i);
673 continue; 705 continue;
674 } 706 }
675 if (wdev->connect_keys->def == i) 707 if (wdev->connect_keys->def == i)
676 if (rdev->ops->set_default_key(wdev->wiphy, dev, i)) { 708 if (rdev->ops->set_default_key(wdev->wiphy, dev,
677 printk(KERN_ERR "%s: failed to set defkey %d\n", 709 i, true, true)) {
678 dev->name, i); 710 netdev_err(dev, "failed to set defkey %d\n", i);
679 continue; 711 continue;
680 } 712 }
681 if (wdev->connect_keys->defmgmt == i) 713 if (wdev->connect_keys->defmgmt == i)
682 if (rdev->ops->set_default_mgmt_key(wdev->wiphy, dev, i)) 714 if (rdev->ops->set_default_mgmt_key(wdev->wiphy, dev, i))
683 printk(KERN_ERR "%s: failed to set mgtdef %d\n", 715 netdev_err(dev, "failed to set mgtdef %d\n", i);
684 dev->name, i);
685 } 716 }
686 717
687 kfree(wdev->connect_keys); 718 kfree(wdev->connect_keys);
@@ -715,7 +746,7 @@ static void cfg80211_process_wdev_events(struct wireless_dev *wdev)
715 NULL); 746 NULL);
716 break; 747 break;
717 case EVENT_ROAMED: 748 case EVENT_ROAMED:
718 __cfg80211_roamed(wdev, ev->rm.bssid, 749 __cfg80211_roamed(wdev, ev->rm.channel, ev->rm.bssid,
719 ev->rm.req_ie, ev->rm.req_ie_len, 750 ev->rm.req_ie, ev->rm.req_ie_len,
720 ev->rm.resp_ie, ev->rm.resp_ie_len); 751 ev->rm.resp_ie, ev->rm.resp_ie_len);
721 break; 752 break;
@@ -771,17 +802,26 @@ int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
771 802
772 /* if it's part of a bridge, reject changing type to station/ibss */ 803 /* if it's part of a bridge, reject changing type to station/ibss */
773 if ((dev->priv_flags & IFF_BRIDGE_PORT) && 804 if ((dev->priv_flags & IFF_BRIDGE_PORT) &&
774 (ntype == NL80211_IFTYPE_ADHOC || ntype == NL80211_IFTYPE_STATION)) 805 (ntype == NL80211_IFTYPE_ADHOC ||
806 ntype == NL80211_IFTYPE_STATION ||
807 ntype == NL80211_IFTYPE_P2P_CLIENT))
775 return -EBUSY; 808 return -EBUSY;
776 809
777 if (ntype != otype) { 810 if (ntype != otype) {
811 err = cfg80211_can_change_interface(rdev, dev->ieee80211_ptr,
812 ntype);
813 if (err)
814 return err;
815
778 dev->ieee80211_ptr->use_4addr = false; 816 dev->ieee80211_ptr->use_4addr = false;
817 dev->ieee80211_ptr->mesh_id_up_len = 0;
779 818
780 switch (otype) { 819 switch (otype) {
781 case NL80211_IFTYPE_ADHOC: 820 case NL80211_IFTYPE_ADHOC:
782 cfg80211_leave_ibss(rdev, dev, false); 821 cfg80211_leave_ibss(rdev, dev, false);
783 break; 822 break;
784 case NL80211_IFTYPE_STATION: 823 case NL80211_IFTYPE_STATION:
824 case NL80211_IFTYPE_P2P_CLIENT:
785 cfg80211_disconnect(rdev, dev, 825 cfg80211_disconnect(rdev, dev,
786 WLAN_REASON_DEAUTH_LEAVING, true); 826 WLAN_REASON_DEAUTH_LEAVING, true);
787 break; 827 break;
@@ -810,9 +850,11 @@ int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
810 if (dev->ieee80211_ptr->use_4addr) 850 if (dev->ieee80211_ptr->use_4addr)
811 break; 851 break;
812 /* fall through */ 852 /* fall through */
853 case NL80211_IFTYPE_P2P_CLIENT:
813 case NL80211_IFTYPE_ADHOC: 854 case NL80211_IFTYPE_ADHOC:
814 dev->priv_flags |= IFF_DONT_BRIDGE; 855 dev->priv_flags |= IFF_DONT_BRIDGE;
815 break; 856 break;
857 case NL80211_IFTYPE_P2P_GO:
816 case NL80211_IFTYPE_AP: 858 case NL80211_IFTYPE_AP:
817 case NL80211_IFTYPE_AP_VLAN: 859 case NL80211_IFTYPE_AP_VLAN:
818 case NL80211_IFTYPE_WDS: 860 case NL80211_IFTYPE_WDS:
@@ -823,7 +865,7 @@ int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
823 /* monitor can't bridge anyway */ 865 /* monitor can't bridge anyway */
824 break; 866 break;
825 case NL80211_IFTYPE_UNSPECIFIED: 867 case NL80211_IFTYPE_UNSPECIFIED:
826 case __NL80211_IFTYPE_AFTER_LAST: 868 case NUM_NL80211_IFTYPES:
827 /* not happening */ 869 /* not happening */
828 break; 870 break;
829 } 871 }
@@ -864,3 +906,103 @@ u16 cfg80211_calculate_bitrate(struct rate_info *rate)
864 /* do NOT round down here */ 906 /* do NOT round down here */
865 return (bitrate + 50000) / 100000; 907 return (bitrate + 50000) / 100000;
866} 908}
909
910int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
911 u32 beacon_int)
912{
913 struct wireless_dev *wdev;
914 int res = 0;
915
916 if (!beacon_int)
917 return -EINVAL;
918
919 mutex_lock(&rdev->devlist_mtx);
920
921 list_for_each_entry(wdev, &rdev->netdev_list, list) {
922 if (!wdev->beacon_interval)
923 continue;
924 if (wdev->beacon_interval != beacon_int) {
925 res = -EINVAL;
926 break;
927 }
928 }
929
930 mutex_unlock(&rdev->devlist_mtx);
931
932 return res;
933}
934
935int cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
936 struct wireless_dev *wdev,
937 enum nl80211_iftype iftype)
938{
939 struct wireless_dev *wdev_iter;
940 int num[NUM_NL80211_IFTYPES];
941 int total = 1;
942 int i, j;
943
944 ASSERT_RTNL();
945
946 /* Always allow software iftypes */
947 if (rdev->wiphy.software_iftypes & BIT(iftype))
948 return 0;
949
950 /*
951 * Drivers will gradually all set this flag, until all
952 * have it we only enforce for those that set it.
953 */
954 if (!(rdev->wiphy.flags & WIPHY_FLAG_ENFORCE_COMBINATIONS))
955 return 0;
956
957 memset(num, 0, sizeof(num));
958
959 num[iftype] = 1;
960
961 mutex_lock(&rdev->devlist_mtx);
962 list_for_each_entry(wdev_iter, &rdev->netdev_list, list) {
963 if (wdev_iter == wdev)
964 continue;
965 if (!netif_running(wdev_iter->netdev))
966 continue;
967
968 if (rdev->wiphy.software_iftypes & BIT(wdev_iter->iftype))
969 continue;
970
971 num[wdev_iter->iftype]++;
972 total++;
973 }
974 mutex_unlock(&rdev->devlist_mtx);
975
976 for (i = 0; i < rdev->wiphy.n_iface_combinations; i++) {
977 const struct ieee80211_iface_combination *c;
978 struct ieee80211_iface_limit *limits;
979
980 c = &rdev->wiphy.iface_combinations[i];
981
982 limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits,
983 GFP_KERNEL);
984 if (!limits)
985 return -ENOMEM;
986 if (total > c->max_interfaces)
987 goto cont;
988
989 for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) {
990 if (rdev->wiphy.software_iftypes & BIT(iftype))
991 continue;
992 for (j = 0; j < c->n_limits; j++) {
993 if (!(limits[j].types & iftype))
994 continue;
995 if (limits[j].max < num[iftype])
996 goto cont;
997 limits[j].max -= num[iftype];
998 }
999 }
1000 /* yay, it fits */
1001 kfree(limits);
1002 return 0;
1003 cont:
1004 kfree(limits);
1005 }
1006
1007 return -EBUSY;
1008}
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
index 7e5c3a45f811..0bf169bb770e 100644
--- a/net/wireless/wext-compat.c
+++ b/net/wireless/wext-compat.c
@@ -267,9 +267,12 @@ int cfg80211_wext_freq(struct wiphy *wiphy, struct iw_freq *freq)
267 * -EINVAL for impossible things. 267 * -EINVAL for impossible things.
268 */ 268 */
269 if (freq->e == 0) { 269 if (freq->e == 0) {
270 enum ieee80211_band band = IEEE80211_BAND_2GHZ;
270 if (freq->m < 0) 271 if (freq->m < 0)
271 return 0; 272 return 0;
272 return ieee80211_channel_to_frequency(freq->m); 273 if (freq->m > 14)
274 band = IEEE80211_BAND_5GHZ;
275 return ieee80211_channel_to_frequency(freq->m, band);
273 } else { 276 } else {
274 int i, div = 1000000; 277 int i, div = 1000000;
275 for (i = 0; i < freq->e; i++) 278 for (i = 0; i < freq->e; i++)
@@ -432,14 +435,17 @@ int cfg80211_wext_giwretry(struct net_device *dev,
432EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry); 435EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry);
433 436
434static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev, 437static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
435 struct net_device *dev, const u8 *addr, 438 struct net_device *dev, bool pairwise,
436 bool remove, bool tx_key, int idx, 439 const u8 *addr, bool remove, bool tx_key,
437 struct key_params *params) 440 int idx, struct key_params *params)
438{ 441{
439 struct wireless_dev *wdev = dev->ieee80211_ptr; 442 struct wireless_dev *wdev = dev->ieee80211_ptr;
440 int err, i; 443 int err, i;
441 bool rejoin = false; 444 bool rejoin = false;
442 445
446 if (pairwise && !addr)
447 return -EINVAL;
448
443 if (!wdev->wext.keys) { 449 if (!wdev->wext.keys) {
444 wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys), 450 wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
445 GFP_KERNEL); 451 GFP_KERNEL);
@@ -478,7 +484,13 @@ static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
478 __cfg80211_leave_ibss(rdev, wdev->netdev, true); 484 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
479 rejoin = true; 485 rejoin = true;
480 } 486 }
481 err = rdev->ops->del_key(&rdev->wiphy, dev, idx, addr); 487
488 if (!pairwise && addr &&
489 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
490 err = -ENOENT;
491 else
492 err = rdev->ops->del_key(&rdev->wiphy, dev, idx,
493 pairwise, addr);
482 } 494 }
483 wdev->wext.connect.privacy = false; 495 wdev->wext.connect.privacy = false;
484 /* 496 /*
@@ -507,12 +519,13 @@ static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
507 if (addr) 519 if (addr)
508 tx_key = false; 520 tx_key = false;
509 521
510 if (cfg80211_validate_key_settings(rdev, params, idx, addr)) 522 if (cfg80211_validate_key_settings(rdev, params, idx, pairwise, addr))
511 return -EINVAL; 523 return -EINVAL;
512 524
513 err = 0; 525 err = 0;
514 if (wdev->current_bss) 526 if (wdev->current_bss)
515 err = rdev->ops->add_key(&rdev->wiphy, dev, idx, addr, params); 527 err = rdev->ops->add_key(&rdev->wiphy, dev, idx,
528 pairwise, addr, params);
516 if (err) 529 if (err)
517 return err; 530 return err;
518 531
@@ -538,8 +551,8 @@ static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
538 __cfg80211_leave_ibss(rdev, wdev->netdev, true); 551 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
539 rejoin = true; 552 rejoin = true;
540 } 553 }
541 err = rdev->ops->set_default_key(&rdev->wiphy, 554 err = rdev->ops->set_default_key(&rdev->wiphy, dev,
542 dev, idx); 555 idx, true, true);
543 } 556 }
544 if (!err) { 557 if (!err) {
545 wdev->wext.default_key = idx; 558 wdev->wext.default_key = idx;
@@ -563,17 +576,17 @@ static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
563} 576}
564 577
565static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev, 578static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
566 struct net_device *dev, const u8 *addr, 579 struct net_device *dev, bool pairwise,
567 bool remove, bool tx_key, int idx, 580 const u8 *addr, bool remove, bool tx_key,
568 struct key_params *params) 581 int idx, struct key_params *params)
569{ 582{
570 int err; 583 int err;
571 584
572 /* devlist mutex needed for possible IBSS re-join */ 585 /* devlist mutex needed for possible IBSS re-join */
573 mutex_lock(&rdev->devlist_mtx); 586 mutex_lock(&rdev->devlist_mtx);
574 wdev_lock(dev->ieee80211_ptr); 587 wdev_lock(dev->ieee80211_ptr);
575 err = __cfg80211_set_encryption(rdev, dev, addr, remove, 588 err = __cfg80211_set_encryption(rdev, dev, pairwise, addr,
576 tx_key, idx, params); 589 remove, tx_key, idx, params);
577 wdev_unlock(dev->ieee80211_ptr); 590 wdev_unlock(dev->ieee80211_ptr);
578 mutex_unlock(&rdev->devlist_mtx); 591 mutex_unlock(&rdev->devlist_mtx);
579 592
@@ -617,8 +630,8 @@ int cfg80211_wext_siwencode(struct net_device *dev,
617 err = 0; 630 err = 0;
618 wdev_lock(wdev); 631 wdev_lock(wdev);
619 if (wdev->current_bss) 632 if (wdev->current_bss)
620 err = rdev->ops->set_default_key(&rdev->wiphy, 633 err = rdev->ops->set_default_key(&rdev->wiphy, dev,
621 dev, idx); 634 idx, true, true);
622 if (!err) 635 if (!err)
623 wdev->wext.default_key = idx; 636 wdev->wext.default_key = idx;
624 wdev_unlock(wdev); 637 wdev_unlock(wdev);
@@ -635,7 +648,7 @@ int cfg80211_wext_siwencode(struct net_device *dev,
635 else if (!remove) 648 else if (!remove)
636 return -EINVAL; 649 return -EINVAL;
637 650
638 return cfg80211_set_encryption(rdev, dev, NULL, remove, 651 return cfg80211_set_encryption(rdev, dev, false, NULL, remove,
639 wdev->wext.default_key == -1, 652 wdev->wext.default_key == -1,
640 idx, &params); 653 idx, &params);
641} 654}
@@ -725,7 +738,9 @@ int cfg80211_wext_siwencodeext(struct net_device *dev,
725 } 738 }
726 739
727 return cfg80211_set_encryption( 740 return cfg80211_set_encryption(
728 rdev, dev, addr, remove, 741 rdev, dev,
742 !(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY),
743 addr, remove,
729 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY, 744 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
730 idx, &params); 745 idx, &params);
731} 746}
@@ -790,11 +805,11 @@ int cfg80211_wext_siwfreq(struct net_device *dev,
790 return freq; 805 return freq;
791 if (freq == 0) 806 if (freq == 0)
792 return -EINVAL; 807 return -EINVAL;
793 wdev_lock(wdev);
794 mutex_lock(&rdev->devlist_mtx); 808 mutex_lock(&rdev->devlist_mtx);
809 wdev_lock(wdev);
795 err = cfg80211_set_freq(rdev, wdev, freq, NL80211_CHAN_NO_HT); 810 err = cfg80211_set_freq(rdev, wdev, freq, NL80211_CHAN_NO_HT);
796 mutex_unlock(&rdev->devlist_mtx);
797 wdev_unlock(wdev); 811 wdev_unlock(wdev);
812 mutex_unlock(&rdev->devlist_mtx);
798 return err; 813 return err;
799 default: 814 default:
800 return -EOPNOTSUPP; 815 return -EOPNOTSUPP;
@@ -1354,6 +1369,10 @@ struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
1354 } 1369 }
1355 1370
1356 wstats.qual.updated |= IW_QUAL_NOISE_INVALID; 1371 wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
1372 if (sinfo.filled & STATION_INFO_RX_DROP_MISC)
1373 wstats.discard.misc = sinfo.rx_dropped_misc;
1374 if (sinfo.filled & STATION_INFO_TX_FAILED)
1375 wstats.discard.retries = sinfo.tx_failed;
1357 1376
1358 return &wstats; 1377 return &wstats;
1359} 1378}
diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
index 8f5116f5af19..fdbc23c10d8c 100644
--- a/net/wireless/wext-core.c
+++ b/net/wireless/wext-core.c
@@ -467,8 +467,8 @@ void wireless_send_event(struct net_device * dev,
467 * The best the driver could do is to log an error message. 467 * The best the driver could do is to log an error message.
468 * We will do it ourselves instead... 468 * We will do it ourselves instead...
469 */ 469 */
470 printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n", 470 netdev_err(dev, "(WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
471 dev->name, cmd); 471 cmd);
472 return; 472 return;
473 } 473 }
474 474
@@ -476,11 +476,13 @@ void wireless_send_event(struct net_device * dev,
476 if (descr->header_type == IW_HEADER_TYPE_POINT) { 476 if (descr->header_type == IW_HEADER_TYPE_POINT) {
477 /* Check if number of token fits within bounds */ 477 /* Check if number of token fits within bounds */
478 if (wrqu->data.length > descr->max_tokens) { 478 if (wrqu->data.length > descr->max_tokens) {
479 printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length); 479 netdev_err(dev, "(WE) : Wireless Event too big (%d)\n",
480 wrqu->data.length);
480 return; 481 return;
481 } 482 }
482 if (wrqu->data.length < descr->min_tokens) { 483 if (wrqu->data.length < descr->min_tokens) {
483 printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length); 484 netdev_err(dev, "(WE) : Wireless Event too small (%d)\n",
485 wrqu->data.length);
484 return; 486 return;
485 } 487 }
486 /* Calculate extra_len - extra is NULL for restricted events */ 488 /* Calculate extra_len - extra is NULL for restricted events */
@@ -611,7 +613,7 @@ struct iw_statistics *get_wireless_stats(struct net_device *dev)
611#endif 613#endif
612 614
613#ifdef CONFIG_CFG80211_WEXT 615#ifdef CONFIG_CFG80211_WEXT
614 if (dev->ieee80211_ptr && dev->ieee80211_ptr && 616 if (dev->ieee80211_ptr &&
615 dev->ieee80211_ptr->wiphy && 617 dev->ieee80211_ptr->wiphy &&
616 dev->ieee80211_ptr->wiphy->wext && 618 dev->ieee80211_ptr->wiphy->wext &&
617 dev->ieee80211_ptr->wiphy->wext->get_wireless_stats) 619 dev->ieee80211_ptr->wiphy->wext->get_wireless_stats)
diff --git a/net/wireless/wext-sme.c b/net/wireless/wext-sme.c
index 9818198add8a..6fffe62d7c25 100644
--- a/net/wireless/wext-sme.c
+++ b/net/wireless/wext-sme.c
@@ -197,6 +197,8 @@ int cfg80211_mgd_wext_siwessid(struct net_device *dev,
197 wdev->wext.connect.ssid_len = len; 197 wdev->wext.connect.ssid_len = len;
198 198
199 wdev->wext.connect.crypto.control_port = false; 199 wdev->wext.connect.crypto.control_port = false;
200 wdev->wext.connect.crypto.control_port_ethertype =
201 cpu_to_be16(ETH_P_PAE);
200 202
201 err = cfg80211_mgd_wext_connect(rdev, wdev); 203 err = cfg80211_mgd_wext_connect(rdev, wdev);
202 out: 204 out: