diff options
author | David S. Miller <davem@davemloft.net> | 2009-12-25 19:34:56 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-12-25 19:34:56 -0500 |
commit | d346f49d0badd80aa9fc699fa9c6d5b23e778eb6 (patch) | |
tree | 9e9698ffe7966fbe7ce924a30843f87cdfa2646e /net/wireless | |
parent | d87fd25d5ac4cd044e21b749a8f6cac90f093c71 (diff) | |
parent | b6ce5c33001b1dc83e6a1a6f30c5dccccea651b6 (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/.gitignore | 1 | ||||
-rw-r--r-- | net/wireless/Kconfig | 16 | ||||
-rw-r--r-- | net/wireless/Makefile | 6 | ||||
-rw-r--r-- | net/wireless/core.h | 2 | ||||
-rw-r--r-- | net/wireless/db.txt | 17 | ||||
-rw-r--r-- | net/wireless/genregdb.awk | 118 | ||||
-rw-r--r-- | net/wireless/mlme.c | 11 | ||||
-rw-r--r-- | net/wireless/nl80211.c | 37 | ||||
-rw-r--r-- | net/wireless/reg.c | 120 | ||||
-rw-r--r-- | net/wireless/regdb.h | 7 | ||||
-rw-r--r-- | net/wireless/util.c | 132 | ||||
-rw-r--r-- | net/wireless/wext-compat.c | 5 |
12 files changed, 405 insertions, 67 deletions
diff --git a/net/wireless/.gitignore b/net/wireless/.gitignore new file mode 100644 index 000000000000..c33451b896d9 --- /dev/null +++ b/net/wireless/.gitignore | |||
@@ -0,0 +1 @@ | |||
regdb.c | |||
diff --git a/net/wireless/Kconfig b/net/wireless/Kconfig index 90e93a5701aa..8419971f07c5 100644 --- a/net/wireless/Kconfig +++ b/net/wireless/Kconfig | |||
@@ -109,6 +109,22 @@ config WIRELESS_OLD_REGULATORY | |||
109 | 109 | ||
110 | Say N and if you say Y, please tell us why. The default is N. | 110 | Say N and if you say Y, please tell us why. The default is N. |
111 | 111 | ||
112 | config CFG80211_INTERNAL_REGDB | ||
113 | bool "use statically compiled regulatory rules database" if EMBEDDED | ||
114 | default n | ||
115 | depends on CFG80211 | ||
116 | ---help--- | ||
117 | This option generates an internal data structure representing | ||
118 | the wireless regulatory rules described in net/wireless/db.txt | ||
119 | and includes code to query that database. This is an alternative | ||
120 | to using CRDA for defining regulatory rules for the kernel. | ||
121 | |||
122 | For details see: | ||
123 | |||
124 | http://wireless.kernel.org/en/developers/Regulatory | ||
125 | |||
126 | Most distributions have a CRDA package. So if unsure, say N. | ||
127 | |||
112 | config CFG80211_WEXT | 128 | config CFG80211_WEXT |
113 | bool "cfg80211 wireless extensions compatibility" | 129 | bool "cfg80211 wireless extensions compatibility" |
114 | depends on CFG80211 | 130 | depends on CFG80211 |
diff --git a/net/wireless/Makefile b/net/wireless/Makefile index f07c8dc7aab2..e77e508126fa 100644 --- a/net/wireless/Makefile +++ b/net/wireless/Makefile | |||
@@ -13,5 +13,11 @@ cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o | |||
13 | cfg80211-y += mlme.o ibss.o sme.o chan.o ethtool.o | 13 | cfg80211-y += mlme.o ibss.o sme.o chan.o ethtool.o |
14 | cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o | 14 | cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o |
15 | cfg80211-$(CONFIG_CFG80211_WEXT) += wext-compat.o wext-sme.o | 15 | cfg80211-$(CONFIG_CFG80211_WEXT) += wext-compat.o wext-sme.o |
16 | cfg80211-$(CONFIG_CFG80211_INTERNAL_REGDB) += regdb.o | ||
16 | 17 | ||
17 | ccflags-y += -D__CHECK_ENDIAN__ | 18 | ccflags-y += -D__CHECK_ENDIAN__ |
19 | |||
20 | $(obj)/regdb.c: $(src)/db.txt $(src)/genregdb.awk | ||
21 | @$(AWK) -f $(srctree)/$(src)/genregdb.awk < $< > $@ | ||
22 | |||
23 | clean-files := regdb.c | ||
diff --git a/net/wireless/core.h b/net/wireless/core.h index 4ef3efc94106..35b712127143 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h | |||
@@ -378,6 +378,8 @@ int rdev_set_freq(struct cfg80211_registered_device *rdev, | |||
378 | struct wireless_dev *for_wdev, | 378 | struct wireless_dev *for_wdev, |
379 | int freq, enum nl80211_channel_type channel_type); | 379 | int freq, enum nl80211_channel_type channel_type); |
380 | 380 | ||
381 | u16 cfg80211_calculate_bitrate(struct rate_info *rate); | ||
382 | |||
381 | #ifdef CONFIG_CFG80211_DEVELOPER_WARNINGS | 383 | #ifdef CONFIG_CFG80211_DEVELOPER_WARNINGS |
382 | #define CFG80211_DEV_WARN_ON(cond) WARN_ON(cond) | 384 | #define CFG80211_DEV_WARN_ON(cond) WARN_ON(cond) |
383 | #else | 385 | #else |
diff --git a/net/wireless/db.txt b/net/wireless/db.txt new file mode 100644 index 000000000000..a2fc3a09ccdc --- /dev/null +++ b/net/wireless/db.txt | |||
@@ -0,0 +1,17 @@ | |||
1 | # | ||
2 | # This file is a placeholder to prevent accidental build breakage if someone | ||
3 | # enables CONFIG_CFG80211_INTERNAL_REGDB. Almost no one actually needs to | ||
4 | # enable that build option. | ||
5 | # | ||
6 | # You should be using CRDA instead. It is even better if you use the CRDA | ||
7 | # package provided by your distribution, since they will probably keep it | ||
8 | # up-to-date on your behalf. | ||
9 | # | ||
10 | # If you _really_ intend to use CONFIG_CFG80211_INTERNAL_REGDB then you will | ||
11 | # need to replace this file with one containing appropriately formatted | ||
12 | # regulatory rules that cover the regulatory domains you will be using. Your | ||
13 | # best option is to extract the db.txt file from the wireless-regdb git | ||
14 | # repository: | ||
15 | # | ||
16 | # git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-regdb.git | ||
17 | # | ||
diff --git a/net/wireless/genregdb.awk b/net/wireless/genregdb.awk new file mode 100644 index 000000000000..8316cf075ce9 --- /dev/null +++ b/net/wireless/genregdb.awk | |||
@@ -0,0 +1,118 @@ | |||
1 | #!/usr/bin/awk -f | ||
2 | # | ||
3 | # genregdb.awk -- generate regdb.c from db.txt | ||
4 | # | ||
5 | # Actually, it reads from stdin (presumed to be db.txt) and writes | ||
6 | # to stdout (presumed to be regdb.c), but close enough... | ||
7 | # | ||
8 | # Copyright 2009 John W. Linville <linville@tuxdriver.com> | ||
9 | # | ||
10 | # This program is free software; you can redistribute it and/or modify | ||
11 | # it under the terms of the GNU General Public License version 2 as | ||
12 | # published by the Free Software Foundation. | ||
13 | # | ||
14 | |||
15 | BEGIN { | ||
16 | active = 0 | ||
17 | rules = 0; | ||
18 | print "/*" | ||
19 | print " * DO NOT EDIT -- file generated from data in db.txt" | ||
20 | print " */" | ||
21 | print "" | ||
22 | print "#include <linux/nl80211.h>" | ||
23 | print "#include <net/cfg80211.h>" | ||
24 | print "" | ||
25 | regdb = "const struct ieee80211_regdomain *reg_regdb[] = {\n" | ||
26 | } | ||
27 | |||
28 | /^[ \t]*#/ { | ||
29 | /* Ignore */ | ||
30 | } | ||
31 | |||
32 | !active && /^[ \t]*$/ { | ||
33 | /* Ignore */ | ||
34 | } | ||
35 | |||
36 | !active && /country/ { | ||
37 | country=$2 | ||
38 | sub(/:/, "", country) | ||
39 | printf "static const struct ieee80211_regdomain regdom_%s = {\n", country | ||
40 | printf "\t.alpha2 = \"%s\",\n", country | ||
41 | printf "\t.reg_rules = {\n" | ||
42 | active = 1 | ||
43 | regdb = regdb "\t®dom_" country ",\n" | ||
44 | } | ||
45 | |||
46 | active && /^[ \t]*\(/ { | ||
47 | start = $1 | ||
48 | sub(/\(/, "", start) | ||
49 | end = $3 | ||
50 | bw = $5 | ||
51 | sub(/\),/, "", bw) | ||
52 | gain = $6 | ||
53 | sub(/\(/, "", gain) | ||
54 | sub(/,/, "", gain) | ||
55 | power = $7 | ||
56 | sub(/\)/, "", power) | ||
57 | sub(/,/, "", power) | ||
58 | # power might be in mW... | ||
59 | units = $8 | ||
60 | sub(/\)/, "", units) | ||
61 | sub(/,/, "", units) | ||
62 | if (units == "mW") { | ||
63 | if (power == 100) { | ||
64 | power = 20 | ||
65 | } else if (power == 200) { | ||
66 | power = 23 | ||
67 | } else if (power == 500) { | ||
68 | power = 27 | ||
69 | } else if (power == 1000) { | ||
70 | power = 30 | ||
71 | } else { | ||
72 | print "Unknown power value in database!" | ||
73 | } | ||
74 | } | ||
75 | flagstr = "" | ||
76 | for (i=8; i<=NF; i++) | ||
77 | flagstr = flagstr $i | ||
78 | split(flagstr, flagarray, ",") | ||
79 | flags = "" | ||
80 | for (arg in flagarray) { | ||
81 | if (flagarray[arg] == "NO-OFDM") { | ||
82 | flags = flags "\n\t\t\tNL80211_RRF_NO_OFDM | " | ||
83 | } else if (flagarray[arg] == "NO-CCK") { | ||
84 | flags = flags "\n\t\t\tNL80211_RRF_NO_CCK | " | ||
85 | } else if (flagarray[arg] == "NO-INDOOR") { | ||
86 | flags = flags "\n\t\t\tNL80211_RRF_NO_INDOOR | " | ||
87 | } else if (flagarray[arg] == "NO-OUTDOOR") { | ||
88 | flags = flags "\n\t\t\tNL80211_RRF_NO_OUTDOOR | " | ||
89 | } else if (flagarray[arg] == "DFS") { | ||
90 | flags = flags "\n\t\t\tNL80211_RRF_DFS | " | ||
91 | } else if (flagarray[arg] == "PTP-ONLY") { | ||
92 | flags = flags "\n\t\t\tNL80211_RRF_PTP_ONLY | " | ||
93 | } else if (flagarray[arg] == "PTMP-ONLY") { | ||
94 | flags = flags "\n\t\t\tNL80211_RRF_PTMP_ONLY | " | ||
95 | } else if (flagarray[arg] == "PASSIVE-SCAN") { | ||
96 | flags = flags "\n\t\t\tNL80211_RRF_PASSIVE_SCAN | " | ||
97 | } else if (flagarray[arg] == "NO-IBSS") { | ||
98 | flags = flags "\n\t\t\tNL80211_RRF_NO_IBSS | " | ||
99 | } | ||
100 | } | ||
101 | flags = flags "0" | ||
102 | printf "\t\tREG_RULE(%d, %d, %d, %d, %d, %s),\n", start, end, bw, gain, power, flags | ||
103 | rules++ | ||
104 | } | ||
105 | |||
106 | active && /^[ \t]*$/ { | ||
107 | active = 0 | ||
108 | printf "\t},\n" | ||
109 | printf "\t.n_reg_rules = %d\n", rules | ||
110 | printf "};\n\n" | ||
111 | rules = 0; | ||
112 | } | ||
113 | |||
114 | END { | ||
115 | print regdb "};" | ||
116 | print "" | ||
117 | print "int reg_regdb_size = ARRAY_SIZE(reg_regdb);" | ||
118 | } | ||
diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c index 1001db4912f7..acaeaa784d68 100644 --- a/net/wireless/mlme.c +++ b/net/wireless/mlme.c | |||
@@ -137,22 +137,23 @@ void __cfg80211_send_deauth(struct net_device *dev, | |||
137 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; | 137 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
138 | const u8 *bssid = mgmt->bssid; | 138 | const u8 *bssid = mgmt->bssid; |
139 | int i; | 139 | int i; |
140 | bool found = false; | ||
140 | 141 | ||
141 | ASSERT_WDEV_LOCK(wdev); | 142 | ASSERT_WDEV_LOCK(wdev); |
142 | 143 | ||
143 | nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL); | ||
144 | |||
145 | if (wdev->current_bss && | 144 | if (wdev->current_bss && |
146 | memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) { | 145 | memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) { |
147 | cfg80211_unhold_bss(wdev->current_bss); | 146 | cfg80211_unhold_bss(wdev->current_bss); |
148 | cfg80211_put_bss(&wdev->current_bss->pub); | 147 | cfg80211_put_bss(&wdev->current_bss->pub); |
149 | wdev->current_bss = NULL; | 148 | wdev->current_bss = NULL; |
149 | found = true; | ||
150 | } else for (i = 0; i < MAX_AUTH_BSSES; i++) { | 150 | } else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
151 | if (wdev->auth_bsses[i] && | 151 | if (wdev->auth_bsses[i] && |
152 | memcmp(wdev->auth_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) { | 152 | memcmp(wdev->auth_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) { |
153 | cfg80211_unhold_bss(wdev->auth_bsses[i]); | 153 | cfg80211_unhold_bss(wdev->auth_bsses[i]); |
154 | cfg80211_put_bss(&wdev->auth_bsses[i]->pub); | 154 | cfg80211_put_bss(&wdev->auth_bsses[i]->pub); |
155 | wdev->auth_bsses[i] = NULL; | 155 | wdev->auth_bsses[i] = NULL; |
156 | found = true; | ||
156 | break; | 157 | break; |
157 | } | 158 | } |
158 | if (wdev->authtry_bsses[i] && | 159 | if (wdev->authtry_bsses[i] && |
@@ -160,10 +161,16 @@ void __cfg80211_send_deauth(struct net_device *dev, | |||
160 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); | 161 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); |
161 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); | 162 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); |
162 | wdev->authtry_bsses[i] = NULL; | 163 | wdev->authtry_bsses[i] = NULL; |
164 | found = true; | ||
163 | break; | 165 | break; |
164 | } | 166 | } |
165 | } | 167 | } |
166 | 168 | ||
169 | if (!found) | ||
170 | return; | ||
171 | |||
172 | nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL); | ||
173 | |||
167 | if (wdev->sme_state == CFG80211_SME_CONNECTED) { | 174 | if (wdev->sme_state == CFG80211_SME_CONNECTED) { |
168 | u16 reason_code; | 175 | u16 reason_code; |
169 | bool from_ap; | 176 | bool from_ap; |
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index a6028433e3a0..7cb0d647fc34 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c | |||
@@ -1637,39 +1637,6 @@ static int parse_station_flags(struct genl_info *info, | |||
1637 | return 0; | 1637 | return 0; |
1638 | } | 1638 | } |
1639 | 1639 | ||
1640 | static u16 nl80211_calculate_bitrate(struct rate_info *rate) | ||
1641 | { | ||
1642 | int modulation, streams, bitrate; | ||
1643 | |||
1644 | if (!(rate->flags & RATE_INFO_FLAGS_MCS)) | ||
1645 | return rate->legacy; | ||
1646 | |||
1647 | /* the formula below does only work for MCS values smaller than 32 */ | ||
1648 | if (rate->mcs >= 32) | ||
1649 | return 0; | ||
1650 | |||
1651 | modulation = rate->mcs & 7; | ||
1652 | streams = (rate->mcs >> 3) + 1; | ||
1653 | |||
1654 | bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ? | ||
1655 | 13500000 : 6500000; | ||
1656 | |||
1657 | if (modulation < 4) | ||
1658 | bitrate *= (modulation + 1); | ||
1659 | else if (modulation == 4) | ||
1660 | bitrate *= (modulation + 2); | ||
1661 | else | ||
1662 | bitrate *= (modulation + 3); | ||
1663 | |||
1664 | bitrate *= streams; | ||
1665 | |||
1666 | if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) | ||
1667 | bitrate = (bitrate / 9) * 10; | ||
1668 | |||
1669 | /* do NOT round down here */ | ||
1670 | return (bitrate + 50000) / 100000; | ||
1671 | } | ||
1672 | |||
1673 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, | 1640 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
1674 | int flags, struct net_device *dev, | 1641 | int flags, struct net_device *dev, |
1675 | u8 *mac_addr, struct station_info *sinfo) | 1642 | u8 *mac_addr, struct station_info *sinfo) |
@@ -1716,8 +1683,8 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, | |||
1716 | if (!txrate) | 1683 | if (!txrate) |
1717 | goto nla_put_failure; | 1684 | goto nla_put_failure; |
1718 | 1685 | ||
1719 | /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */ | 1686 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
1720 | bitrate = nl80211_calculate_bitrate(&sinfo->txrate); | 1687 | bitrate = cfg80211_calculate_bitrate(&sinfo->txrate); |
1721 | if (bitrate > 0) | 1688 | if (bitrate > 0) |
1722 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); | 1689 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
1723 | 1690 | ||
diff --git a/net/wireless/reg.c b/net/wireless/reg.c index baa898add287..dc13c3ffeca6 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <net/cfg80211.h> | 40 | #include <net/cfg80211.h> |
41 | #include "core.h" | 41 | #include "core.h" |
42 | #include "reg.h" | 42 | #include "reg.h" |
43 | #include "regdb.h" | ||
43 | #include "nl80211.h" | 44 | #include "nl80211.h" |
44 | 45 | ||
45 | /* Receipt of information from last regulatory request */ | 46 | /* Receipt of information from last regulatory request */ |
@@ -335,6 +336,98 @@ static bool country_ie_integrity_changes(u32 checksum) | |||
335 | return false; | 336 | return false; |
336 | } | 337 | } |
337 | 338 | ||
339 | static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd, | ||
340 | const struct ieee80211_regdomain *src_regd) | ||
341 | { | ||
342 | struct ieee80211_regdomain *regd; | ||
343 | int size_of_regd = 0; | ||
344 | unsigned int i; | ||
345 | |||
346 | size_of_regd = sizeof(struct ieee80211_regdomain) + | ||
347 | ((src_regd->n_reg_rules + 1) * sizeof(struct ieee80211_reg_rule)); | ||
348 | |||
349 | regd = kzalloc(size_of_regd, GFP_KERNEL); | ||
350 | if (!regd) | ||
351 | return -ENOMEM; | ||
352 | |||
353 | memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain)); | ||
354 | |||
355 | for (i = 0; i < src_regd->n_reg_rules; i++) | ||
356 | memcpy(®d->reg_rules[i], &src_regd->reg_rules[i], | ||
357 | sizeof(struct ieee80211_reg_rule)); | ||
358 | |||
359 | *dst_regd = regd; | ||
360 | return 0; | ||
361 | } | ||
362 | |||
363 | #ifdef CONFIG_CFG80211_INTERNAL_REGDB | ||
364 | struct reg_regdb_search_request { | ||
365 | char alpha2[2]; | ||
366 | struct list_head list; | ||
367 | }; | ||
368 | |||
369 | static LIST_HEAD(reg_regdb_search_list); | ||
370 | static DEFINE_SPINLOCK(reg_regdb_search_lock); | ||
371 | |||
372 | static void reg_regdb_search(struct work_struct *work) | ||
373 | { | ||
374 | struct reg_regdb_search_request *request; | ||
375 | const struct ieee80211_regdomain *curdom, *regdom; | ||
376 | int i, r; | ||
377 | |||
378 | spin_lock(®_regdb_search_lock); | ||
379 | while (!list_empty(®_regdb_search_list)) { | ||
380 | request = list_first_entry(®_regdb_search_list, | ||
381 | struct reg_regdb_search_request, | ||
382 | list); | ||
383 | list_del(&request->list); | ||
384 | |||
385 | for (i=0; i<reg_regdb_size; i++) { | ||
386 | curdom = reg_regdb[i]; | ||
387 | |||
388 | if (!memcmp(request->alpha2, curdom->alpha2, 2)) { | ||
389 | r = reg_copy_regd(®dom, curdom); | ||
390 | if (r) | ||
391 | break; | ||
392 | spin_unlock(®_regdb_search_lock); | ||
393 | mutex_lock(&cfg80211_mutex); | ||
394 | set_regdom(regdom); | ||
395 | mutex_unlock(&cfg80211_mutex); | ||
396 | spin_lock(®_regdb_search_lock); | ||
397 | break; | ||
398 | } | ||
399 | } | ||
400 | |||
401 | kfree(request); | ||
402 | } | ||
403 | spin_unlock(®_regdb_search_lock); | ||
404 | } | ||
405 | |||
406 | static DECLARE_WORK(reg_regdb_work, reg_regdb_search); | ||
407 | |||
408 | static void reg_regdb_query(const char *alpha2) | ||
409 | { | ||
410 | struct reg_regdb_search_request *request; | ||
411 | |||
412 | if (!alpha2) | ||
413 | return; | ||
414 | |||
415 | request = kzalloc(sizeof(struct reg_regdb_search_request), GFP_KERNEL); | ||
416 | if (!request) | ||
417 | return; | ||
418 | |||
419 | memcpy(request->alpha2, alpha2, 2); | ||
420 | |||
421 | spin_lock(®_regdb_search_lock); | ||
422 | list_add_tail(&request->list, ®_regdb_search_list); | ||
423 | spin_unlock(®_regdb_search_lock); | ||
424 | |||
425 | schedule_work(®_regdb_work); | ||
426 | } | ||
427 | #else | ||
428 | static inline void reg_regdb_query(const char *alpha2) {} | ||
429 | #endif /* CONFIG_CFG80211_INTERNAL_REGDB */ | ||
430 | |||
338 | /* | 431 | /* |
339 | * This lets us keep regulatory code which is updated on a regulatory | 432 | * This lets us keep regulatory code which is updated on a regulatory |
340 | * basis in userspace. | 433 | * basis in userspace. |
@@ -354,6 +447,9 @@ static int call_crda(const char *alpha2) | |||
354 | printk(KERN_INFO "cfg80211: Calling CRDA to update world " | 447 | printk(KERN_INFO "cfg80211: Calling CRDA to update world " |
355 | "regulatory domain\n"); | 448 | "regulatory domain\n"); |
356 | 449 | ||
450 | /* query internal regulatory database (if it exists) */ | ||
451 | reg_regdb_query(alpha2); | ||
452 | |||
357 | country_env[8] = alpha2[0]; | 453 | country_env[8] = alpha2[0]; |
358 | country_env[9] = alpha2[1]; | 454 | country_env[9] = alpha2[1]; |
359 | 455 | ||
@@ -1342,30 +1438,6 @@ void wiphy_apply_custom_regulatory(struct wiphy *wiphy, | |||
1342 | } | 1438 | } |
1343 | EXPORT_SYMBOL(wiphy_apply_custom_regulatory); | 1439 | EXPORT_SYMBOL(wiphy_apply_custom_regulatory); |
1344 | 1440 | ||
1345 | static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd, | ||
1346 | const struct ieee80211_regdomain *src_regd) | ||
1347 | { | ||
1348 | struct ieee80211_regdomain *regd; | ||
1349 | int size_of_regd = 0; | ||
1350 | unsigned int i; | ||
1351 | |||
1352 | size_of_regd = sizeof(struct ieee80211_regdomain) + | ||
1353 | ((src_regd->n_reg_rules + 1) * sizeof(struct ieee80211_reg_rule)); | ||
1354 | |||
1355 | regd = kzalloc(size_of_regd, GFP_KERNEL); | ||
1356 | if (!regd) | ||
1357 | return -ENOMEM; | ||
1358 | |||
1359 | memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain)); | ||
1360 | |||
1361 | for (i = 0; i < src_regd->n_reg_rules; i++) | ||
1362 | memcpy(®d->reg_rules[i], &src_regd->reg_rules[i], | ||
1363 | sizeof(struct ieee80211_reg_rule)); | ||
1364 | |||
1365 | *dst_regd = regd; | ||
1366 | return 0; | ||
1367 | } | ||
1368 | |||
1369 | /* | 1441 | /* |
1370 | * Return value which can be used by ignore_request() to indicate | 1442 | * Return value which can be used by ignore_request() to indicate |
1371 | * it has been determined we should intersect two regulatory domains | 1443 | * it has been determined we should intersect two regulatory domains |
diff --git a/net/wireless/regdb.h b/net/wireless/regdb.h new file mode 100644 index 000000000000..818222c92513 --- /dev/null +++ b/net/wireless/regdb.h | |||
@@ -0,0 +1,7 @@ | |||
1 | #ifndef __REGDB_H__ | ||
2 | #define __REGDB_H__ | ||
3 | |||
4 | extern const struct ieee80211_regdomain *reg_regdb[]; | ||
5 | extern int reg_regdb_size; | ||
6 | |||
7 | #endif /* __REGDB_H__ */ | ||
diff --git a/net/wireless/util.c b/net/wireless/util.c index 59361fdcb5d0..23557c1d0a9c 100644 --- a/net/wireless/util.c +++ b/net/wireless/util.c | |||
@@ -285,7 +285,7 @@ static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr) | |||
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
288 | int ieee80211_data_to_8023(struct sk_buff *skb, u8 *addr, | 288 | int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr, |
289 | enum nl80211_iftype iftype) | 289 | enum nl80211_iftype iftype) |
290 | { | 290 | { |
291 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | 291 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
@@ -383,7 +383,7 @@ int ieee80211_data_to_8023(struct sk_buff *skb, u8 *addr, | |||
383 | } | 383 | } |
384 | EXPORT_SYMBOL(ieee80211_data_to_8023); | 384 | EXPORT_SYMBOL(ieee80211_data_to_8023); |
385 | 385 | ||
386 | int ieee80211_data_from_8023(struct sk_buff *skb, u8 *addr, | 386 | int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr, |
387 | enum nl80211_iftype iftype, u8 *bssid, bool qos) | 387 | enum nl80211_iftype iftype, u8 *bssid, bool qos) |
388 | { | 388 | { |
389 | struct ieee80211_hdr hdr; | 389 | struct ieee80211_hdr hdr; |
@@ -497,6 +497,101 @@ int ieee80211_data_from_8023(struct sk_buff *skb, u8 *addr, | |||
497 | } | 497 | } |
498 | EXPORT_SYMBOL(ieee80211_data_from_8023); | 498 | EXPORT_SYMBOL(ieee80211_data_from_8023); |
499 | 499 | ||
500 | |||
501 | void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list, | ||
502 | const u8 *addr, enum nl80211_iftype iftype, | ||
503 | const unsigned int extra_headroom) | ||
504 | { | ||
505 | struct sk_buff *frame = NULL; | ||
506 | u16 ethertype; | ||
507 | u8 *payload; | ||
508 | const struct ethhdr *eth; | ||
509 | int remaining, err; | ||
510 | u8 dst[ETH_ALEN], src[ETH_ALEN]; | ||
511 | |||
512 | err = ieee80211_data_to_8023(skb, addr, iftype); | ||
513 | if (err) | ||
514 | goto out; | ||
515 | |||
516 | /* skip the wrapping header */ | ||
517 | eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr)); | ||
518 | if (!eth) | ||
519 | goto out; | ||
520 | |||
521 | while (skb != frame) { | ||
522 | u8 padding; | ||
523 | __be16 len = eth->h_proto; | ||
524 | unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len); | ||
525 | |||
526 | remaining = skb->len; | ||
527 | memcpy(dst, eth->h_dest, ETH_ALEN); | ||
528 | memcpy(src, eth->h_source, ETH_ALEN); | ||
529 | |||
530 | padding = (4 - subframe_len) & 0x3; | ||
531 | /* the last MSDU has no padding */ | ||
532 | if (subframe_len > remaining) | ||
533 | goto purge; | ||
534 | |||
535 | skb_pull(skb, sizeof(struct ethhdr)); | ||
536 | /* reuse skb for the last subframe */ | ||
537 | if (remaining <= subframe_len + padding) | ||
538 | frame = skb; | ||
539 | else { | ||
540 | unsigned int hlen = ALIGN(extra_headroom, 4); | ||
541 | /* | ||
542 | * Allocate and reserve two bytes more for payload | ||
543 | * alignment since sizeof(struct ethhdr) is 14. | ||
544 | */ | ||
545 | frame = dev_alloc_skb(hlen + subframe_len + 2); | ||
546 | if (!frame) | ||
547 | goto purge; | ||
548 | |||
549 | skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2); | ||
550 | memcpy(skb_put(frame, ntohs(len)), skb->data, | ||
551 | ntohs(len)); | ||
552 | |||
553 | eth = (struct ethhdr *)skb_pull(skb, ntohs(len) + | ||
554 | padding); | ||
555 | if (!eth) { | ||
556 | dev_kfree_skb(frame); | ||
557 | goto purge; | ||
558 | } | ||
559 | } | ||
560 | |||
561 | skb_reset_network_header(frame); | ||
562 | frame->dev = skb->dev; | ||
563 | frame->priority = skb->priority; | ||
564 | |||
565 | payload = frame->data; | ||
566 | ethertype = (payload[6] << 8) | payload[7]; | ||
567 | |||
568 | if (likely((compare_ether_addr(payload, rfc1042_header) == 0 && | ||
569 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || | ||
570 | compare_ether_addr(payload, | ||
571 | bridge_tunnel_header) == 0)) { | ||
572 | /* remove RFC1042 or Bridge-Tunnel | ||
573 | * encapsulation and replace EtherType */ | ||
574 | skb_pull(frame, 6); | ||
575 | memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN); | ||
576 | memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN); | ||
577 | } else { | ||
578 | memcpy(skb_push(frame, sizeof(__be16)), &len, | ||
579 | sizeof(__be16)); | ||
580 | memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN); | ||
581 | memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN); | ||
582 | } | ||
583 | __skb_queue_tail(list, frame); | ||
584 | } | ||
585 | |||
586 | return; | ||
587 | |||
588 | purge: | ||
589 | __skb_queue_purge(list); | ||
590 | out: | ||
591 | dev_kfree_skb(skb); | ||
592 | } | ||
593 | EXPORT_SYMBOL(ieee80211_amsdu_to_8023s); | ||
594 | |||
500 | /* Given a data frame determine the 802.1p/1d tag to use. */ | 595 | /* Given a data frame determine the 802.1p/1d tag to use. */ |
501 | unsigned int cfg80211_classify8021d(struct sk_buff *skb) | 596 | unsigned int cfg80211_classify8021d(struct sk_buff *skb) |
502 | { | 597 | { |
@@ -720,3 +815,36 @@ int cfg80211_change_iface(struct cfg80211_registered_device *rdev, | |||
720 | 815 | ||
721 | return err; | 816 | return err; |
722 | } | 817 | } |
818 | |||
819 | u16 cfg80211_calculate_bitrate(struct rate_info *rate) | ||
820 | { | ||
821 | int modulation, streams, bitrate; | ||
822 | |||
823 | if (!(rate->flags & RATE_INFO_FLAGS_MCS)) | ||
824 | return rate->legacy; | ||
825 | |||
826 | /* the formula below does only work for MCS values smaller than 32 */ | ||
827 | if (rate->mcs >= 32) | ||
828 | return 0; | ||
829 | |||
830 | modulation = rate->mcs & 7; | ||
831 | streams = (rate->mcs >> 3) + 1; | ||
832 | |||
833 | bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ? | ||
834 | 13500000 : 6500000; | ||
835 | |||
836 | if (modulation < 4) | ||
837 | bitrate *= (modulation + 1); | ||
838 | else if (modulation == 4) | ||
839 | bitrate *= (modulation + 2); | ||
840 | else | ||
841 | bitrate *= (modulation + 3); | ||
842 | |||
843 | bitrate *= streams; | ||
844 | |||
845 | if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) | ||
846 | bitrate = (bitrate / 9) * 10; | ||
847 | |||
848 | /* do NOT round down here */ | ||
849 | return (bitrate + 50000) / 100000; | ||
850 | } | ||
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c index 54face3d4424..4198243a3dff 100644 --- a/net/wireless/wext-compat.c +++ b/net/wireless/wext-compat.c | |||
@@ -1257,10 +1257,7 @@ int cfg80211_wext_giwrate(struct net_device *dev, | |||
1257 | if (!(sinfo.filled & STATION_INFO_TX_BITRATE)) | 1257 | if (!(sinfo.filled & STATION_INFO_TX_BITRATE)) |
1258 | return -EOPNOTSUPP; | 1258 | return -EOPNOTSUPP; |
1259 | 1259 | ||
1260 | rate->value = 0; | 1260 | rate->value = 100000 * cfg80211_calculate_bitrate(&sinfo.txrate); |
1261 | |||
1262 | if (!(sinfo.txrate.flags & RATE_INFO_FLAGS_MCS)) | ||
1263 | rate->value = 100000 * sinfo.txrate.legacy; | ||
1264 | 1261 | ||
1265 | return 0; | 1262 | return 0; |
1266 | } | 1263 | } |