diff options
author | David S. Miller <davem@davemloft.net> | 2009-05-25 03:38:24 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-05-25 03:38:24 -0400 |
commit | 45ea4ea2af358fe316c918381c7868f9418cad09 (patch) | |
tree | 4deb3d87b26e884b06929fe33740d45e78fbdcab /net/wireless | |
parent | dddc045e2fdd4eb8d7dfac29bff191d639fff8c3 (diff) | |
parent | a2e2322d83df82a57ba456cfa604c8b8f7b04670 (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next-2.6
Diffstat (limited to 'net/wireless')
-rw-r--r-- | net/wireless/Kconfig | 8 | ||||
-rw-r--r-- | net/wireless/Makefile | 1 | ||||
-rw-r--r-- | net/wireless/core.c | 7 | ||||
-rw-r--r-- | net/wireless/core.h | 14 | ||||
-rw-r--r-- | net/wireless/debugfs.c | 131 | ||||
-rw-r--r-- | net/wireless/debugfs.h | 14 | ||||
-rw-r--r-- | net/wireless/nl80211.c | 66 | ||||
-rw-r--r-- | net/wireless/reg.c | 216 | ||||
-rw-r--r-- | net/wireless/util.c | 320 | ||||
-rw-r--r-- | net/wireless/wext-compat.c | 7 | ||||
-rw-r--r-- | net/wireless/wext.c | 32 |
11 files changed, 735 insertions, 81 deletions
diff --git a/net/wireless/Kconfig b/net/wireless/Kconfig index 3c3bc9e579ed..45005497c634 100644 --- a/net/wireless/Kconfig +++ b/net/wireless/Kconfig | |||
@@ -10,6 +10,14 @@ config CFG80211_REG_DEBUG | |||
10 | 10 | ||
11 | If unsure, say N. | 11 | If unsure, say N. |
12 | 12 | ||
13 | config CFG80211_DEBUGFS | ||
14 | bool "cfg80211 DebugFS entries" | ||
15 | depends on CFG80211 && DEBUG_FS | ||
16 | ---help--- | ||
17 | You can enable this if you want to debugfs entries for cfg80211. | ||
18 | |||
19 | If unsure, say N. | ||
20 | |||
13 | config WIRELESS_OLD_REGULATORY | 21 | config WIRELESS_OLD_REGULATORY |
14 | bool "Old wireless static regulatory definitions" | 22 | bool "Old wireless static regulatory definitions" |
15 | default n | 23 | default n |
diff --git a/net/wireless/Makefile b/net/wireless/Makefile index 14ea01c4a103..f78c4832a9ca 100644 --- a/net/wireless/Makefile +++ b/net/wireless/Makefile | |||
@@ -6,6 +6,7 @@ obj-$(CONFIG_LIB80211_CRYPT_CCMP) += lib80211_crypt_ccmp.o | |||
6 | obj-$(CONFIG_LIB80211_CRYPT_TKIP) += lib80211_crypt_tkip.o | 6 | obj-$(CONFIG_LIB80211_CRYPT_TKIP) += lib80211_crypt_tkip.o |
7 | 7 | ||
8 | cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o mlme.o ibss.o | 8 | cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o mlme.o ibss.o |
9 | cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o | ||
9 | cfg80211-$(CONFIG_WIRELESS_EXT) += wext-compat.o | 10 | cfg80211-$(CONFIG_WIRELESS_EXT) += wext-compat.o |
10 | 11 | ||
11 | ccflags-y += -D__CHECK_ENDIAN__ | 12 | ccflags-y += -D__CHECK_ENDIAN__ |
diff --git a/net/wireless/core.c b/net/wireless/core.c index 47c20eb0c04d..a5dbea1da476 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include "nl80211.h" | 17 | #include "nl80211.h" |
18 | #include "core.h" | 18 | #include "core.h" |
19 | #include "sysfs.h" | 19 | #include "sysfs.h" |
20 | #include "debugfs.h" | ||
20 | 21 | ||
21 | /* name for sysfs, %d is appended */ | 22 | /* name for sysfs, %d is appended */ |
22 | #define PHY_NAME "phy" | 23 | #define PHY_NAME "phy" |
@@ -228,7 +229,7 @@ int cfg80211_dev_rename(struct cfg80211_registered_device *rdev, | |||
228 | 229 | ||
229 | /* exported functions */ | 230 | /* exported functions */ |
230 | 231 | ||
231 | struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv) | 232 | struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv) |
232 | { | 233 | { |
233 | static int wiphy_counter; | 234 | static int wiphy_counter; |
234 | 235 | ||
@@ -375,6 +376,8 @@ int wiphy_register(struct wiphy *wiphy) | |||
375 | nl80211_send_reg_change_event(&request); | 376 | nl80211_send_reg_change_event(&request); |
376 | } | 377 | } |
377 | 378 | ||
379 | cfg80211_debugfs_drv_add(drv); | ||
380 | |||
378 | res = 0; | 381 | res = 0; |
379 | out_unlock: | 382 | out_unlock: |
380 | mutex_unlock(&cfg80211_mutex); | 383 | mutex_unlock(&cfg80211_mutex); |
@@ -405,6 +408,8 @@ void wiphy_unregister(struct wiphy *wiphy) | |||
405 | /* unlock again before freeing */ | 408 | /* unlock again before freeing */ |
406 | mutex_unlock(&drv->mtx); | 409 | mutex_unlock(&drv->mtx); |
407 | 410 | ||
411 | cfg80211_debugfs_drv_del(drv); | ||
412 | |||
408 | /* If this device got a regulatory hint tell core its | 413 | /* If this device got a regulatory hint tell core its |
409 | * free to listen now to a new shiny device regulatory hint */ | 414 | * free to listen now to a new shiny device regulatory hint */ |
410 | reg_device_remove(wiphy); | 415 | reg_device_remove(wiphy); |
diff --git a/net/wireless/core.h b/net/wireless/core.h index f14b6c5f4221..ab512bcd8153 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h | |||
@@ -10,12 +10,13 @@ | |||
10 | #include <linux/netdevice.h> | 10 | #include <linux/netdevice.h> |
11 | #include <linux/kref.h> | 11 | #include <linux/kref.h> |
12 | #include <linux/rbtree.h> | 12 | #include <linux/rbtree.h> |
13 | #include <linux/debugfs.h> | ||
13 | #include <net/genetlink.h> | 14 | #include <net/genetlink.h> |
14 | #include <net/cfg80211.h> | 15 | #include <net/cfg80211.h> |
15 | #include "reg.h" | 16 | #include "reg.h" |
16 | 17 | ||
17 | struct cfg80211_registered_device { | 18 | struct cfg80211_registered_device { |
18 | struct cfg80211_ops *ops; | 19 | const struct cfg80211_ops *ops; |
19 | struct list_head list; | 20 | struct list_head list; |
20 | /* we hold this mutex during any call so that | 21 | /* we hold this mutex during any call so that |
21 | * we cannot do multiple calls at once, and also | 22 | * we cannot do multiple calls at once, and also |
@@ -50,6 +51,17 @@ struct cfg80211_registered_device { | |||
50 | struct cfg80211_scan_request *scan_req; /* protected by RTNL */ | 51 | struct cfg80211_scan_request *scan_req; /* protected by RTNL */ |
51 | unsigned long suspend_at; | 52 | unsigned long suspend_at; |
52 | 53 | ||
54 | #ifdef CONFIG_CFG80211_DEBUGFS | ||
55 | /* Debugfs entries */ | ||
56 | struct wiphy_debugfsdentries { | ||
57 | struct dentry *rts_threshold; | ||
58 | struct dentry *fragmentation_threshold; | ||
59 | struct dentry *short_retry_limit; | ||
60 | struct dentry *long_retry_limit; | ||
61 | struct dentry *ht40allow_map; | ||
62 | } debugfs; | ||
63 | #endif | ||
64 | |||
53 | /* must be last because of the way we do wiphy_priv(), | 65 | /* must be last because of the way we do wiphy_priv(), |
54 | * and it should at least be aligned to NETDEV_ALIGN */ | 66 | * and it should at least be aligned to NETDEV_ALIGN */ |
55 | struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN))); | 67 | struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN))); |
diff --git a/net/wireless/debugfs.c b/net/wireless/debugfs.c new file mode 100644 index 000000000000..679ddfcec1ee --- /dev/null +++ b/net/wireless/debugfs.c | |||
@@ -0,0 +1,131 @@ | |||
1 | /* | ||
2 | * cfg80211 debugfs | ||
3 | * | ||
4 | * Copyright 2009 Luis R. Rodriguez <lrodriguez@atheros.com> | ||
5 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include "core.h" | ||
13 | #include "debugfs.h" | ||
14 | |||
15 | static int cfg80211_open_file_generic(struct inode *inode, struct file *file) | ||
16 | { | ||
17 | file->private_data = inode->i_private; | ||
18 | return 0; | ||
19 | } | ||
20 | |||
21 | #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \ | ||
22 | static ssize_t name## _read(struct file *file, char __user *userbuf, \ | ||
23 | size_t count, loff_t *ppos) \ | ||
24 | { \ | ||
25 | struct wiphy *wiphy= file->private_data; \ | ||
26 | char buf[buflen]; \ | ||
27 | int res; \ | ||
28 | \ | ||
29 | res = scnprintf(buf, buflen, fmt "\n", ##value); \ | ||
30 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); \ | ||
31 | } \ | ||
32 | \ | ||
33 | static const struct file_operations name## _ops = { \ | ||
34 | .read = name## _read, \ | ||
35 | .open = cfg80211_open_file_generic, \ | ||
36 | }; | ||
37 | |||
38 | DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d", | ||
39 | wiphy->rts_threshold) | ||
40 | DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d", | ||
41 | wiphy->frag_threshold); | ||
42 | DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d", | ||
43 | wiphy->retry_short) | ||
44 | DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d", | ||
45 | wiphy->retry_long); | ||
46 | |||
47 | static int ht_print_chan(struct ieee80211_channel *chan, | ||
48 | char *buf, int buf_size, int offset) | ||
49 | { | ||
50 | if (WARN_ON(offset > buf_size)) | ||
51 | return 0; | ||
52 | |||
53 | if (chan->flags & IEEE80211_CHAN_DISABLED) | ||
54 | return snprintf(buf + offset, | ||
55 | buf_size - offset, | ||
56 | "%d Disabled\n", | ||
57 | chan->center_freq); | ||
58 | |||
59 | return snprintf(buf + offset, | ||
60 | buf_size - offset, | ||
61 | "%d HT40 %c%c\n", | ||
62 | chan->center_freq, | ||
63 | (chan->flags & IEEE80211_CHAN_NO_HT40MINUS) ? ' ' : '-', | ||
64 | (chan->flags & IEEE80211_CHAN_NO_HT40PLUS) ? ' ' : '+'); | ||
65 | } | ||
66 | |||
67 | static ssize_t ht40allow_map_read(struct file *file, | ||
68 | char __user *user_buf, | ||
69 | size_t count, loff_t *ppos) | ||
70 | { | ||
71 | struct wiphy *wiphy = file->private_data; | ||
72 | char *buf; | ||
73 | unsigned int offset = 0, buf_size = PAGE_SIZE, i, r; | ||
74 | enum ieee80211_band band; | ||
75 | struct ieee80211_supported_band *sband; | ||
76 | |||
77 | buf = kzalloc(buf_size, GFP_KERNEL); | ||
78 | if (!buf) | ||
79 | return -ENOMEM; | ||
80 | |||
81 | mutex_lock(&cfg80211_mutex); | ||
82 | |||
83 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | ||
84 | sband = wiphy->bands[band]; | ||
85 | if (!sband) | ||
86 | continue; | ||
87 | for (i = 0; i < sband->n_channels; i++) | ||
88 | offset += ht_print_chan(&sband->channels[i], | ||
89 | buf, buf_size, offset); | ||
90 | } | ||
91 | |||
92 | mutex_unlock(&cfg80211_mutex); | ||
93 | |||
94 | r = simple_read_from_buffer(user_buf, count, ppos, buf, offset); | ||
95 | |||
96 | kfree(buf); | ||
97 | |||
98 | return r; | ||
99 | } | ||
100 | |||
101 | static const struct file_operations ht40allow_map_ops = { | ||
102 | .read = ht40allow_map_read, | ||
103 | .open = cfg80211_open_file_generic, | ||
104 | }; | ||
105 | |||
106 | #define DEBUGFS_ADD(name) \ | ||
107 | drv->debugfs.name = debugfs_create_file(#name, S_IRUGO, phyd, \ | ||
108 | &drv->wiphy, &name## _ops); | ||
109 | #define DEBUGFS_DEL(name) \ | ||
110 | debugfs_remove(drv->debugfs.name); \ | ||
111 | drv->debugfs.name = NULL; | ||
112 | |||
113 | void cfg80211_debugfs_drv_add(struct cfg80211_registered_device *drv) | ||
114 | { | ||
115 | struct dentry *phyd = drv->wiphy.debugfsdir; | ||
116 | |||
117 | DEBUGFS_ADD(rts_threshold); | ||
118 | DEBUGFS_ADD(fragmentation_threshold); | ||
119 | DEBUGFS_ADD(short_retry_limit); | ||
120 | DEBUGFS_ADD(long_retry_limit); | ||
121 | DEBUGFS_ADD(ht40allow_map); | ||
122 | } | ||
123 | |||
124 | void cfg80211_debugfs_drv_del(struct cfg80211_registered_device *drv) | ||
125 | { | ||
126 | DEBUGFS_DEL(rts_threshold); | ||
127 | DEBUGFS_DEL(fragmentation_threshold); | ||
128 | DEBUGFS_DEL(short_retry_limit); | ||
129 | DEBUGFS_DEL(long_retry_limit); | ||
130 | DEBUGFS_DEL(ht40allow_map); | ||
131 | } | ||
diff --git a/net/wireless/debugfs.h b/net/wireless/debugfs.h new file mode 100644 index 000000000000..c226983ae66b --- /dev/null +++ b/net/wireless/debugfs.h | |||
@@ -0,0 +1,14 @@ | |||
1 | #ifndef __CFG80211_DEBUGFS_H | ||
2 | #define __CFG80211_DEBUGFS_H | ||
3 | |||
4 | #ifdef CONFIG_CFG80211_DEBUGFS | ||
5 | void cfg80211_debugfs_drv_add(struct cfg80211_registered_device *drv); | ||
6 | void cfg80211_debugfs_drv_del(struct cfg80211_registered_device *drv); | ||
7 | #else | ||
8 | static inline | ||
9 | void cfg80211_debugfs_drv_add(struct cfg80211_registered_device *drv) {} | ||
10 | static inline | ||
11 | void cfg80211_debugfs_drv_del(struct cfg80211_registered_device *drv) {} | ||
12 | #endif | ||
13 | |||
14 | #endif /* __CFG80211_DEBUGFS_H */ | ||
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index a3a152f55dd0..56d729c43b31 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c | |||
@@ -77,6 +77,7 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = { | |||
77 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | 77 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
78 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | 78 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
79 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | 79 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
80 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, | ||
80 | 81 | ||
81 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | 82 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
82 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | 83 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
@@ -492,7 +493,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) | |||
492 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | 493 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
493 | struct ieee80211_channel *chan; | 494 | struct ieee80211_channel *chan; |
494 | struct ieee80211_sta_ht_cap *ht_cap; | 495 | struct ieee80211_sta_ht_cap *ht_cap; |
495 | u32 freq, sec_freq; | 496 | u32 freq; |
496 | 497 | ||
497 | if (!rdev->ops->set_channel) { | 498 | if (!rdev->ops->set_channel) { |
498 | result = -EOPNOTSUPP; | 499 | result = -EOPNOTSUPP; |
@@ -518,33 +519,28 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) | |||
518 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | 519 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
519 | goto bad_res; | 520 | goto bad_res; |
520 | 521 | ||
521 | if (channel_type == NL80211_CHAN_HT40MINUS) | 522 | if (channel_type == NL80211_CHAN_HT40MINUS && |
522 | sec_freq = freq - 20; | 523 | (chan->flags & IEEE80211_CHAN_NO_HT40MINUS)) |
523 | else if (channel_type == NL80211_CHAN_HT40PLUS) | 524 | goto bad_res; |
524 | sec_freq = freq + 20; | 525 | else if (channel_type == NL80211_CHAN_HT40PLUS && |
525 | else | 526 | (chan->flags & IEEE80211_CHAN_NO_HT40PLUS)) |
526 | sec_freq = 0; | ||
527 | |||
528 | ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap; | ||
529 | |||
530 | /* no HT capabilities */ | ||
531 | if (channel_type != NL80211_CHAN_NO_HT && | ||
532 | !ht_cap->ht_supported) | ||
533 | goto bad_res; | 527 | goto bad_res; |
534 | 528 | ||
535 | if (sec_freq) { | 529 | /* |
536 | struct ieee80211_channel *schan; | 530 | * At this point we know if that if HT40 was requested |
531 | * we are allowed to use it and the extension channel | ||
532 | * exists. | ||
533 | */ | ||
534 | |||
535 | ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap; | ||
537 | 536 | ||
538 | /* no 40 MHz capabilities */ | 537 | /* no HT capabilities or intolerant */ |
538 | if (channel_type != NL80211_CHAN_NO_HT) { | ||
539 | if (!ht_cap->ht_supported) | ||
540 | goto bad_res; | ||
539 | if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) || | 541 | if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) || |
540 | (ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT)) | 542 | (ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT)) |
541 | goto bad_res; | 543 | goto bad_res; |
542 | |||
543 | schan = ieee80211_get_channel(&rdev->wiphy, sec_freq); | ||
544 | |||
545 | /* Secondary channel not allowed */ | ||
546 | if (!schan || schan->flags & IEEE80211_CHAN_DISABLED) | ||
547 | goto bad_res; | ||
548 | } | 544 | } |
549 | 545 | ||
550 | result = rdev->ops->set_channel(&rdev->wiphy, chan, | 546 | result = rdev->ops->set_channel(&rdev->wiphy, chan, |
@@ -2571,18 +2567,24 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) | |||
2571 | rem_reg_rules) { | 2567 | rem_reg_rules) { |
2572 | num_rules++; | 2568 | num_rules++; |
2573 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | 2569 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
2574 | goto bad_reg; | 2570 | return -EINVAL; |
2575 | } | 2571 | } |
2576 | 2572 | ||
2577 | if (!reg_is_valid_request(alpha2)) | 2573 | mutex_lock(&cfg80211_mutex); |
2578 | return -EINVAL; | 2574 | |
2575 | if (!reg_is_valid_request(alpha2)) { | ||
2576 | r = -EINVAL; | ||
2577 | goto bad_reg; | ||
2578 | } | ||
2579 | 2579 | ||
2580 | size_of_regd = sizeof(struct ieee80211_regdomain) + | 2580 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
2581 | (num_rules * sizeof(struct ieee80211_reg_rule)); | 2581 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
2582 | 2582 | ||
2583 | rd = kzalloc(size_of_regd, GFP_KERNEL); | 2583 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
2584 | if (!rd) | 2584 | if (!rd) { |
2585 | return -ENOMEM; | 2585 | r = -ENOMEM; |
2586 | goto bad_reg; | ||
2587 | } | ||
2586 | 2588 | ||
2587 | rd->n_reg_rules = num_rules; | 2589 | rd->n_reg_rules = num_rules; |
2588 | rd->alpha2[0] = alpha2[0]; | 2590 | rd->alpha2[0] = alpha2[0]; |
@@ -2599,20 +2601,24 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) | |||
2599 | 2601 | ||
2600 | rule_idx++; | 2602 | rule_idx++; |
2601 | 2603 | ||
2602 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) | 2604 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
2605 | r = -EINVAL; | ||
2603 | goto bad_reg; | 2606 | goto bad_reg; |
2607 | } | ||
2604 | } | 2608 | } |
2605 | 2609 | ||
2606 | BUG_ON(rule_idx != num_rules); | 2610 | BUG_ON(rule_idx != num_rules); |
2607 | 2611 | ||
2608 | mutex_lock(&cfg80211_mutex); | ||
2609 | r = set_regdom(rd); | 2612 | r = set_regdom(rd); |
2613 | |||
2610 | mutex_unlock(&cfg80211_mutex); | 2614 | mutex_unlock(&cfg80211_mutex); |
2615 | |||
2611 | return r; | 2616 | return r; |
2612 | 2617 | ||
2613 | bad_reg: | 2618 | bad_reg: |
2619 | mutex_unlock(&cfg80211_mutex); | ||
2614 | kfree(rd); | 2620 | kfree(rd); |
2615 | return -EINVAL; | 2621 | return r; |
2616 | } | 2622 | } |
2617 | 2623 | ||
2618 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) | 2624 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 537af62ec42b..df0ced9405d3 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c | |||
@@ -48,12 +48,6 @@ static struct regulatory_request *last_request; | |||
48 | /* To trigger userspace events */ | 48 | /* To trigger userspace events */ |
49 | static struct platform_device *reg_pdev; | 49 | static struct platform_device *reg_pdev; |
50 | 50 | ||
51 | /* Keep the ordering from large to small */ | ||
52 | static u32 supported_bandwidths[] = { | ||
53 | MHZ_TO_KHZ(40), | ||
54 | MHZ_TO_KHZ(20), | ||
55 | }; | ||
56 | |||
57 | /* | 51 | /* |
58 | * Central wireless core regulatory domains, we only need two, | 52 | * Central wireless core regulatory domains, we only need two, |
59 | * the current one and a world regulatory domain in case we have no | 53 | * the current one and a world regulatory domain in case we have no |
@@ -388,6 +382,8 @@ static int call_crda(const char *alpha2) | |||
388 | /* Used by nl80211 before kmalloc'ing our regulatory domain */ | 382 | /* Used by nl80211 before kmalloc'ing our regulatory domain */ |
389 | bool reg_is_valid_request(const char *alpha2) | 383 | bool reg_is_valid_request(const char *alpha2) |
390 | { | 384 | { |
385 | assert_cfg80211_lock(); | ||
386 | |||
391 | if (!last_request) | 387 | if (!last_request) |
392 | return false; | 388 | return false; |
393 | 389 | ||
@@ -435,19 +431,20 @@ static bool is_valid_rd(const struct ieee80211_regdomain *rd) | |||
435 | return true; | 431 | return true; |
436 | } | 432 | } |
437 | 433 | ||
438 | /* Returns value in KHz */ | 434 | static bool reg_does_bw_fit(const struct ieee80211_freq_range *freq_range, |
439 | static u32 freq_max_bandwidth(const struct ieee80211_freq_range *freq_range, | 435 | u32 center_freq_khz, |
440 | u32 freq) | 436 | u32 bw_khz) |
441 | { | 437 | { |
442 | unsigned int i; | 438 | u32 start_freq_khz, end_freq_khz; |
443 | for (i = 0; i < ARRAY_SIZE(supported_bandwidths); i++) { | 439 | |
444 | u32 start_freq_khz = freq - supported_bandwidths[i]/2; | 440 | start_freq_khz = center_freq_khz - (bw_khz/2); |
445 | u32 end_freq_khz = freq + supported_bandwidths[i]/2; | 441 | end_freq_khz = center_freq_khz + (bw_khz/2); |
446 | if (start_freq_khz >= freq_range->start_freq_khz && | 442 | |
447 | end_freq_khz <= freq_range->end_freq_khz) | 443 | if (start_freq_khz >= freq_range->start_freq_khz && |
448 | return supported_bandwidths[i]; | 444 | end_freq_khz <= freq_range->end_freq_khz) |
449 | } | 445 | return true; |
450 | return 0; | 446 | |
447 | return false; | ||
451 | } | 448 | } |
452 | 449 | ||
453 | /** | 450 | /** |
@@ -847,14 +844,17 @@ static u32 map_regdom_flags(u32 rd_flags) | |||
847 | 844 | ||
848 | static int freq_reg_info_regd(struct wiphy *wiphy, | 845 | static int freq_reg_info_regd(struct wiphy *wiphy, |
849 | u32 center_freq, | 846 | u32 center_freq, |
850 | u32 *bandwidth, | 847 | u32 desired_bw_khz, |
851 | const struct ieee80211_reg_rule **reg_rule, | 848 | const struct ieee80211_reg_rule **reg_rule, |
852 | const struct ieee80211_regdomain *custom_regd) | 849 | const struct ieee80211_regdomain *custom_regd) |
853 | { | 850 | { |
854 | int i; | 851 | int i; |
855 | bool band_rule_found = false; | 852 | bool band_rule_found = false; |
856 | const struct ieee80211_regdomain *regd; | 853 | const struct ieee80211_regdomain *regd; |
857 | u32 max_bandwidth = 0; | 854 | bool bw_fits = false; |
855 | |||
856 | if (!desired_bw_khz) | ||
857 | desired_bw_khz = MHZ_TO_KHZ(20); | ||
858 | 858 | ||
859 | regd = custom_regd ? custom_regd : cfg80211_regdomain; | 859 | regd = custom_regd ? custom_regd : cfg80211_regdomain; |
860 | 860 | ||
@@ -887,38 +887,54 @@ static int freq_reg_info_regd(struct wiphy *wiphy, | |||
887 | if (!band_rule_found) | 887 | if (!band_rule_found) |
888 | band_rule_found = freq_in_rule_band(fr, center_freq); | 888 | band_rule_found = freq_in_rule_band(fr, center_freq); |
889 | 889 | ||
890 | max_bandwidth = freq_max_bandwidth(fr, center_freq); | 890 | bw_fits = reg_does_bw_fit(fr, |
891 | center_freq, | ||
892 | desired_bw_khz); | ||
891 | 893 | ||
892 | if (max_bandwidth && *bandwidth <= max_bandwidth) { | 894 | if (band_rule_found && bw_fits) { |
893 | *reg_rule = rr; | 895 | *reg_rule = rr; |
894 | *bandwidth = max_bandwidth; | 896 | return 0; |
895 | break; | ||
896 | } | 897 | } |
897 | } | 898 | } |
898 | 899 | ||
899 | if (!band_rule_found) | 900 | if (!band_rule_found) |
900 | return -ERANGE; | 901 | return -ERANGE; |
901 | 902 | ||
902 | return !max_bandwidth; | 903 | return -EINVAL; |
903 | } | 904 | } |
904 | EXPORT_SYMBOL(freq_reg_info); | 905 | EXPORT_SYMBOL(freq_reg_info); |
905 | 906 | ||
906 | int freq_reg_info(struct wiphy *wiphy, u32 center_freq, u32 *bandwidth, | 907 | int freq_reg_info(struct wiphy *wiphy, |
907 | const struct ieee80211_reg_rule **reg_rule) | 908 | u32 center_freq, |
909 | u32 desired_bw_khz, | ||
910 | const struct ieee80211_reg_rule **reg_rule) | ||
908 | { | 911 | { |
909 | assert_cfg80211_lock(); | 912 | assert_cfg80211_lock(); |
910 | return freq_reg_info_regd(wiphy, center_freq, | 913 | return freq_reg_info_regd(wiphy, |
911 | bandwidth, reg_rule, NULL); | 914 | center_freq, |
915 | desired_bw_khz, | ||
916 | reg_rule, | ||
917 | NULL); | ||
912 | } | 918 | } |
913 | 919 | ||
920 | /* | ||
921 | * Note that right now we assume the desired channel bandwidth | ||
922 | * is always 20 MHz for each individual channel (HT40 uses 20 MHz | ||
923 | * per channel, the primary and the extension channel). To support | ||
924 | * smaller custom bandwidths such as 5 MHz or 10 MHz we'll need a | ||
925 | * new ieee80211_channel.target_bw and re run the regulatory check | ||
926 | * on the wiphy with the target_bw specified. Then we can simply use | ||
927 | * that below for the desired_bw_khz below. | ||
928 | */ | ||
914 | static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band, | 929 | static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band, |
915 | unsigned int chan_idx) | 930 | unsigned int chan_idx) |
916 | { | 931 | { |
917 | int r; | 932 | int r; |
918 | u32 flags; | 933 | u32 flags, bw_flags = 0; |
919 | u32 max_bandwidth = 0; | 934 | u32 desired_bw_khz = MHZ_TO_KHZ(20); |
920 | const struct ieee80211_reg_rule *reg_rule = NULL; | 935 | const struct ieee80211_reg_rule *reg_rule = NULL; |
921 | const struct ieee80211_power_rule *power_rule = NULL; | 936 | const struct ieee80211_power_rule *power_rule = NULL; |
937 | const struct ieee80211_freq_range *freq_range = NULL; | ||
922 | struct ieee80211_supported_band *sband; | 938 | struct ieee80211_supported_band *sband; |
923 | struct ieee80211_channel *chan; | 939 | struct ieee80211_channel *chan; |
924 | struct wiphy *request_wiphy = NULL; | 940 | struct wiphy *request_wiphy = NULL; |
@@ -933,8 +949,10 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band, | |||
933 | 949 | ||
934 | flags = chan->orig_flags; | 950 | flags = chan->orig_flags; |
935 | 951 | ||
936 | r = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq), | 952 | r = freq_reg_info(wiphy, |
937 | &max_bandwidth, ®_rule); | 953 | MHZ_TO_KHZ(chan->center_freq), |
954 | desired_bw_khz, | ||
955 | ®_rule); | ||
938 | 956 | ||
939 | if (r) { | 957 | if (r) { |
940 | /* | 958 | /* |
@@ -977,6 +995,10 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band, | |||
977 | } | 995 | } |
978 | 996 | ||
979 | power_rule = ®_rule->power_rule; | 997 | power_rule = ®_rule->power_rule; |
998 | freq_range = ®_rule->freq_range; | ||
999 | |||
1000 | if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(40)) | ||
1001 | bw_flags = IEEE80211_CHAN_NO_HT40; | ||
980 | 1002 | ||
981 | if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER && | 1003 | if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER && |
982 | request_wiphy && request_wiphy == wiphy && | 1004 | request_wiphy && request_wiphy == wiphy && |
@@ -987,19 +1009,19 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band, | |||
987 | * settings | 1009 | * settings |
988 | */ | 1010 | */ |
989 | chan->flags = chan->orig_flags = | 1011 | chan->flags = chan->orig_flags = |
990 | map_regdom_flags(reg_rule->flags); | 1012 | map_regdom_flags(reg_rule->flags) | bw_flags; |
991 | chan->max_antenna_gain = chan->orig_mag = | 1013 | chan->max_antenna_gain = chan->orig_mag = |
992 | (int) MBI_TO_DBI(power_rule->max_antenna_gain); | 1014 | (int) MBI_TO_DBI(power_rule->max_antenna_gain); |
993 | chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth); | 1015 | chan->max_bandwidth = KHZ_TO_MHZ(desired_bw_khz); |
994 | chan->max_power = chan->orig_mpwr = | 1016 | chan->max_power = chan->orig_mpwr = |
995 | (int) MBM_TO_DBM(power_rule->max_eirp); | 1017 | (int) MBM_TO_DBM(power_rule->max_eirp); |
996 | return; | 1018 | return; |
997 | } | 1019 | } |
998 | 1020 | ||
999 | chan->flags = flags | map_regdom_flags(reg_rule->flags); | 1021 | chan->flags = flags | bw_flags | map_regdom_flags(reg_rule->flags); |
1000 | chan->max_antenna_gain = min(chan->orig_mag, | 1022 | chan->max_antenna_gain = min(chan->orig_mag, |
1001 | (int) MBI_TO_DBI(power_rule->max_antenna_gain)); | 1023 | (int) MBI_TO_DBI(power_rule->max_antenna_gain)); |
1002 | chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth); | 1024 | chan->max_bandwidth = KHZ_TO_MHZ(desired_bw_khz); |
1003 | if (chan->orig_mpwr) | 1025 | if (chan->orig_mpwr) |
1004 | chan->max_power = min(chan->orig_mpwr, | 1026 | chan->max_power = min(chan->orig_mpwr, |
1005 | (int) MBM_TO_DBM(power_rule->max_eirp)); | 1027 | (int) MBM_TO_DBM(power_rule->max_eirp)); |
@@ -1156,6 +1178,93 @@ static void reg_process_beacons(struct wiphy *wiphy) | |||
1156 | wiphy_update_beacon_reg(wiphy); | 1178 | wiphy_update_beacon_reg(wiphy); |
1157 | } | 1179 | } |
1158 | 1180 | ||
1181 | static bool is_ht40_not_allowed(struct ieee80211_channel *chan) | ||
1182 | { | ||
1183 | if (!chan) | ||
1184 | return true; | ||
1185 | if (chan->flags & IEEE80211_CHAN_DISABLED) | ||
1186 | return true; | ||
1187 | /* This would happen when regulatory rules disallow HT40 completely */ | ||
1188 | if (IEEE80211_CHAN_NO_HT40 == (chan->flags & (IEEE80211_CHAN_NO_HT40))) | ||
1189 | return true; | ||
1190 | return false; | ||
1191 | } | ||
1192 | |||
1193 | static void reg_process_ht_flags_channel(struct wiphy *wiphy, | ||
1194 | enum ieee80211_band band, | ||
1195 | unsigned int chan_idx) | ||
1196 | { | ||
1197 | struct ieee80211_supported_band *sband; | ||
1198 | struct ieee80211_channel *channel; | ||
1199 | struct ieee80211_channel *channel_before = NULL, *channel_after = NULL; | ||
1200 | unsigned int i; | ||
1201 | |||
1202 | assert_cfg80211_lock(); | ||
1203 | |||
1204 | sband = wiphy->bands[band]; | ||
1205 | BUG_ON(chan_idx >= sband->n_channels); | ||
1206 | channel = &sband->channels[chan_idx]; | ||
1207 | |||
1208 | if (is_ht40_not_allowed(channel)) { | ||
1209 | channel->flags |= IEEE80211_CHAN_NO_HT40; | ||
1210 | return; | ||
1211 | } | ||
1212 | |||
1213 | /* | ||
1214 | * We need to ensure the extension channels exist to | ||
1215 | * be able to use HT40- or HT40+, this finds them (or not) | ||
1216 | */ | ||
1217 | for (i = 0; i < sband->n_channels; i++) { | ||
1218 | struct ieee80211_channel *c = &sband->channels[i]; | ||
1219 | if (c->center_freq == (channel->center_freq - 20)) | ||
1220 | channel_before = c; | ||
1221 | if (c->center_freq == (channel->center_freq + 20)) | ||
1222 | channel_after = c; | ||
1223 | } | ||
1224 | |||
1225 | /* | ||
1226 | * Please note that this assumes target bandwidth is 20 MHz, | ||
1227 | * if that ever changes we also need to change the below logic | ||
1228 | * to include that as well. | ||
1229 | */ | ||
1230 | if (is_ht40_not_allowed(channel_before)) | ||
1231 | channel->flags |= IEEE80211_CHAN_NO_HT40MINUS; | ||
1232 | else | ||
1233 | channel->flags &= ~IEEE80211_CHAN_NO_HT40MINUS; | ||
1234 | |||
1235 | if (is_ht40_not_allowed(channel_after)) | ||
1236 | channel->flags |= IEEE80211_CHAN_NO_HT40PLUS; | ||
1237 | else | ||
1238 | channel->flags &= ~IEEE80211_CHAN_NO_HT40PLUS; | ||
1239 | } | ||
1240 | |||
1241 | static void reg_process_ht_flags_band(struct wiphy *wiphy, | ||
1242 | enum ieee80211_band band) | ||
1243 | { | ||
1244 | unsigned int i; | ||
1245 | struct ieee80211_supported_band *sband; | ||
1246 | |||
1247 | BUG_ON(!wiphy->bands[band]); | ||
1248 | sband = wiphy->bands[band]; | ||
1249 | |||
1250 | for (i = 0; i < sband->n_channels; i++) | ||
1251 | reg_process_ht_flags_channel(wiphy, band, i); | ||
1252 | } | ||
1253 | |||
1254 | static void reg_process_ht_flags(struct wiphy *wiphy) | ||
1255 | { | ||
1256 | enum ieee80211_band band; | ||
1257 | |||
1258 | if (!wiphy) | ||
1259 | return; | ||
1260 | |||
1261 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | ||
1262 | if (wiphy->bands[band]) | ||
1263 | reg_process_ht_flags_band(wiphy, band); | ||
1264 | } | ||
1265 | |||
1266 | } | ||
1267 | |||
1159 | void wiphy_update_regulatory(struct wiphy *wiphy, | 1268 | void wiphy_update_regulatory(struct wiphy *wiphy, |
1160 | enum nl80211_reg_initiator initiator) | 1269 | enum nl80211_reg_initiator initiator) |
1161 | { | 1270 | { |
@@ -1169,6 +1278,7 @@ void wiphy_update_regulatory(struct wiphy *wiphy, | |||
1169 | } | 1278 | } |
1170 | out: | 1279 | out: |
1171 | reg_process_beacons(wiphy); | 1280 | reg_process_beacons(wiphy); |
1281 | reg_process_ht_flags(wiphy); | ||
1172 | if (wiphy->reg_notifier) | 1282 | if (wiphy->reg_notifier) |
1173 | wiphy->reg_notifier(wiphy, last_request); | 1283 | wiphy->reg_notifier(wiphy, last_request); |
1174 | } | 1284 | } |
@@ -1179,9 +1289,11 @@ static void handle_channel_custom(struct wiphy *wiphy, | |||
1179 | const struct ieee80211_regdomain *regd) | 1289 | const struct ieee80211_regdomain *regd) |
1180 | { | 1290 | { |
1181 | int r; | 1291 | int r; |
1182 | u32 max_bandwidth = 0; | 1292 | u32 desired_bw_khz = MHZ_TO_KHZ(20); |
1293 | u32 bw_flags = 0; | ||
1183 | const struct ieee80211_reg_rule *reg_rule = NULL; | 1294 | const struct ieee80211_reg_rule *reg_rule = NULL; |
1184 | const struct ieee80211_power_rule *power_rule = NULL; | 1295 | const struct ieee80211_power_rule *power_rule = NULL; |
1296 | const struct ieee80211_freq_range *freq_range = NULL; | ||
1185 | struct ieee80211_supported_band *sband; | 1297 | struct ieee80211_supported_band *sband; |
1186 | struct ieee80211_channel *chan; | 1298 | struct ieee80211_channel *chan; |
1187 | 1299 | ||
@@ -1191,8 +1303,11 @@ static void handle_channel_custom(struct wiphy *wiphy, | |||
1191 | BUG_ON(chan_idx >= sband->n_channels); | 1303 | BUG_ON(chan_idx >= sband->n_channels); |
1192 | chan = &sband->channels[chan_idx]; | 1304 | chan = &sband->channels[chan_idx]; |
1193 | 1305 | ||
1194 | r = freq_reg_info_regd(wiphy, MHZ_TO_KHZ(chan->center_freq), | 1306 | r = freq_reg_info_regd(wiphy, |
1195 | &max_bandwidth, ®_rule, regd); | 1307 | MHZ_TO_KHZ(chan->center_freq), |
1308 | desired_bw_khz, | ||
1309 | ®_rule, | ||
1310 | regd); | ||
1196 | 1311 | ||
1197 | if (r) { | 1312 | if (r) { |
1198 | chan->flags = IEEE80211_CHAN_DISABLED; | 1313 | chan->flags = IEEE80211_CHAN_DISABLED; |
@@ -1200,10 +1315,14 @@ static void handle_channel_custom(struct wiphy *wiphy, | |||
1200 | } | 1315 | } |
1201 | 1316 | ||
1202 | power_rule = ®_rule->power_rule; | 1317 | power_rule = ®_rule->power_rule; |
1318 | freq_range = ®_rule->freq_range; | ||
1203 | 1319 | ||
1204 | chan->flags |= map_regdom_flags(reg_rule->flags); | 1320 | if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(40)) |
1321 | bw_flags = IEEE80211_CHAN_NO_HT40; | ||
1322 | |||
1323 | chan->flags |= map_regdom_flags(reg_rule->flags) | bw_flags; | ||
1205 | chan->max_antenna_gain = (int) MBI_TO_DBI(power_rule->max_antenna_gain); | 1324 | chan->max_antenna_gain = (int) MBI_TO_DBI(power_rule->max_antenna_gain); |
1206 | chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth); | 1325 | chan->max_bandwidth = KHZ_TO_MHZ(desired_bw_khz); |
1207 | chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp); | 1326 | chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp); |
1208 | } | 1327 | } |
1209 | 1328 | ||
@@ -1225,13 +1344,22 @@ void wiphy_apply_custom_regulatory(struct wiphy *wiphy, | |||
1225 | const struct ieee80211_regdomain *regd) | 1344 | const struct ieee80211_regdomain *regd) |
1226 | { | 1345 | { |
1227 | enum ieee80211_band band; | 1346 | enum ieee80211_band band; |
1347 | unsigned int bands_set = 0; | ||
1228 | 1348 | ||
1229 | mutex_lock(&cfg80211_mutex); | 1349 | mutex_lock(&cfg80211_mutex); |
1230 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | 1350 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
1231 | if (wiphy->bands[band]) | 1351 | if (!wiphy->bands[band]) |
1232 | handle_band_custom(wiphy, band, regd); | 1352 | continue; |
1353 | handle_band_custom(wiphy, band, regd); | ||
1354 | bands_set++; | ||
1233 | } | 1355 | } |
1234 | mutex_unlock(&cfg80211_mutex); | 1356 | mutex_unlock(&cfg80211_mutex); |
1357 | |||
1358 | /* | ||
1359 | * no point in calling this if it won't have any effect | ||
1360 | * on your device's supportd bands. | ||
1361 | */ | ||
1362 | WARN_ON(!bands_set); | ||
1235 | } | 1363 | } |
1236 | EXPORT_SYMBOL(wiphy_apply_custom_regulatory); | 1364 | EXPORT_SYMBOL(wiphy_apply_custom_regulatory); |
1237 | 1365 | ||
diff --git a/net/wireless/util.c b/net/wireless/util.c index beb226e78cd7..d072bff463aa 100644 --- a/net/wireless/util.c +++ b/net/wireless/util.c | |||
@@ -4,7 +4,9 @@ | |||
4 | * Copyright 2007-2009 Johannes Berg <johannes@sipsolutions.net> | 4 | * Copyright 2007-2009 Johannes Berg <johannes@sipsolutions.net> |
5 | */ | 5 | */ |
6 | #include <linux/bitops.h> | 6 | #include <linux/bitops.h> |
7 | #include <linux/etherdevice.h> | ||
7 | #include <net/cfg80211.h> | 8 | #include <net/cfg80211.h> |
9 | #include <net/ip.h> | ||
8 | #include "core.h" | 10 | #include "core.h" |
9 | 11 | ||
10 | struct ieee80211_rate * | 12 | struct ieee80211_rate * |
@@ -181,5 +183,323 @@ int cfg80211_validate_key_settings(struct key_params *params, int key_idx, | |||
181 | return -EINVAL; | 183 | return -EINVAL; |
182 | } | 184 | } |
183 | 185 | ||
186 | if (params->seq) { | ||
187 | switch (params->cipher) { | ||
188 | case WLAN_CIPHER_SUITE_WEP40: | ||
189 | case WLAN_CIPHER_SUITE_WEP104: | ||
190 | /* These ciphers do not use key sequence */ | ||
191 | return -EINVAL; | ||
192 | case WLAN_CIPHER_SUITE_TKIP: | ||
193 | case WLAN_CIPHER_SUITE_CCMP: | ||
194 | case WLAN_CIPHER_SUITE_AES_CMAC: | ||
195 | if (params->seq_len != 6) | ||
196 | return -EINVAL; | ||
197 | break; | ||
198 | } | ||
199 | } | ||
200 | |||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ | ||
205 | /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ | ||
206 | const unsigned char rfc1042_header[] __aligned(2) = | ||
207 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; | ||
208 | EXPORT_SYMBOL(rfc1042_header); | ||
209 | |||
210 | /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ | ||
211 | const unsigned char bridge_tunnel_header[] __aligned(2) = | ||
212 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; | ||
213 | EXPORT_SYMBOL(bridge_tunnel_header); | ||
214 | |||
215 | unsigned int ieee80211_hdrlen(__le16 fc) | ||
216 | { | ||
217 | unsigned int hdrlen = 24; | ||
218 | |||
219 | if (ieee80211_is_data(fc)) { | ||
220 | if (ieee80211_has_a4(fc)) | ||
221 | hdrlen = 30; | ||
222 | if (ieee80211_is_data_qos(fc)) | ||
223 | hdrlen += IEEE80211_QOS_CTL_LEN; | ||
224 | goto out; | ||
225 | } | ||
226 | |||
227 | if (ieee80211_is_ctl(fc)) { | ||
228 | /* | ||
229 | * ACK and CTS are 10 bytes, all others 16. To see how | ||
230 | * to get this condition consider | ||
231 | * subtype mask: 0b0000000011110000 (0x00F0) | ||
232 | * ACK subtype: 0b0000000011010000 (0x00D0) | ||
233 | * CTS subtype: 0b0000000011000000 (0x00C0) | ||
234 | * bits that matter: ^^^ (0x00E0) | ||
235 | * value of those: 0b0000000011000000 (0x00C0) | ||
236 | */ | ||
237 | if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0)) | ||
238 | hdrlen = 10; | ||
239 | else | ||
240 | hdrlen = 16; | ||
241 | } | ||
242 | out: | ||
243 | return hdrlen; | ||
244 | } | ||
245 | EXPORT_SYMBOL(ieee80211_hdrlen); | ||
246 | |||
247 | unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb) | ||
248 | { | ||
249 | const struct ieee80211_hdr *hdr = | ||
250 | (const struct ieee80211_hdr *)skb->data; | ||
251 | unsigned int hdrlen; | ||
252 | |||
253 | if (unlikely(skb->len < 10)) | ||
254 | return 0; | ||
255 | hdrlen = ieee80211_hdrlen(hdr->frame_control); | ||
256 | if (unlikely(hdrlen > skb->len)) | ||
257 | return 0; | ||
258 | return hdrlen; | ||
259 | } | ||
260 | EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb); | ||
261 | |||
262 | int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr) | ||
263 | { | ||
264 | int ae = meshhdr->flags & MESH_FLAGS_AE; | ||
265 | /* 7.1.3.5a.2 */ | ||
266 | switch (ae) { | ||
267 | case 0: | ||
268 | return 6; | ||
269 | case 1: | ||
270 | return 12; | ||
271 | case 2: | ||
272 | return 18; | ||
273 | case 3: | ||
274 | return 24; | ||
275 | default: | ||
276 | return 6; | ||
277 | } | ||
278 | } | ||
279 | |||
280 | int ieee80211_data_to_8023(struct sk_buff *skb, u8 *addr, | ||
281 | enum nl80211_iftype iftype) | ||
282 | { | ||
283 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | ||
284 | u16 hdrlen, ethertype; | ||
285 | u8 *payload; | ||
286 | u8 dst[ETH_ALEN]; | ||
287 | u8 src[ETH_ALEN] __aligned(2); | ||
288 | |||
289 | if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) | ||
290 | return -1; | ||
291 | |||
292 | hdrlen = ieee80211_hdrlen(hdr->frame_control); | ||
293 | |||
294 | /* convert IEEE 802.11 header + possible LLC headers into Ethernet | ||
295 | * header | ||
296 | * IEEE 802.11 address fields: | ||
297 | * ToDS FromDS Addr1 Addr2 Addr3 Addr4 | ||
298 | * 0 0 DA SA BSSID n/a | ||
299 | * 0 1 DA BSSID SA n/a | ||
300 | * 1 0 BSSID SA DA n/a | ||
301 | * 1 1 RA TA DA SA | ||
302 | */ | ||
303 | memcpy(dst, ieee80211_get_DA(hdr), ETH_ALEN); | ||
304 | memcpy(src, ieee80211_get_SA(hdr), ETH_ALEN); | ||
305 | |||
306 | switch (hdr->frame_control & | ||
307 | cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) { | ||
308 | case cpu_to_le16(IEEE80211_FCTL_TODS): | ||
309 | if (unlikely(iftype != NL80211_IFTYPE_AP && | ||
310 | iftype != NL80211_IFTYPE_AP_VLAN)) | ||
311 | return -1; | ||
312 | break; | ||
313 | case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS): | ||
314 | if (unlikely(iftype != NL80211_IFTYPE_WDS && | ||
315 | iftype != NL80211_IFTYPE_MESH_POINT)) | ||
316 | return -1; | ||
317 | if (iftype == NL80211_IFTYPE_MESH_POINT) { | ||
318 | struct ieee80211s_hdr *meshdr = | ||
319 | (struct ieee80211s_hdr *) (skb->data + hdrlen); | ||
320 | hdrlen += ieee80211_get_mesh_hdrlen(meshdr); | ||
321 | if (meshdr->flags & MESH_FLAGS_AE_A5_A6) { | ||
322 | memcpy(dst, meshdr->eaddr1, ETH_ALEN); | ||
323 | memcpy(src, meshdr->eaddr2, ETH_ALEN); | ||
324 | } | ||
325 | } | ||
326 | break; | ||
327 | case cpu_to_le16(IEEE80211_FCTL_FROMDS): | ||
328 | if (iftype != NL80211_IFTYPE_STATION || | ||
329 | (is_multicast_ether_addr(dst) && | ||
330 | !compare_ether_addr(src, addr))) | ||
331 | return -1; | ||
332 | break; | ||
333 | case cpu_to_le16(0): | ||
334 | if (iftype != NL80211_IFTYPE_ADHOC) | ||
335 | return -1; | ||
336 | break; | ||
337 | } | ||
338 | |||
339 | if (unlikely(skb->len - hdrlen < 8)) | ||
340 | return -1; | ||
341 | |||
342 | payload = skb->data + hdrlen; | ||
343 | ethertype = (payload[6] << 8) | payload[7]; | ||
344 | |||
345 | if (likely((compare_ether_addr(payload, rfc1042_header) == 0 && | ||
346 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || | ||
347 | compare_ether_addr(payload, bridge_tunnel_header) == 0)) { | ||
348 | /* remove RFC1042 or Bridge-Tunnel encapsulation and | ||
349 | * replace EtherType */ | ||
350 | skb_pull(skb, hdrlen + 6); | ||
351 | memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); | ||
352 | memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); | ||
353 | } else { | ||
354 | struct ethhdr *ehdr; | ||
355 | __be16 len; | ||
356 | |||
357 | skb_pull(skb, hdrlen); | ||
358 | len = htons(skb->len); | ||
359 | ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr)); | ||
360 | memcpy(ehdr->h_dest, dst, ETH_ALEN); | ||
361 | memcpy(ehdr->h_source, src, ETH_ALEN); | ||
362 | ehdr->h_proto = len; | ||
363 | } | ||
364 | return 0; | ||
365 | } | ||
366 | EXPORT_SYMBOL(ieee80211_data_to_8023); | ||
367 | |||
368 | int ieee80211_data_from_8023(struct sk_buff *skb, u8 *addr, | ||
369 | enum nl80211_iftype iftype, u8 *bssid, bool qos) | ||
370 | { | ||
371 | struct ieee80211_hdr hdr; | ||
372 | u16 hdrlen, ethertype; | ||
373 | __le16 fc; | ||
374 | const u8 *encaps_data; | ||
375 | int encaps_len, skip_header_bytes; | ||
376 | int nh_pos, h_pos; | ||
377 | int head_need; | ||
378 | |||
379 | if (unlikely(skb->len < ETH_HLEN)) | ||
380 | return -EINVAL; | ||
381 | |||
382 | nh_pos = skb_network_header(skb) - skb->data; | ||
383 | h_pos = skb_transport_header(skb) - skb->data; | ||
384 | |||
385 | /* convert Ethernet header to proper 802.11 header (based on | ||
386 | * operation mode) */ | ||
387 | ethertype = (skb->data[12] << 8) | skb->data[13]; | ||
388 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA); | ||
389 | |||
390 | switch (iftype) { | ||
391 | case NL80211_IFTYPE_AP: | ||
392 | case NL80211_IFTYPE_AP_VLAN: | ||
393 | fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); | ||
394 | /* DA BSSID SA */ | ||
395 | memcpy(hdr.addr1, skb->data, ETH_ALEN); | ||
396 | memcpy(hdr.addr2, addr, ETH_ALEN); | ||
397 | memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN); | ||
398 | hdrlen = 24; | ||
399 | break; | ||
400 | case NL80211_IFTYPE_STATION: | ||
401 | fc |= cpu_to_le16(IEEE80211_FCTL_TODS); | ||
402 | /* BSSID SA DA */ | ||
403 | memcpy(hdr.addr1, bssid, ETH_ALEN); | ||
404 | memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); | ||
405 | memcpy(hdr.addr3, skb->data, ETH_ALEN); | ||
406 | hdrlen = 24; | ||
407 | break; | ||
408 | case NL80211_IFTYPE_ADHOC: | ||
409 | /* DA SA BSSID */ | ||
410 | memcpy(hdr.addr1, skb->data, ETH_ALEN); | ||
411 | memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); | ||
412 | memcpy(hdr.addr3, bssid, ETH_ALEN); | ||
413 | hdrlen = 24; | ||
414 | break; | ||
415 | default: | ||
416 | return -EOPNOTSUPP; | ||
417 | } | ||
418 | |||
419 | if (qos) { | ||
420 | fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA); | ||
421 | hdrlen += 2; | ||
422 | } | ||
423 | |||
424 | hdr.frame_control = fc; | ||
425 | hdr.duration_id = 0; | ||
426 | hdr.seq_ctrl = 0; | ||
427 | |||
428 | skip_header_bytes = ETH_HLEN; | ||
429 | if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) { | ||
430 | encaps_data = bridge_tunnel_header; | ||
431 | encaps_len = sizeof(bridge_tunnel_header); | ||
432 | skip_header_bytes -= 2; | ||
433 | } else if (ethertype > 0x600) { | ||
434 | encaps_data = rfc1042_header; | ||
435 | encaps_len = sizeof(rfc1042_header); | ||
436 | skip_header_bytes -= 2; | ||
437 | } else { | ||
438 | encaps_data = NULL; | ||
439 | encaps_len = 0; | ||
440 | } | ||
441 | |||
442 | skb_pull(skb, skip_header_bytes); | ||
443 | nh_pos -= skip_header_bytes; | ||
444 | h_pos -= skip_header_bytes; | ||
445 | |||
446 | head_need = hdrlen + encaps_len - skb_headroom(skb); | ||
447 | |||
448 | if (head_need > 0 || skb_cloned(skb)) { | ||
449 | head_need = max(head_need, 0); | ||
450 | if (head_need) | ||
451 | skb_orphan(skb); | ||
452 | |||
453 | if (pskb_expand_head(skb, head_need, 0, GFP_ATOMIC)) { | ||
454 | printk(KERN_ERR "failed to reallocate Tx buffer\n"); | ||
455 | return -ENOMEM; | ||
456 | } | ||
457 | skb->truesize += head_need; | ||
458 | } | ||
459 | |||
460 | if (encaps_data) { | ||
461 | memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len); | ||
462 | nh_pos += encaps_len; | ||
463 | h_pos += encaps_len; | ||
464 | } | ||
465 | |||
466 | memcpy(skb_push(skb, hdrlen), &hdr, hdrlen); | ||
467 | |||
468 | nh_pos += hdrlen; | ||
469 | h_pos += hdrlen; | ||
470 | |||
471 | /* Update skb pointers to various headers since this modified frame | ||
472 | * is going to go through Linux networking code that may potentially | ||
473 | * need things like pointer to IP header. */ | ||
474 | skb_set_mac_header(skb, 0); | ||
475 | skb_set_network_header(skb, nh_pos); | ||
476 | skb_set_transport_header(skb, h_pos); | ||
477 | |||
184 | return 0; | 478 | return 0; |
185 | } | 479 | } |
480 | EXPORT_SYMBOL(ieee80211_data_from_8023); | ||
481 | |||
482 | /* Given a data frame determine the 802.1p/1d tag to use. */ | ||
483 | unsigned int cfg80211_classify8021d(struct sk_buff *skb) | ||
484 | { | ||
485 | unsigned int dscp; | ||
486 | |||
487 | /* skb->priority values from 256->263 are magic values to | ||
488 | * directly indicate a specific 802.1d priority. This is used | ||
489 | * to allow 802.1d priority to be passed directly in from VLAN | ||
490 | * tags, etc. | ||
491 | */ | ||
492 | if (skb->priority >= 256 && skb->priority <= 263) | ||
493 | return skb->priority - 256; | ||
494 | |||
495 | switch (skb->protocol) { | ||
496 | case htons(ETH_P_IP): | ||
497 | dscp = ip_hdr(skb)->tos & 0xfc; | ||
498 | break; | ||
499 | default: | ||
500 | return 0; | ||
501 | } | ||
502 | |||
503 | return dscp >> 5; | ||
504 | } | ||
505 | EXPORT_SYMBOL(cfg80211_classify8021d); | ||
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c index f98090b90fbf..711e00a0c9b5 100644 --- a/net/wireless/wext-compat.c +++ b/net/wireless/wext-compat.c | |||
@@ -504,6 +504,13 @@ static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev, | |||
504 | else if (idx == wdev->wext.default_mgmt_key) | 504 | else if (idx == wdev->wext.default_mgmt_key) |
505 | wdev->wext.default_mgmt_key = -1; | 505 | wdev->wext.default_mgmt_key = -1; |
506 | } | 506 | } |
507 | /* | ||
508 | * Applications using wireless extensions expect to be | ||
509 | * able to delete keys that don't exist, so allow that. | ||
510 | */ | ||
511 | if (err == -ENOENT) | ||
512 | return 0; | ||
513 | |||
507 | return err; | 514 | return err; |
508 | } else { | 515 | } else { |
509 | if (addr) | 516 | if (addr) |
diff --git a/net/wireless/wext.c b/net/wireless/wext.c index d3bbef70cc7c..22378daceb94 100644 --- a/net/wireless/wext.c +++ b/net/wireless/wext.c | |||
@@ -636,8 +636,10 @@ static void wireless_seq_printf_stats(struct seq_file *seq, | |||
636 | /* | 636 | /* |
637 | * Print info for /proc/net/wireless (print all entries) | 637 | * Print info for /proc/net/wireless (print all entries) |
638 | */ | 638 | */ |
639 | static int wireless_seq_show(struct seq_file *seq, void *v) | 639 | static int wireless_dev_seq_show(struct seq_file *seq, void *v) |
640 | { | 640 | { |
641 | might_sleep(); | ||
642 | |||
641 | if (v == SEQ_START_TOKEN) | 643 | if (v == SEQ_START_TOKEN) |
642 | seq_printf(seq, "Inter-| sta-| Quality | Discarded " | 644 | seq_printf(seq, "Inter-| sta-| Quality | Discarded " |
643 | "packets | Missed | WE\n" | 645 | "packets | Missed | WE\n" |
@@ -651,21 +653,41 @@ static int wireless_seq_show(struct seq_file *seq, void *v) | |||
651 | 653 | ||
652 | static void *wireless_dev_seq_start(struct seq_file *seq, loff_t *pos) | 654 | static void *wireless_dev_seq_start(struct seq_file *seq, loff_t *pos) |
653 | { | 655 | { |
656 | struct net *net = seq_file_net(seq); | ||
657 | loff_t off; | ||
658 | struct net_device *dev; | ||
659 | |||
654 | rtnl_lock(); | 660 | rtnl_lock(); |
655 | return dev_seq_start(seq, pos); | 661 | if (!*pos) |
662 | return SEQ_START_TOKEN; | ||
663 | |||
664 | off = 1; | ||
665 | for_each_netdev(net, dev) | ||
666 | if (off++ == *pos) | ||
667 | return dev; | ||
668 | return NULL; | ||
669 | } | ||
670 | |||
671 | static void *wireless_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) | ||
672 | { | ||
673 | struct net *net = seq_file_net(seq); | ||
674 | |||
675 | ++*pos; | ||
676 | |||
677 | return v == SEQ_START_TOKEN ? | ||
678 | first_net_device(net) : next_net_device(v); | ||
656 | } | 679 | } |
657 | 680 | ||
658 | static void wireless_dev_seq_stop(struct seq_file *seq, void *v) | 681 | static void wireless_dev_seq_stop(struct seq_file *seq, void *v) |
659 | { | 682 | { |
660 | dev_seq_stop(seq, v); | ||
661 | rtnl_unlock(); | 683 | rtnl_unlock(); |
662 | } | 684 | } |
663 | 685 | ||
664 | static const struct seq_operations wireless_seq_ops = { | 686 | static const struct seq_operations wireless_seq_ops = { |
665 | .start = wireless_dev_seq_start, | 687 | .start = wireless_dev_seq_start, |
666 | .next = dev_seq_next, | 688 | .next = wireless_dev_seq_next, |
667 | .stop = wireless_dev_seq_stop, | 689 | .stop = wireless_dev_seq_stop, |
668 | .show = wireless_seq_show, | 690 | .show = wireless_dev_seq_show, |
669 | }; | 691 | }; |
670 | 692 | ||
671 | static int seq_open_wireless(struct inode *inode, struct file *file) | 693 | static int seq_open_wireless(struct inode *inode, struct file *file) |