ieee80211_geo.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/errno.h>
  21. #include <linux/if_arp.h>
  22. #include <linux/in6.h>
  23. #include <linux/in.h>
  24. #include <linux/ip.h>
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/proc_fs.h>
  29. #include <linux/skbuff.h>
  30. #include <linux/slab.h>
  31. #include <linux/tcp.h>
  32. #include <linux/types.h>
  33. #include <linux/wireless.h>
  34. #include <linux/etherdevice.h>
  35. #include <asm/uaccess.h>
  36. #include <net/ieee80211.h>
  37. int ieee80211_is_valid_channel(struct ieee80211_device *ieee, u8 channel)
  38. {
  39. int i;
  40. /* Driver needs to initialize the geography map before using
  41. * these helper functions */
  42. if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
  43. return 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->geo.bg[i].flags & IEEE80211_CH_INVALID) &&
  51. (!(ieee->mode & IEEE_G) ||
  52. !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY)))
  53. return IEEE80211_24GHZ_BAND;
  54. if (ieee->freq_band & IEEE80211_52GHZ_BAND)
  55. for (i = 0; i < ieee->geo.a_channels; i++)
  56. if ((ieee->geo.a[i].channel == channel) &&
  57. !(ieee->geo.a[i].flags & IEEE80211_CH_INVALID))
  58. return IEEE80211_52GHZ_BAND;
  59. return 0;
  60. }
  61. int ieee80211_channel_to_index(struct ieee80211_device *ieee, u8 channel)
  62. {
  63. int i;
  64. /* Driver needs to initialize the geography map before using
  65. * these helper functions */
  66. if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
  67. return -1;
  68. if (ieee->freq_band & IEEE80211_24GHZ_BAND)
  69. for (i = 0; i < ieee->geo.bg_channels; i++)
  70. if (ieee->geo.bg[i].channel == channel)
  71. return i;
  72. if (ieee->freq_band & IEEE80211_52GHZ_BAND)
  73. for (i = 0; i < ieee->geo.a_channels; i++)
  74. if (ieee->geo.a[i].channel == channel)
  75. return i;
  76. return -1;
  77. }
  78. u8 ieee80211_freq_to_channel(struct ieee80211_device * ieee, u32 freq)
  79. {
  80. int i;
  81. /* Driver needs to initialize the geography map before using
  82. * these helper functions */
  83. if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
  84. return 0;
  85. freq /= 100000;
  86. if (ieee->freq_band & IEEE80211_24GHZ_BAND)
  87. for (i = 0; i < ieee->geo.bg_channels; i++)
  88. if (ieee->geo.bg[i].freq == freq)
  89. return ieee->geo.bg[i].channel;
  90. if (ieee->freq_band & IEEE80211_52GHZ_BAND)
  91. for (i = 0; i < ieee->geo.a_channels; i++)
  92. if (ieee->geo.a[i].freq == freq)
  93. return ieee->geo.a[i].channel;
  94. return 0;
  95. }
  96. int ieee80211_set_geo(struct ieee80211_device *ieee,
  97. const struct ieee80211_geo *geo)
  98. {
  99. memcpy(ieee->geo.name, geo->name, 3);
  100. ieee->geo.name[3] = '\0';
  101. ieee->geo.bg_channels = geo->bg_channels;
  102. ieee->geo.a_channels = geo->a_channels;
  103. memcpy(ieee->geo.bg, geo->bg, geo->bg_channels *
  104. sizeof(struct ieee80211_channel));
  105. memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels *
  106. sizeof(struct ieee80211_channel));
  107. return 0;
  108. }
  109. const struct ieee80211_geo *ieee80211_get_geo(struct ieee80211_device *ieee)
  110. {
  111. return &ieee->geo;
  112. }
  113. u8 ieee80211_get_channel_flags(struct ieee80211_device * ieee, u8 channel)
  114. {
  115. int index = ieee80211_channel_to_index(ieee, channel);
  116. if (index == -1)
  117. return IEEE80211_CH_INVALID;
  118. if (channel <= IEEE80211_24GHZ_CHANNELS)
  119. return ieee->geo.bg[index].flags;
  120. return ieee->geo.a[index].flags;
  121. }
  122. static const struct ieee80211_channel bad_channel = {
  123. .channel = 0,
  124. .flags = IEEE80211_CH_INVALID,
  125. .max_power = 0,
  126. };
  127. const struct ieee80211_channel *ieee80211_get_channel(struct ieee80211_device
  128. *ieee, u8 channel)
  129. {
  130. int index = ieee80211_channel_to_index(ieee, channel);
  131. if (index == -1)
  132. return &bad_channel;
  133. if (channel <= IEEE80211_24GHZ_CHANNELS)
  134. return &ieee->geo.bg[index];
  135. return &ieee->geo.a[index];
  136. }
  137. EXPORT_SYMBOL(ieee80211_get_channel);
  138. EXPORT_SYMBOL(ieee80211_get_channel_flags);
  139. EXPORT_SYMBOL(ieee80211_is_valid_channel);
  140. EXPORT_SYMBOL(ieee80211_freq_to_channel);
  141. EXPORT_SYMBOL(ieee80211_channel_to_index);
  142. EXPORT_SYMBOL(ieee80211_set_geo);
  143. EXPORT_SYMBOL(ieee80211_get_geo);