2005-09-22 00:56:38 +08:00
|
|
|
/******************************************************************************
|
|
|
|
|
|
|
|
Copyright(c) 2005 Intel Corporation. All rights reserved.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of version 2 of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc., 59
|
|
|
|
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
The full GNU General Public License is included in this distribution in the
|
|
|
|
file called LICENSE.
|
|
|
|
|
|
|
|
Contact Information:
|
2009-08-22 04:34:26 +08:00
|
|
|
Intel Linux Wireless <ilw@linux.intel.com>
|
2005-09-22 00:56:38 +08:00
|
|
|
Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/in6.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/tcp.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/wireless.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
#include "libipw.h"
|
2005-09-22 00:56:38 +08:00
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
int libipw_is_valid_channel(struct libipw_device *ieee, u8 channel)
|
2005-09-22 00:56:38 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Driver needs to initialize the geography map before using
|
|
|
|
* these helper functions */
|
2006-02-27 08:29:51 +08:00
|
|
|
if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
|
|
|
|
return 0;
|
2005-09-22 00:56:38 +08:00
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
if (ieee->freq_band & LIBIPW_24GHZ_BAND)
|
2005-09-22 00:56:38 +08:00
|
|
|
for (i = 0; i < ieee->geo.bg_channels; i++)
|
|
|
|
/* NOTE: If G mode is currently supported but
|
|
|
|
* this is a B only channel, we don't see it
|
|
|
|
* as valid. */
|
|
|
|
if ((ieee->geo.bg[i].channel == channel) &&
|
2009-08-21 02:48:03 +08:00
|
|
|
!(ieee->geo.bg[i].flags & LIBIPW_CH_INVALID) &&
|
2005-09-22 00:56:38 +08:00
|
|
|
(!(ieee->mode & IEEE_G) ||
|
2009-08-21 02:48:03 +08:00
|
|
|
!(ieee->geo.bg[i].flags & LIBIPW_CH_B_ONLY)))
|
|
|
|
return LIBIPW_24GHZ_BAND;
|
2005-09-22 00:56:38 +08:00
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
if (ieee->freq_band & LIBIPW_52GHZ_BAND)
|
2005-09-22 00:56:38 +08:00
|
|
|
for (i = 0; i < ieee->geo.a_channels; i++)
|
2006-01-19 16:21:45 +08:00
|
|
|
if ((ieee->geo.a[i].channel == channel) &&
|
2009-08-21 02:48:03 +08:00
|
|
|
!(ieee->geo.a[i].flags & LIBIPW_CH_INVALID))
|
|
|
|
return LIBIPW_52GHZ_BAND;
|
2005-09-22 00:56:38 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
int libipw_channel_to_index(struct libipw_device *ieee, u8 channel)
|
2005-09-22 00:56:38 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Driver needs to initialize the geography map before using
|
|
|
|
* these helper functions */
|
2006-02-27 08:29:51 +08:00
|
|
|
if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
|
|
|
|
return -1;
|
2005-09-22 00:56:38 +08:00
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
if (ieee->freq_band & LIBIPW_24GHZ_BAND)
|
2005-09-22 00:56:38 +08:00
|
|
|
for (i = 0; i < ieee->geo.bg_channels; i++)
|
|
|
|
if (ieee->geo.bg[i].channel == channel)
|
|
|
|
return i;
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
if (ieee->freq_band & LIBIPW_52GHZ_BAND)
|
2005-09-22 00:56:38 +08:00
|
|
|
for (i = 0; i < ieee->geo.a_channels; i++)
|
|
|
|
if (ieee->geo.a[i].channel == channel)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
u32 libipw_channel_to_freq(struct libipw_device * ieee, u8 channel)
|
2007-04-22 06:56:29 +08:00
|
|
|
{
|
2009-08-21 02:48:03 +08:00
|
|
|
const struct libipw_channel * ch;
|
2007-04-22 06:56:29 +08:00
|
|
|
|
|
|
|
/* Driver needs to initialize the geography map before using
|
|
|
|
* these helper functions */
|
|
|
|
if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
|
|
|
|
return 0;
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
ch = libipw_get_channel(ieee, channel);
|
2007-04-22 06:56:29 +08:00
|
|
|
if (!ch->channel)
|
|
|
|
return 0;
|
|
|
|
return ch->freq;
|
|
|
|
}
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
u8 libipw_freq_to_channel(struct libipw_device * ieee, u32 freq)
|
2005-09-22 00:56:38 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Driver needs to initialize the geography map before using
|
|
|
|
* these helper functions */
|
2006-02-27 08:29:51 +08:00
|
|
|
if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
|
|
|
|
return 0;
|
2005-09-22 00:56:38 +08:00
|
|
|
|
|
|
|
freq /= 100000;
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
if (ieee->freq_band & LIBIPW_24GHZ_BAND)
|
2005-09-22 00:56:38 +08:00
|
|
|
for (i = 0; i < ieee->geo.bg_channels; i++)
|
|
|
|
if (ieee->geo.bg[i].freq == freq)
|
|
|
|
return ieee->geo.bg[i].channel;
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
if (ieee->freq_band & LIBIPW_52GHZ_BAND)
|
2005-09-22 00:56:38 +08:00
|
|
|
for (i = 0; i < ieee->geo.a_channels; i++)
|
|
|
|
if (ieee->geo.a[i].freq == freq)
|
|
|
|
return ieee->geo.a[i].channel;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-15 11:07:47 +08:00
|
|
|
void libipw_set_geo(struct libipw_device *ieee,
|
2009-08-21 02:48:03 +08:00
|
|
|
const struct libipw_geo *geo)
|
2005-09-22 00:56:38 +08:00
|
|
|
{
|
|
|
|
memcpy(ieee->geo.name, geo->name, 3);
|
|
|
|
ieee->geo.name[3] = '\0';
|
|
|
|
ieee->geo.bg_channels = geo->bg_channels;
|
|
|
|
ieee->geo.a_channels = geo->a_channels;
|
|
|
|
memcpy(ieee->geo.bg, geo->bg, geo->bg_channels *
|
2009-08-21 02:48:03 +08:00
|
|
|
sizeof(struct libipw_channel));
|
2005-09-22 00:56:38 +08:00
|
|
|
memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels *
|
2009-08-21 02:48:03 +08:00
|
|
|
sizeof(struct libipw_channel));
|
2005-09-22 00:56:38 +08:00
|
|
|
}
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
const struct libipw_geo *libipw_get_geo(struct libipw_device *ieee)
|
2005-09-22 00:56:38 +08:00
|
|
|
{
|
|
|
|
return &ieee->geo;
|
|
|
|
}
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
u8 libipw_get_channel_flags(struct libipw_device * ieee, u8 channel)
|
2006-01-19 16:21:45 +08:00
|
|
|
{
|
2009-08-21 02:48:03 +08:00
|
|
|
int index = libipw_channel_to_index(ieee, channel);
|
2006-01-19 16:21:45 +08:00
|
|
|
|
|
|
|
if (index == -1)
|
2009-08-21 02:48:03 +08:00
|
|
|
return LIBIPW_CH_INVALID;
|
2006-01-19 16:21:45 +08:00
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
if (channel <= LIBIPW_24GHZ_CHANNELS)
|
2006-01-19 16:21:45 +08:00
|
|
|
return ieee->geo.bg[index].flags;
|
|
|
|
|
|
|
|
return ieee->geo.a[index].flags;
|
|
|
|
}
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
static const struct libipw_channel bad_channel = {
|
2006-01-19 16:21:45 +08:00
|
|
|
.channel = 0,
|
2009-08-21 02:48:03 +08:00
|
|
|
.flags = LIBIPW_CH_INVALID,
|
2006-01-19 16:21:45 +08:00
|
|
|
.max_power = 0,
|
|
|
|
};
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
const struct libipw_channel *libipw_get_channel(struct libipw_device
|
2006-01-19 16:21:45 +08:00
|
|
|
*ieee, u8 channel)
|
|
|
|
{
|
2009-08-21 02:48:03 +08:00
|
|
|
int index = libipw_channel_to_index(ieee, channel);
|
2006-01-19 16:21:45 +08:00
|
|
|
|
|
|
|
if (index == -1)
|
|
|
|
return &bad_channel;
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
if (channel <= LIBIPW_24GHZ_CHANNELS)
|
2006-01-19 16:21:45 +08:00
|
|
|
return &ieee->geo.bg[index];
|
|
|
|
|
|
|
|
return &ieee->geo.a[index];
|
|
|
|
}
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
EXPORT_SYMBOL(libipw_get_channel);
|
|
|
|
EXPORT_SYMBOL(libipw_get_channel_flags);
|
|
|
|
EXPORT_SYMBOL(libipw_is_valid_channel);
|
|
|
|
EXPORT_SYMBOL(libipw_freq_to_channel);
|
|
|
|
EXPORT_SYMBOL(libipw_channel_to_freq);
|
|
|
|
EXPORT_SYMBOL(libipw_channel_to_index);
|
|
|
|
EXPORT_SYMBOL(libipw_set_geo);
|
|
|
|
EXPORT_SYMBOL(libipw_get_geo);
|