regdomain.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright 2002-2005, Instant802 Networks, Inc.
  3. * Copyright 2005-2006, Devicescape Software, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. /*
  10. * This regulatory domain control implementation is known to be incomplete
  11. * and confusing. mac80211 regulatory domain control will be significantly
  12. * reworked in the not-too-distant future.
  13. *
  14. * For now, drivers wishing to control which channels are and aren't available
  15. * are advised as follows:
  16. * - set the IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED flag
  17. * - continue to include *ALL* possible channels in the modes registered
  18. * through ieee80211_register_hwmode()
  19. * - for each allowable ieee80211_channel structure registered in the above
  20. * call, set the flag member to some meaningful value such as
  21. * IEEE80211_CHAN_W_SCAN | IEEE80211_CHAN_W_ACTIVE_SCAN |
  22. * IEEE80211_CHAN_W_IBSS.
  23. * - leave flag as 0 for non-allowable channels
  24. *
  25. * The usual implementation is for a driver to read a device EEPROM to
  26. * determine which regulatory domain it should be operating under, then
  27. * looking up the allowable channels in a driver-local table, then performing
  28. * the above.
  29. */
  30. #include <linux/module.h>
  31. #include <linux/netdevice.h>
  32. #include <net/mac80211.h>
  33. static int ieee80211_regdom = 0x10; /* FCC */
  34. module_param(ieee80211_regdom, int, 0444);
  35. MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain; 64=MKK");
  36. /*
  37. * If firmware is upgraded by the vendor, additional channels can be used based
  38. * on the new Japanese regulatory rules. This is indicated by setting
  39. * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
  40. * module.
  41. */
  42. static int ieee80211_japan_5ghz /* = 0 */;
  43. module_param(ieee80211_japan_5ghz, int, 0444);
  44. MODULE_PARM_DESC(ieee80211_japan_5ghz, "Vendor-updated firmware for 5 GHz");
  45. struct ieee80211_channel_range {
  46. short start_freq;
  47. short end_freq;
  48. unsigned char power_level;
  49. unsigned char antenna_max;
  50. };
  51. static const struct ieee80211_channel_range ieee80211_fcc_channels[] = {
  52. { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
  53. { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
  54. { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
  55. { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
  56. { 0 }
  57. };
  58. static const struct ieee80211_channel_range ieee80211_mkk_channels[] = {
  59. { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
  60. { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
  61. { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
  62. { 0 }
  63. };
  64. static const struct ieee80211_channel_range *channel_range =
  65. ieee80211_fcc_channels;
  66. static void ieee80211_unmask_channel(int mode, struct ieee80211_channel *chan)
  67. {
  68. int i;
  69. chan->flag = 0;
  70. if (ieee80211_regdom == 64 &&
  71. (mode == MODE_ATHEROS_TURBO || mode == MODE_ATHEROS_TURBOG)) {
  72. /* Do not allow Turbo modes in Japan. */
  73. return;
  74. }
  75. for (i = 0; channel_range[i].start_freq; i++) {
  76. const struct ieee80211_channel_range *r = &channel_range[i];
  77. if (r->start_freq <= chan->freq && r->end_freq >= chan->freq) {
  78. if (ieee80211_regdom == 64 && !ieee80211_japan_5ghz &&
  79. chan->freq >= 5260 && chan->freq <= 5320) {
  80. /*
  81. * Skip new channels in Japan since the
  82. * firmware was not marked having been upgraded
  83. * by the vendor.
  84. */
  85. continue;
  86. }
  87. if (ieee80211_regdom == 0x10 &&
  88. (chan->freq == 5190 || chan->freq == 5210 ||
  89. chan->freq == 5230)) {
  90. /* Skip MKK channels when in FCC domain. */
  91. continue;
  92. }
  93. chan->flag |= IEEE80211_CHAN_W_SCAN |
  94. IEEE80211_CHAN_W_ACTIVE_SCAN |
  95. IEEE80211_CHAN_W_IBSS;
  96. chan->power_level = r->power_level;
  97. chan->antenna_max = r->antenna_max;
  98. if (ieee80211_regdom == 64 &&
  99. (chan->freq == 5170 || chan->freq == 5190 ||
  100. chan->freq == 5210 || chan->freq == 5230)) {
  101. /*
  102. * New regulatory rules in Japan have backwards
  103. * compatibility with old channels in 5.15-5.25
  104. * GHz band, but the station is not allowed to
  105. * use active scan on these old channels.
  106. */
  107. chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
  108. }
  109. if (ieee80211_regdom == 64 &&
  110. (chan->freq == 5260 || chan->freq == 5280 ||
  111. chan->freq == 5300 || chan->freq == 5320)) {
  112. /*
  113. * IBSS is not allowed on 5.25-5.35 GHz band
  114. * due to radar detection requirements.
  115. */
  116. chan->flag &= ~IEEE80211_CHAN_W_IBSS;
  117. }
  118. break;
  119. }
  120. }
  121. }
  122. void ieee80211_set_default_regdomain(struct ieee80211_hw_mode *mode)
  123. {
  124. int c;
  125. for (c = 0; c < mode->num_channels; c++)
  126. ieee80211_unmask_channel(mode->mode, &mode->channels[c]);
  127. }
  128. void ieee80211_regdomain_init(void)
  129. {
  130. if (ieee80211_regdom == 0x40)
  131. channel_range = ieee80211_mkk_channels;
  132. }