James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 1 | /****************************************************************************** |
| 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: |
Reinette Chatre | c1eb2c8 | 2009-08-21 13:34:26 -0700 | [diff] [blame] | 22 | Intel Linux Wireless <ilw@linux.intel.com> |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 23 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | |
| 25 | ******************************************************************************/ |
| 26 | #include <linux/compiler.h> |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 27 | #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> |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 37 | #include <linux/tcp.h> |
| 38 | #include <linux/types.h> |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 39 | #include <linux/wireless.h> |
| 40 | #include <linux/etherdevice.h> |
| 41 | #include <asm/uaccess.h> |
| 42 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 43 | #include "libipw.h" |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 44 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 45 | int libipw_is_valid_channel(struct libipw_device *ieee, u8 channel) |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 46 | { |
| 47 | int i; |
| 48 | |
| 49 | /* Driver needs to initialize the geography map before using |
| 50 | * these helper functions */ |
Pete Zaitcev | 07981aa | 2006-02-26 16:29:51 -0800 | [diff] [blame] | 51 | if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0) |
| 52 | return 0; |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 53 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 54 | if (ieee->freq_band & LIBIPW_24GHZ_BAND) |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 55 | for (i = 0; i < ieee->geo.bg_channels; i++) |
| 56 | /* NOTE: If G mode is currently supported but |
| 57 | * this is a B only channel, we don't see it |
| 58 | * as valid. */ |
| 59 | if ((ieee->geo.bg[i].channel == channel) && |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 60 | !(ieee->geo.bg[i].flags & LIBIPW_CH_INVALID) && |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 61 | (!(ieee->mode & IEEE_G) || |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 62 | !(ieee->geo.bg[i].flags & LIBIPW_CH_B_ONLY))) |
| 63 | return LIBIPW_24GHZ_BAND; |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 64 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 65 | if (ieee->freq_band & LIBIPW_52GHZ_BAND) |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 66 | for (i = 0; i < ieee->geo.a_channels; i++) |
Zhu Yi | d128f6c | 2006-01-19 16:21:45 +0800 | [diff] [blame] | 67 | if ((ieee->geo.a[i].channel == channel) && |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 68 | !(ieee->geo.a[i].flags & LIBIPW_CH_INVALID)) |
| 69 | return LIBIPW_52GHZ_BAND; |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 74 | int libipw_channel_to_index(struct libipw_device *ieee, u8 channel) |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 75 | { |
| 76 | int i; |
| 77 | |
| 78 | /* Driver needs to initialize the geography map before using |
| 79 | * these helper functions */ |
Pete Zaitcev | 07981aa | 2006-02-26 16:29:51 -0800 | [diff] [blame] | 80 | if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0) |
| 81 | return -1; |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 82 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 83 | if (ieee->freq_band & LIBIPW_24GHZ_BAND) |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 84 | for (i = 0; i < ieee->geo.bg_channels; i++) |
| 85 | if (ieee->geo.bg[i].channel == channel) |
| 86 | return i; |
| 87 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 88 | if (ieee->freq_band & LIBIPW_52GHZ_BAND) |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 89 | for (i = 0; i < ieee->geo.a_channels; i++) |
| 90 | if (ieee->geo.a[i].channel == channel) |
| 91 | return i; |
| 92 | |
| 93 | return -1; |
| 94 | } |
| 95 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 96 | u32 libipw_channel_to_freq(struct libipw_device * ieee, u8 channel) |
Larry Finger | f5cdf30 | 2007-04-21 17:56:29 -0500 | [diff] [blame] | 97 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 98 | const struct libipw_channel * ch; |
Larry Finger | f5cdf30 | 2007-04-21 17:56:29 -0500 | [diff] [blame] | 99 | |
| 100 | /* Driver needs to initialize the geography map before using |
| 101 | * these helper functions */ |
| 102 | if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0) |
| 103 | return 0; |
| 104 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 105 | ch = libipw_get_channel(ieee, channel); |
Larry Finger | f5cdf30 | 2007-04-21 17:56:29 -0500 | [diff] [blame] | 106 | if (!ch->channel) |
| 107 | return 0; |
| 108 | return ch->freq; |
| 109 | } |
| 110 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 111 | u8 libipw_freq_to_channel(struct libipw_device * ieee, u32 freq) |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 112 | { |
| 113 | int i; |
| 114 | |
| 115 | /* Driver needs to initialize the geography map before using |
| 116 | * these helper functions */ |
Pete Zaitcev | 07981aa | 2006-02-26 16:29:51 -0800 | [diff] [blame] | 117 | if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0) |
| 118 | return 0; |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 119 | |
| 120 | freq /= 100000; |
| 121 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 122 | if (ieee->freq_band & LIBIPW_24GHZ_BAND) |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 123 | for (i = 0; i < ieee->geo.bg_channels; i++) |
| 124 | if (ieee->geo.bg[i].freq == freq) |
| 125 | return ieee->geo.bg[i].channel; |
| 126 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 127 | if (ieee->freq_band & LIBIPW_52GHZ_BAND) |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 128 | for (i = 0; i < ieee->geo.a_channels; i++) |
| 129 | if (ieee->geo.a[i].freq == freq) |
| 130 | return ieee->geo.a[i].channel; |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 135 | int libipw_set_geo(struct libipw_device *ieee, |
| 136 | const struct libipw_geo *geo) |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 137 | { |
| 138 | memcpy(ieee->geo.name, geo->name, 3); |
| 139 | ieee->geo.name[3] = '\0'; |
| 140 | ieee->geo.bg_channels = geo->bg_channels; |
| 141 | ieee->geo.a_channels = geo->a_channels; |
| 142 | memcpy(ieee->geo.bg, geo->bg, geo->bg_channels * |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 143 | sizeof(struct libipw_channel)); |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 144 | memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels * |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 145 | sizeof(struct libipw_channel)); |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 149 | const struct libipw_geo *libipw_get_geo(struct libipw_device *ieee) |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 150 | { |
| 151 | return &ieee->geo; |
| 152 | } |
| 153 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 154 | u8 libipw_get_channel_flags(struct libipw_device * ieee, u8 channel) |
Zhu Yi | d128f6c | 2006-01-19 16:21:45 +0800 | [diff] [blame] | 155 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 156 | int index = libipw_channel_to_index(ieee, channel); |
Zhu Yi | d128f6c | 2006-01-19 16:21:45 +0800 | [diff] [blame] | 157 | |
| 158 | if (index == -1) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 159 | return LIBIPW_CH_INVALID; |
Zhu Yi | d128f6c | 2006-01-19 16:21:45 +0800 | [diff] [blame] | 160 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 161 | if (channel <= LIBIPW_24GHZ_CHANNELS) |
Zhu Yi | d128f6c | 2006-01-19 16:21:45 +0800 | [diff] [blame] | 162 | return ieee->geo.bg[index].flags; |
| 163 | |
| 164 | return ieee->geo.a[index].flags; |
| 165 | } |
| 166 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 167 | static const struct libipw_channel bad_channel = { |
Zhu Yi | d128f6c | 2006-01-19 16:21:45 +0800 | [diff] [blame] | 168 | .channel = 0, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 169 | .flags = LIBIPW_CH_INVALID, |
Zhu Yi | d128f6c | 2006-01-19 16:21:45 +0800 | [diff] [blame] | 170 | .max_power = 0, |
| 171 | }; |
| 172 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 173 | const struct libipw_channel *libipw_get_channel(struct libipw_device |
Zhu Yi | d128f6c | 2006-01-19 16:21:45 +0800 | [diff] [blame] | 174 | *ieee, u8 channel) |
| 175 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 176 | int index = libipw_channel_to_index(ieee, channel); |
Zhu Yi | d128f6c | 2006-01-19 16:21:45 +0800 | [diff] [blame] | 177 | |
| 178 | if (index == -1) |
| 179 | return &bad_channel; |
| 180 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 181 | if (channel <= LIBIPW_24GHZ_CHANNELS) |
Zhu Yi | d128f6c | 2006-01-19 16:21:45 +0800 | [diff] [blame] | 182 | return &ieee->geo.bg[index]; |
| 183 | |
| 184 | return &ieee->geo.a[index]; |
| 185 | } |
| 186 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 187 | EXPORT_SYMBOL(libipw_get_channel); |
| 188 | EXPORT_SYMBOL(libipw_get_channel_flags); |
| 189 | EXPORT_SYMBOL(libipw_is_valid_channel); |
| 190 | EXPORT_SYMBOL(libipw_freq_to_channel); |
| 191 | EXPORT_SYMBOL(libipw_channel_to_freq); |
| 192 | EXPORT_SYMBOL(libipw_channel_to_index); |
| 193 | EXPORT_SYMBOL(libipw_set_geo); |
| 194 | EXPORT_SYMBOL(libipw_get_geo); |