blob: d04979ba2a5ba2dcfb365f7b69e56f0d9e7fa9eb [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
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040044#include "libipw.h"
James Ketrenos02cda6a2005-09-21 11:56:38 -050045
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040046int libipw_is_valid_channel(struct libipw_device *ieee, u8 channel)
James Ketrenos02cda6a2005-09-21 11:56:38 -050047{
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
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040055 if (ieee->freq_band & LIBIPW_24GHZ_BAND)
James Ketrenos02cda6a2005-09-21 11:56:38 -050056 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) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040061 !(ieee->geo.bg[i].flags & LIBIPW_CH_INVALID) &&
James Ketrenos02cda6a2005-09-21 11:56:38 -050062 (!(ieee->mode & IEEE_G) ||
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040063 !(ieee->geo.bg[i].flags & LIBIPW_CH_B_ONLY)))
64 return LIBIPW_24GHZ_BAND;
James Ketrenos02cda6a2005-09-21 11:56:38 -050065
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040066 if (ieee->freq_band & LIBIPW_52GHZ_BAND)
James Ketrenos02cda6a2005-09-21 11:56:38 -050067 for (i = 0; i < ieee->geo.a_channels; i++)
Zhu Yid128f6c2006-01-19 16:21:45 +080068 if ((ieee->geo.a[i].channel == channel) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040069 !(ieee->geo.a[i].flags & LIBIPW_CH_INVALID))
70 return LIBIPW_52GHZ_BAND;
James Ketrenos02cda6a2005-09-21 11:56:38 -050071
72 return 0;
73}
74
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040075int libipw_channel_to_index(struct libipw_device *ieee, u8 channel)
James Ketrenos02cda6a2005-09-21 11:56:38 -050076{
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
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040084 if (ieee->freq_band & LIBIPW_24GHZ_BAND)
James Ketrenos02cda6a2005-09-21 11:56:38 -050085 for (i = 0; i < ieee->geo.bg_channels; i++)
86 if (ieee->geo.bg[i].channel == channel)
87 return i;
88
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040089 if (ieee->freq_band & LIBIPW_52GHZ_BAND)
James Ketrenos02cda6a2005-09-21 11:56:38 -050090 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
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040097u32 libipw_channel_to_freq(struct libipw_device * ieee, u8 channel)
Larry Fingerf5cdf302007-04-21 17:56:29 -050098{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040099 const struct libipw_channel * ch;
Larry Fingerf5cdf302007-04-21 17:56:29 -0500100
101 /* Driver needs to initialize the geography map before using
102 * these helper functions */
103 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
104 return 0;
105
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400106 ch = libipw_get_channel(ieee, channel);
Larry Fingerf5cdf302007-04-21 17:56:29 -0500107 if (!ch->channel)
108 return 0;
109 return ch->freq;
110}
111
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400112u8 libipw_freq_to_channel(struct libipw_device * ieee, u32 freq)
James Ketrenos02cda6a2005-09-21 11:56:38 -0500113{
114 int i;
115
116 /* Driver needs to initialize the geography map before using
117 * these helper functions */
Pete Zaitcev07981aa2006-02-26 16:29:51 -0800118 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
119 return 0;
James Ketrenos02cda6a2005-09-21 11:56:38 -0500120
121 freq /= 100000;
122
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400123 if (ieee->freq_band & LIBIPW_24GHZ_BAND)
James Ketrenos02cda6a2005-09-21 11:56:38 -0500124 for (i = 0; i < ieee->geo.bg_channels; i++)
125 if (ieee->geo.bg[i].freq == freq)
126 return ieee->geo.bg[i].channel;
127
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400128 if (ieee->freq_band & LIBIPW_52GHZ_BAND)
James Ketrenos02cda6a2005-09-21 11:56:38 -0500129 for (i = 0; i < ieee->geo.a_channels; i++)
130 if (ieee->geo.a[i].freq == freq)
131 return ieee->geo.a[i].channel;
132
133 return 0;
134}
135
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400136int libipw_set_geo(struct libipw_device *ieee,
137 const struct libipw_geo *geo)
James Ketrenos02cda6a2005-09-21 11:56:38 -0500138{
139 memcpy(ieee->geo.name, geo->name, 3);
140 ieee->geo.name[3] = '\0';
141 ieee->geo.bg_channels = geo->bg_channels;
142 ieee->geo.a_channels = geo->a_channels;
143 memcpy(ieee->geo.bg, geo->bg, geo->bg_channels *
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400144 sizeof(struct libipw_channel));
James Ketrenos02cda6a2005-09-21 11:56:38 -0500145 memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels *
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400146 sizeof(struct libipw_channel));
James Ketrenos02cda6a2005-09-21 11:56:38 -0500147 return 0;
148}
149
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400150const struct libipw_geo *libipw_get_geo(struct libipw_device *ieee)
James Ketrenos02cda6a2005-09-21 11:56:38 -0500151{
152 return &ieee->geo;
153}
154
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400155u8 libipw_get_channel_flags(struct libipw_device * ieee, u8 channel)
Zhu Yid128f6c2006-01-19 16:21:45 +0800156{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400157 int index = libipw_channel_to_index(ieee, channel);
Zhu Yid128f6c2006-01-19 16:21:45 +0800158
159 if (index == -1)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400160 return LIBIPW_CH_INVALID;
Zhu Yid128f6c2006-01-19 16:21:45 +0800161
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400162 if (channel <= LIBIPW_24GHZ_CHANNELS)
Zhu Yid128f6c2006-01-19 16:21:45 +0800163 return ieee->geo.bg[index].flags;
164
165 return ieee->geo.a[index].flags;
166}
167
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400168static const struct libipw_channel bad_channel = {
Zhu Yid128f6c2006-01-19 16:21:45 +0800169 .channel = 0,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400170 .flags = LIBIPW_CH_INVALID,
Zhu Yid128f6c2006-01-19 16:21:45 +0800171 .max_power = 0,
172};
173
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400174const struct libipw_channel *libipw_get_channel(struct libipw_device
Zhu Yid128f6c2006-01-19 16:21:45 +0800175 *ieee, u8 channel)
176{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400177 int index = libipw_channel_to_index(ieee, channel);
Zhu Yid128f6c2006-01-19 16:21:45 +0800178
179 if (index == -1)
180 return &bad_channel;
181
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400182 if (channel <= LIBIPW_24GHZ_CHANNELS)
Zhu Yid128f6c2006-01-19 16:21:45 +0800183 return &ieee->geo.bg[index];
184
185 return &ieee->geo.a[index];
186}
187
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400188EXPORT_SYMBOL(libipw_get_channel);
189EXPORT_SYMBOL(libipw_get_channel_flags);
190EXPORT_SYMBOL(libipw_is_valid_channel);
191EXPORT_SYMBOL(libipw_freq_to_channel);
192EXPORT_SYMBOL(libipw_channel_to_freq);
193EXPORT_SYMBOL(libipw_channel_to_index);
194EXPORT_SYMBOL(libipw_set_geo);
195EXPORT_SYMBOL(libipw_get_geo);