blob: 305a09de85a57d924a187abe72148c315b06868d [file] [log] [blame]
James Ketrenos02cda6a2005-09-21 11:56:38 -05001/******************************************************************************
2
3 Copyright(c) 2005 Intel Corporation. All rights reserved.
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of version 2 of the GNU General Public License as
7 published by the Free Software Foundation.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc., 59
16 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 The full GNU General Public License is included in this distribution in the
19 file called LICENSE.
20
21 Contact Information:
22 James P. Ketrenos <ipw2100-admin@linux.intel.com>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24
25******************************************************************************/
26#include <linux/compiler.h>
James Ketrenos02cda6a2005-09-21 11:56:38 -050027#include <linux/errno.h>
28#include <linux/if_arp.h>
29#include <linux/in6.h>
30#include <linux/in.h>
31#include <linux/ip.h>
32#include <linux/kernel.h>
33#include <linux/module.h>
34#include <linux/netdevice.h>
35#include <linux/proc_fs.h>
36#include <linux/skbuff.h>
37#include <linux/slab.h>
38#include <linux/tcp.h>
39#include <linux/types.h>
James Ketrenos02cda6a2005-09-21 11:56:38 -050040#include <linux/wireless.h>
41#include <linux/etherdevice.h>
42#include <asm/uaccess.h>
43
44#include <net/ieee80211.h>
45
46int ieee80211_is_valid_channel(struct ieee80211_device *ieee, u8 channel)
47{
48 int i;
49
50 /* Driver needs to initialize the geography map before using
51 * these helper functions */
Pete Zaitcev07981aa2006-02-26 16:29:51 -080052 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
53 return 0;
James Ketrenos02cda6a2005-09-21 11:56:38 -050054
55 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
56 for (i = 0; i < ieee->geo.bg_channels; i++)
57 /* NOTE: If G mode is currently supported but
58 * this is a B only channel, we don't see it
59 * as valid. */
60 if ((ieee->geo.bg[i].channel == channel) &&
Zhu Yid128f6c2006-01-19 16:21:45 +080061 !(ieee->geo.bg[i].flags & IEEE80211_CH_INVALID) &&
James Ketrenos02cda6a2005-09-21 11:56:38 -050062 (!(ieee->mode & IEEE_G) ||
63 !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY)))
64 return IEEE80211_24GHZ_BAND;
65
66 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
67 for (i = 0; i < ieee->geo.a_channels; i++)
Zhu Yid128f6c2006-01-19 16:21:45 +080068 if ((ieee->geo.a[i].channel == channel) &&
69 !(ieee->geo.a[i].flags & IEEE80211_CH_INVALID))
James Ketrenos02cda6a2005-09-21 11:56:38 -050070 return IEEE80211_52GHZ_BAND;
71
72 return 0;
73}
74
75int ieee80211_channel_to_index(struct ieee80211_device *ieee, u8 channel)
76{
77 int i;
78
79 /* Driver needs to initialize the geography map before using
80 * these helper functions */
Pete Zaitcev07981aa2006-02-26 16:29:51 -080081 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
82 return -1;
James Ketrenos02cda6a2005-09-21 11:56:38 -050083
84 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
85 for (i = 0; i < ieee->geo.bg_channels; i++)
86 if (ieee->geo.bg[i].channel == channel)
87 return i;
88
89 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
90 for (i = 0; i < ieee->geo.a_channels; i++)
91 if (ieee->geo.a[i].channel == channel)
92 return i;
93
94 return -1;
95}
96
97u8 ieee80211_freq_to_channel(struct ieee80211_device * ieee, u32 freq)
98{
99 int i;
100
101 /* Driver needs to initialize the geography map before using
102 * these helper functions */
Pete Zaitcev07981aa2006-02-26 16:29:51 -0800103 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
104 return 0;
James Ketrenos02cda6a2005-09-21 11:56:38 -0500105
106 freq /= 100000;
107
108 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
109 for (i = 0; i < ieee->geo.bg_channels; i++)
110 if (ieee->geo.bg[i].freq == freq)
111 return ieee->geo.bg[i].channel;
112
113 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
114 for (i = 0; i < ieee->geo.a_channels; i++)
115 if (ieee->geo.a[i].freq == freq)
116 return ieee->geo.a[i].channel;
117
118 return 0;
119}
120
121int ieee80211_set_geo(struct ieee80211_device *ieee,
122 const struct ieee80211_geo *geo)
123{
124 memcpy(ieee->geo.name, geo->name, 3);
125 ieee->geo.name[3] = '\0';
126 ieee->geo.bg_channels = geo->bg_channels;
127 ieee->geo.a_channels = geo->a_channels;
128 memcpy(ieee->geo.bg, geo->bg, geo->bg_channels *
129 sizeof(struct ieee80211_channel));
130 memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels *
131 sizeof(struct ieee80211_channel));
132 return 0;
133}
134
135const struct ieee80211_geo *ieee80211_get_geo(struct ieee80211_device *ieee)
136{
137 return &ieee->geo;
138}
139
Zhu Yid128f6c2006-01-19 16:21:45 +0800140u8 ieee80211_get_channel_flags(struct ieee80211_device * ieee, u8 channel)
141{
142 int index = ieee80211_channel_to_index(ieee, channel);
143
144 if (index == -1)
145 return IEEE80211_CH_INVALID;
146
147 if (channel <= IEEE80211_24GHZ_CHANNELS)
148 return ieee->geo.bg[index].flags;
149
150 return ieee->geo.a[index].flags;
151}
152
153static const struct ieee80211_channel bad_channel = {
154 .channel = 0,
155 .flags = IEEE80211_CH_INVALID,
156 .max_power = 0,
157};
158
159const struct ieee80211_channel *ieee80211_get_channel(struct ieee80211_device
160 *ieee, u8 channel)
161{
162 int index = ieee80211_channel_to_index(ieee, channel);
163
164 if (index == -1)
165 return &bad_channel;
166
167 if (channel <= IEEE80211_24GHZ_CHANNELS)
168 return &ieee->geo.bg[index];
169
170 return &ieee->geo.a[index];
171}
172
173EXPORT_SYMBOL(ieee80211_get_channel);
174EXPORT_SYMBOL(ieee80211_get_channel_flags);
James Ketrenos02cda6a2005-09-21 11:56:38 -0500175EXPORT_SYMBOL(ieee80211_is_valid_channel);
176EXPORT_SYMBOL(ieee80211_freq_to_channel);
177EXPORT_SYMBOL(ieee80211_channel_to_index);
178EXPORT_SYMBOL(ieee80211_set_geo);
179EXPORT_SYMBOL(ieee80211_get_geo);