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: |
| 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> |
| 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> |
James Ketrenos | 02cda6a | 2005-09-21 11:56:38 -0500 | [diff] [blame] | 41 | #include <linux/wireless.h> |
| 42 | #include <linux/etherdevice.h> |
| 43 | #include <asm/uaccess.h> |
| 44 | |
| 45 | #include <net/ieee80211.h> |
| 46 | |
| 47 | int ieee80211_is_valid_channel(struct ieee80211_device *ieee, u8 channel) |
| 48 | { |
| 49 | int i; |
| 50 | |
| 51 | /* Driver needs to initialize the geography map before using |
| 52 | * these helper functions */ |
| 53 | BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0); |
| 54 | |
| 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) && |
| 61 | (!(ieee->mode & IEEE_G) || |
| 62 | !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY))) |
| 63 | return IEEE80211_24GHZ_BAND; |
| 64 | |
| 65 | if (ieee->freq_band & IEEE80211_52GHZ_BAND) |
| 66 | for (i = 0; i < ieee->geo.a_channels; i++) |
| 67 | if (ieee->geo.a[i].channel == channel) |
| 68 | return IEEE80211_52GHZ_BAND; |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | int ieee80211_channel_to_index(struct ieee80211_device *ieee, u8 channel) |
| 74 | { |
| 75 | int i; |
| 76 | |
| 77 | /* Driver needs to initialize the geography map before using |
| 78 | * these helper functions */ |
| 79 | BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0); |
| 80 | |
| 81 | if (ieee->freq_band & IEEE80211_24GHZ_BAND) |
| 82 | for (i = 0; i < ieee->geo.bg_channels; i++) |
| 83 | if (ieee->geo.bg[i].channel == channel) |
| 84 | return i; |
| 85 | |
| 86 | if (ieee->freq_band & IEEE80211_52GHZ_BAND) |
| 87 | for (i = 0; i < ieee->geo.a_channels; i++) |
| 88 | if (ieee->geo.a[i].channel == channel) |
| 89 | return i; |
| 90 | |
| 91 | return -1; |
| 92 | } |
| 93 | |
| 94 | u8 ieee80211_freq_to_channel(struct ieee80211_device * ieee, u32 freq) |
| 95 | { |
| 96 | int i; |
| 97 | |
| 98 | /* Driver needs to initialize the geography map before using |
| 99 | * these helper functions */ |
| 100 | BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0); |
| 101 | |
| 102 | freq /= 100000; |
| 103 | |
| 104 | if (ieee->freq_band & IEEE80211_24GHZ_BAND) |
| 105 | for (i = 0; i < ieee->geo.bg_channels; i++) |
| 106 | if (ieee->geo.bg[i].freq == freq) |
| 107 | return ieee->geo.bg[i].channel; |
| 108 | |
| 109 | if (ieee->freq_band & IEEE80211_52GHZ_BAND) |
| 110 | for (i = 0; i < ieee->geo.a_channels; i++) |
| 111 | if (ieee->geo.a[i].freq == freq) |
| 112 | return ieee->geo.a[i].channel; |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | int ieee80211_set_geo(struct ieee80211_device *ieee, |
| 118 | const struct ieee80211_geo *geo) |
| 119 | { |
| 120 | memcpy(ieee->geo.name, geo->name, 3); |
| 121 | ieee->geo.name[3] = '\0'; |
| 122 | ieee->geo.bg_channels = geo->bg_channels; |
| 123 | ieee->geo.a_channels = geo->a_channels; |
| 124 | memcpy(ieee->geo.bg, geo->bg, geo->bg_channels * |
| 125 | sizeof(struct ieee80211_channel)); |
| 126 | memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels * |
| 127 | sizeof(struct ieee80211_channel)); |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | const struct ieee80211_geo *ieee80211_get_geo(struct ieee80211_device *ieee) |
| 132 | { |
| 133 | return &ieee->geo; |
| 134 | } |
| 135 | |
| 136 | EXPORT_SYMBOL(ieee80211_is_valid_channel); |
| 137 | EXPORT_SYMBOL(ieee80211_freq_to_channel); |
| 138 | EXPORT_SYMBOL(ieee80211_channel_to_index); |
| 139 | EXPORT_SYMBOL(ieee80211_set_geo); |
| 140 | EXPORT_SYMBOL(ieee80211_get_geo); |