zd_ieee80211.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* zd_ieee80211.c
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /*
  18. * In the long term, we'll probably find a better way of handling regulatory
  19. * requirements outside of the driver.
  20. */
  21. #include <linux/kernel.h>
  22. #include <net/mac80211.h>
  23. #include "zd_ieee80211.h"
  24. #include "zd_mac.h"
  25. struct channel_range {
  26. u8 regdomain;
  27. u8 start;
  28. u8 end; /* exclusive (channel must be less than end) */
  29. };
  30. static const struct channel_range channel_ranges[] = {
  31. { ZD_REGDOMAIN_FCC, 1, 12 },
  32. { ZD_REGDOMAIN_IC, 1, 12 },
  33. { ZD_REGDOMAIN_ETSI, 1, 14 },
  34. { ZD_REGDOMAIN_JAPAN, 1, 14 },
  35. { ZD_REGDOMAIN_SPAIN, 1, 14 },
  36. { ZD_REGDOMAIN_FRANCE, 1, 14 },
  37. /* Japan originally only had channel 14 available (see CHNL_ID 0x40 in
  38. * 802.11). However, in 2001 the range was extended to include channels
  39. * 1-13. The ZyDAS devices still use the old region code but are
  40. * designed to allow the extra channel access in Japan. */
  41. { ZD_REGDOMAIN_JAPAN_ADD, 1, 15 },
  42. };
  43. static const struct channel_range *zd_channel_range(u8 regdomain)
  44. {
  45. int i;
  46. for (i = 0; i < ARRAY_SIZE(channel_ranges); i++) {
  47. const struct channel_range *range = &channel_ranges[i];
  48. if (range->regdomain == regdomain)
  49. return range;
  50. }
  51. return NULL;
  52. }
  53. #define CHAN_TO_IDX(chan) ((chan) - 1)
  54. static void unmask_bg_channels(struct ieee80211_hw *hw,
  55. const struct channel_range *range,
  56. struct ieee80211_hw_mode *mode)
  57. {
  58. u8 channel;
  59. for (channel = range->start; channel < range->end; channel++) {
  60. struct ieee80211_channel *chan =
  61. &mode->channels[CHAN_TO_IDX(channel)];
  62. chan->flag |= IEEE80211_CHAN_W_SCAN |
  63. IEEE80211_CHAN_W_ACTIVE_SCAN |
  64. IEEE80211_CHAN_W_IBSS;
  65. }
  66. }
  67. void zd_geo_init(struct ieee80211_hw *hw, u8 regdomain)
  68. {
  69. struct zd_mac *mac = zd_hw_mac(hw);
  70. const struct channel_range *range;
  71. dev_dbg(zd_mac_dev(mac), "regdomain %#02x\n", regdomain);
  72. range = zd_channel_range(regdomain);
  73. if (!range) {
  74. /* The vendor driver overrides the regulatory domain and
  75. * allowed channel registers and unconditionally restricts
  76. * available channels to 1-11 everywhere. Match their
  77. * questionable behaviour only for regdomains which we don't
  78. * recognise. */
  79. dev_warn(zd_mac_dev(mac), "Unrecognised regulatory domain: "
  80. "%#02x. Defaulting to FCC.\n", regdomain);
  81. range = zd_channel_range(ZD_REGDOMAIN_FCC);
  82. }
  83. unmask_bg_channels(hw, range, &mac->modes[0]);
  84. unmask_bg_channels(hw, range, &mac->modes[1]);
  85. }