ieee80211_geo.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /******************************************************************************
  2. Copyright(c) 2005 Intel Corporation. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of version 2 of the GNU General Public License as
  5. published by the Free Software Foundation.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  9. more details.
  10. You should have received a copy of the GNU General Public License along with
  11. this program; if not, write to the Free Software Foundation, Inc., 59
  12. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  13. The full GNU General Public License is included in this distribution in the
  14. file called LICENSE.
  15. Contact Information:
  16. James P. Ketrenos <ipw2100-admin@linux.intel.com>
  17. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  18. ******************************************************************************/
  19. #include <linux/compiler.h>
  20. #include <linux/config.h>
  21. #include <linux/errno.h>
  22. #include <linux/if_arp.h>
  23. #include <linux/in6.h>
  24. #include <linux/in.h>
  25. #include <linux/ip.h>
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/proc_fs.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/slab.h>
  32. #include <linux/tcp.h>
  33. #include <linux/types.h>
  34. #include <linux/wireless.h>
  35. #include <linux/etherdevice.h>
  36. #include <asm/uaccess.h>
  37. #include <net/ieee80211.h>
  38. int ieee80211_is_valid_channel(struct ieee80211_device *ieee, u8 channel)
  39. {
  40. int i;
  41. /* Driver needs to initialize the geography map before using
  42. * these helper functions */
  43. BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
  44. if (ieee->freq_band & IEEE80211_24GHZ_BAND)
  45. for (i = 0; i < ieee->geo.bg_channels; i++)
  46. /* NOTE: If G mode is currently supported but
  47. * this is a B only channel, we don't see it
  48. * as valid. */
  49. if ((ieee->geo.bg[i].channel == channel) &&
  50. (!(ieee->mode & IEEE_G) ||
  51. !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY)))
  52. return IEEE80211_24GHZ_BAND;
  53. if (ieee->freq_band & IEEE80211_52GHZ_BAND)
  54. for (i = 0; i < ieee->geo.a_channels; i++)
  55. if (ieee->geo.a[i].channel == channel)
  56. return IEEE80211_52GHZ_BAND;
  57. return 0;
  58. }
  59. int ieee80211_channel_to_index(struct ieee80211_device *ieee, u8 channel)
  60. {
  61. int i;
  62. /* Driver needs to initialize the geography map before using
  63. * these helper functions */
  64. BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
  65. if (ieee->freq_band & IEEE80211_24GHZ_BAND)
  66. for (i = 0; i < ieee->geo.bg_channels; i++)
  67. if (ieee->geo.bg[i].channel == channel)
  68. return i;
  69. if (ieee->freq_band & IEEE80211_52GHZ_BAND)
  70. for (i = 0; i < ieee->geo.a_channels; i++)
  71. if (ieee->geo.a[i].channel == channel)
  72. return i;
  73. return -1;
  74. }
  75. u8 ieee80211_freq_to_channel(struct ieee80211_device * ieee, u32 freq)
  76. {
  77. int i;
  78. /* Driver needs to initialize the geography map before using
  79. * these helper functions */
  80. BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
  81. freq /= 100000;
  82. if (ieee->freq_band & IEEE80211_24GHZ_BAND)
  83. for (i = 0; i < ieee->geo.bg_channels; i++)
  84. if (ieee->geo.bg[i].freq == freq)
  85. return ieee->geo.bg[i].channel;
  86. if (ieee->freq_band & IEEE80211_52GHZ_BAND)
  87. for (i = 0; i < ieee->geo.a_channels; i++)
  88. if (ieee->geo.a[i].freq == freq)
  89. return ieee->geo.a[i].channel;
  90. return 0;
  91. }
  92. int ieee80211_set_geo(struct ieee80211_device *ieee,
  93. const struct ieee80211_geo *geo)
  94. {
  95. memcpy(ieee->geo.name, geo->name, 3);
  96. ieee->geo.name[3] = '\0';
  97. ieee->geo.bg_channels = geo->bg_channels;
  98. ieee->geo.a_channels = geo->a_channels;
  99. memcpy(ieee->geo.bg, geo->bg, geo->bg_channels *
  100. sizeof(struct ieee80211_channel));
  101. memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels *
  102. sizeof(struct ieee80211_channel));
  103. return 0;
  104. }
  105. const struct ieee80211_geo *ieee80211_get_geo(struct ieee80211_device *ieee)
  106. {
  107. return &ieee->geo;
  108. }
  109. EXPORT_SYMBOL(ieee80211_is_valid_channel);
  110. EXPORT_SYMBOL(ieee80211_freq_to_channel);
  111. EXPORT_SYMBOL(ieee80211_channel_to_index);
  112. EXPORT_SYMBOL(ieee80211_set_geo);
  113. EXPORT_SYMBOL(ieee80211_get_geo);