regdomain.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. #include "ieee80211_i.h"
  34. static int ieee80211_regdom = 0x10; /* FCC */
  35. module_param(ieee80211_regdom, int, 0444);
  36. MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain; 64=MKK");
  37. /*
  38. * If firmware is upgraded by the vendor, additional channels can be used based
  39. * on the new Japanese regulatory rules. This is indicated by setting
  40. * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
  41. * module.
  42. */
  43. static int ieee80211_japan_5ghz /* = 0 */;
  44. module_param(ieee80211_japan_5ghz, int, 0444);
  45. MODULE_PARM_DESC(ieee80211_japan_5ghz, "Vendor-updated firmware for 5 GHz");
  46. struct ieee80211_channel_range {
  47. short start_freq;
  48. short end_freq;
  49. unsigned char power_level;
  50. unsigned char antenna_max;
  51. };
  52. static const struct ieee80211_channel_range ieee80211_fcc_channels[] = {
  53. { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
  54. { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
  55. { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
  56. { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
  57. { 0 }
  58. };
  59. static const struct ieee80211_channel_range ieee80211_mkk_channels[] = {
  60. { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
  61. { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
  62. { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
  63. { 0 }
  64. };
  65. static const struct ieee80211_channel_range *channel_range =
  66. ieee80211_fcc_channels;
  67. static void ieee80211_unmask_channel(int mode, struct ieee80211_channel *chan)
  68. {
  69. int i;
  70. chan->flag = 0;
  71. if (ieee80211_regdom == 64 &&
  72. (mode == MODE_ATHEROS_TURBO || mode == MODE_ATHEROS_TURBOG)) {
  73. /* Do not allow Turbo modes in Japan. */
  74. return;
  75. }
  76. for (i = 0; channel_range[i].start_freq; i++) {
  77. const struct ieee80211_channel_range *r = &channel_range[i];
  78. if (r->start_freq <= chan->freq && r->end_freq >= chan->freq) {
  79. if (ieee80211_regdom == 64 && !ieee80211_japan_5ghz &&
  80. chan->freq >= 5260 && chan->freq <= 5320) {
  81. /*
  82. * Skip new channels in Japan since the
  83. * firmware was not marked having been upgraded
  84. * by the vendor.
  85. */
  86. continue;
  87. }
  88. if (ieee80211_regdom == 0x10 &&
  89. (chan->freq == 5190 || chan->freq == 5210 ||
  90. chan->freq == 5230)) {
  91. /* Skip MKK channels when in FCC domain. */
  92. continue;
  93. }
  94. chan->flag |= IEEE80211_CHAN_W_SCAN |
  95. IEEE80211_CHAN_W_ACTIVE_SCAN |
  96. IEEE80211_CHAN_W_IBSS;
  97. chan->power_level = r->power_level;
  98. chan->antenna_max = r->antenna_max;
  99. if (ieee80211_regdom == 64 &&
  100. (chan->freq == 5170 || chan->freq == 5190 ||
  101. chan->freq == 5210 || chan->freq == 5230)) {
  102. /*
  103. * New regulatory rules in Japan have backwards
  104. * compatibility with old channels in 5.15-5.25
  105. * GHz band, but the station is not allowed to
  106. * use active scan on these old channels.
  107. */
  108. chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
  109. }
  110. if (ieee80211_regdom == 64 &&
  111. (chan->freq == 5260 || chan->freq == 5280 ||
  112. chan->freq == 5300 || chan->freq == 5320)) {
  113. /*
  114. * IBSS is not allowed on 5.25-5.35 GHz band
  115. * due to radar detection requirements.
  116. */
  117. chan->flag &= ~IEEE80211_CHAN_W_IBSS;
  118. }
  119. break;
  120. }
  121. }
  122. }
  123. void ieee80211_set_default_regdomain(struct ieee80211_hw_mode *mode)
  124. {
  125. int c;
  126. for (c = 0; c < mode->num_channels; c++)
  127. ieee80211_unmask_channel(mode->mode, &mode->channels[c]);
  128. }
  129. void ieee80211_regdomain_init(void)
  130. {
  131. if (ieee80211_regdom == 0x40)
  132. channel_range = ieee80211_mkk_channels;
  133. }