[PATCH] w1: Userspace communication protocol over connector.
[linux-2.6/verdex.git] / net / ieee80211 / ieee80211_geo.c
blob192243ab35ed2fce2c9d377aca926657e58a70dc
1 /******************************************************************************
3 Copyright(c) 2005 Intel Corporation. All rights reserved.
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.
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.
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.
18 The full GNU General Public License is included in this distribution in the
19 file called LICENSE.
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
25 ******************************************************************************/
26 #include <linux/compiler.h>
27 #include <linux/config.h>
28 #include <linux/errno.h>
29 #include <linux/if_arp.h>
30 #include <linux/in6.h>
31 #include <linux/in.h>
32 #include <linux/ip.h>
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/netdevice.h>
36 #include <linux/proc_fs.h>
37 #include <linux/skbuff.h>
38 #include <linux/slab.h>
39 #include <linux/tcp.h>
40 #include <linux/types.h>
41 #include <linux/wireless.h>
42 #include <linux/etherdevice.h>
43 #include <asm/uaccess.h>
45 #include <net/ieee80211.h>
47 int ieee80211_is_valid_channel(struct ieee80211_device *ieee, u8 channel)
49 int i;
51 /* Driver needs to initialize the geography map before using
52 * these helper functions */
53 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
54 return 0;
56 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
57 for (i = 0; i < ieee->geo.bg_channels; i++)
58 /* NOTE: If G mode is currently supported but
59 * this is a B only channel, we don't see it
60 * as valid. */
61 if ((ieee->geo.bg[i].channel == channel) &&
62 !(ieee->geo.bg[i].flags & IEEE80211_CH_INVALID) &&
63 (!(ieee->mode & IEEE_G) ||
64 !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY)))
65 return IEEE80211_24GHZ_BAND;
67 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
68 for (i = 0; i < ieee->geo.a_channels; i++)
69 if ((ieee->geo.a[i].channel == channel) &&
70 !(ieee->geo.a[i].flags & IEEE80211_CH_INVALID))
71 return IEEE80211_52GHZ_BAND;
73 return 0;
76 int ieee80211_channel_to_index(struct ieee80211_device *ieee, u8 channel)
78 int i;
80 /* Driver needs to initialize the geography map before using
81 * these helper functions */
82 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
83 return -1;
85 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
86 for (i = 0; i < ieee->geo.bg_channels; i++)
87 if (ieee->geo.bg[i].channel == channel)
88 return i;
90 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
91 for (i = 0; i < ieee->geo.a_channels; i++)
92 if (ieee->geo.a[i].channel == channel)
93 return i;
95 return -1;
98 u8 ieee80211_freq_to_channel(struct ieee80211_device * ieee, u32 freq)
100 int i;
102 /* Driver needs to initialize the geography map before using
103 * these helper functions */
104 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
105 return 0;
107 freq /= 100000;
109 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
110 for (i = 0; i < ieee->geo.bg_channels; i++)
111 if (ieee->geo.bg[i].freq == freq)
112 return ieee->geo.bg[i].channel;
114 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
115 for (i = 0; i < ieee->geo.a_channels; i++)
116 if (ieee->geo.a[i].freq == freq)
117 return ieee->geo.a[i].channel;
119 return 0;
122 int ieee80211_set_geo(struct ieee80211_device *ieee,
123 const struct ieee80211_geo *geo)
125 memcpy(ieee->geo.name, geo->name, 3);
126 ieee->geo.name[3] = '\0';
127 ieee->geo.bg_channels = geo->bg_channels;
128 ieee->geo.a_channels = geo->a_channels;
129 memcpy(ieee->geo.bg, geo->bg, geo->bg_channels *
130 sizeof(struct ieee80211_channel));
131 memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels *
132 sizeof(struct ieee80211_channel));
133 return 0;
136 const struct ieee80211_geo *ieee80211_get_geo(struct ieee80211_device *ieee)
138 return &ieee->geo;
141 u8 ieee80211_get_channel_flags(struct ieee80211_device * ieee, u8 channel)
143 int index = ieee80211_channel_to_index(ieee, channel);
145 if (index == -1)
146 return IEEE80211_CH_INVALID;
148 if (channel <= IEEE80211_24GHZ_CHANNELS)
149 return ieee->geo.bg[index].flags;
151 return ieee->geo.a[index].flags;
154 static const struct ieee80211_channel bad_channel = {
155 .channel = 0,
156 .flags = IEEE80211_CH_INVALID,
157 .max_power = 0,
160 const struct ieee80211_channel *ieee80211_get_channel(struct ieee80211_device
161 *ieee, u8 channel)
163 int index = ieee80211_channel_to_index(ieee, channel);
165 if (index == -1)
166 return &bad_channel;
168 if (channel <= IEEE80211_24GHZ_CHANNELS)
169 return &ieee->geo.bg[index];
171 return &ieee->geo.a[index];
174 EXPORT_SYMBOL(ieee80211_get_channel);
175 EXPORT_SYMBOL(ieee80211_get_channel_flags);
176 EXPORT_SYMBOL(ieee80211_is_valid_channel);
177 EXPORT_SYMBOL(ieee80211_freq_to_channel);
178 EXPORT_SYMBOL(ieee80211_channel_to_index);
179 EXPORT_SYMBOL(ieee80211_set_geo);
180 EXPORT_SYMBOL(ieee80211_get_geo);