diff options
Diffstat (limited to 'net/wireless/util.c')
-rw-r--r-- | net/wireless/util.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/net/wireless/util.c b/net/wireless/util.c new file mode 100644 index 000000000000..0dcccbf3eb57 --- /dev/null +++ b/net/wireless/util.c | |||
@@ -0,0 +1,98 @@ | |||
1 | /* | ||
2 | * Wireless utility functions | ||
3 | * | ||
4 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> | ||
5 | */ | ||
6 | #include <net/wireless.h> | ||
7 | #include <asm/bitops.h> | ||
8 | #include "core.h" | ||
9 | |||
10 | int ieee80211_channel_to_frequency(int chan) | ||
11 | { | ||
12 | if (chan < 14) | ||
13 | return 2407 + chan * 5; | ||
14 | |||
15 | if (chan == 14) | ||
16 | return 2484; | ||
17 | |||
18 | /* FIXME: 802.11j 17.3.8.3.2 */ | ||
19 | return (chan + 1000) * 5; | ||
20 | } | ||
21 | EXPORT_SYMBOL(ieee80211_channel_to_frequency); | ||
22 | |||
23 | int ieee80211_frequency_to_channel(int freq) | ||
24 | { | ||
25 | if (freq == 2484) | ||
26 | return 14; | ||
27 | |||
28 | if (freq < 2484) | ||
29 | return (freq - 2407) / 5; | ||
30 | |||
31 | /* FIXME: 802.11j 17.3.8.3.2 */ | ||
32 | return freq/5 - 1000; | ||
33 | } | ||
34 | EXPORT_SYMBOL(ieee80211_frequency_to_channel); | ||
35 | |||
36 | static void set_mandatory_flags_band(struct ieee80211_supported_band *sband, | ||
37 | enum ieee80211_band band) | ||
38 | { | ||
39 | int i, want; | ||
40 | |||
41 | switch (band) { | ||
42 | case IEEE80211_BAND_5GHZ: | ||
43 | want = 3; | ||
44 | for (i = 0; i < sband->n_bitrates; i++) { | ||
45 | if (sband->bitrates[i].bitrate == 60 || | ||
46 | sband->bitrates[i].bitrate == 120 || | ||
47 | sband->bitrates[i].bitrate == 240) { | ||
48 | sband->bitrates[i].flags |= | ||
49 | IEEE80211_RATE_MANDATORY_A; | ||
50 | want--; | ||
51 | } | ||
52 | } | ||
53 | WARN_ON(want); | ||
54 | break; | ||
55 | case IEEE80211_BAND_2GHZ: | ||
56 | want = 7; | ||
57 | for (i = 0; i < sband->n_bitrates; i++) { | ||
58 | if (sband->bitrates[i].bitrate == 10) { | ||
59 | sband->bitrates[i].flags |= | ||
60 | IEEE80211_RATE_MANDATORY_B | | ||
61 | IEEE80211_RATE_MANDATORY_G; | ||
62 | want--; | ||
63 | } | ||
64 | |||
65 | if (sband->bitrates[i].bitrate == 20 || | ||
66 | sband->bitrates[i].bitrate == 55 || | ||
67 | sband->bitrates[i].bitrate == 110 || | ||
68 | sband->bitrates[i].bitrate == 60 || | ||
69 | sband->bitrates[i].bitrate == 120 || | ||
70 | sband->bitrates[i].bitrate == 240) { | ||
71 | sband->bitrates[i].flags |= | ||
72 | IEEE80211_RATE_MANDATORY_G; | ||
73 | want--; | ||
74 | } | ||
75 | |||
76 | if (sband->bitrates[i].bitrate == 10 || | ||
77 | sband->bitrates[i].bitrate == 20 || | ||
78 | sband->bitrates[i].bitrate == 55 || | ||
79 | sband->bitrates[i].bitrate == 110) | ||
80 | sband->bitrates[i].flags |= | ||
81 | IEEE80211_RATE_ERP_G; | ||
82 | } | ||
83 | WARN_ON(want != 0 && want != 6); | ||
84 | break; | ||
85 | case IEEE80211_NUM_BANDS: | ||
86 | WARN_ON(1); | ||
87 | break; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | void ieee80211_set_bitrate_flags(struct wiphy *wiphy) | ||
92 | { | ||
93 | enum ieee80211_band band; | ||
94 | |||
95 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | ||
96 | if (wiphy->bands[band]) | ||
97 | set_mandatory_flags_band(wiphy->bands[band], band); | ||
98 | } | ||