regdomain.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. for (i = 0; channel_range[i].start_freq; i++) {
  72. const struct ieee80211_channel_range *r = &channel_range[i];
  73. if (r->start_freq <= chan->freq && r->end_freq >= chan->freq) {
  74. if (ieee80211_regdom == 64 && !ieee80211_japan_5ghz &&
  75. chan->freq >= 5260 && chan->freq <= 5320) {
  76. /*
  77. * Skip new channels in Japan since the
  78. * firmware was not marked having been upgraded
  79. * by the vendor.
  80. */
  81. continue;
  82. }
  83. if (ieee80211_regdom == 0x10 &&
  84. (chan->freq == 5190 || chan->freq == 5210 ||
  85. chan->freq == 5230)) {
  86. /* Skip MKK channels when in FCC domain. */
  87. continue;
  88. }
  89. chan->flag |= IEEE80211_CHAN_W_SCAN |
  90. IEEE80211_CHAN_W_ACTIVE_SCAN |
  91. IEEE80211_CHAN_W_IBSS;
  92. chan->power_level = r->power_level;
  93. chan->antenna_max = r->antenna_max;
  94. if (ieee80211_regdom == 64 &&
  95. (chan->freq == 5170 || chan->freq == 5190 ||
  96. chan->freq == 5210 || chan->freq == 5230)) {
  97. /*
  98. * New regulatory rules in Japan have backwards
  99. * compatibility with old channels in 5.15-5.25
  100. * GHz band, but the station is not allowed to
  101. * use active scan on these old channels.
  102. */
  103. chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
  104. }
  105. if (ieee80211_regdom == 64 &&
  106. (chan->freq == 5260 || chan->freq == 5280 ||
  107. chan->freq == 5300 || chan->freq == 5320)) {
  108. /*
  109. * IBSS is not allowed on 5.25-5.35 GHz band
  110. * due to radar detection requirements.
  111. */
  112. chan->flag &= ~IEEE80211_CHAN_W_IBSS;
  113. }
  114. break;
  115. }
  116. }
  117. }
  118. void ieee80211_set_default_regdomain(struct ieee80211_hw_mode *mode)
  119. {
  120. int c;
  121. for (c = 0; c < mode->num_channels; c++)
  122. ieee80211_unmask_channel(mode->mode, &mode->channels[c]);
  123. }
  124. void ieee80211_regdomain_init(void)
  125. {
  126. if (ieee80211_regdom == 0x40)
  127. channel_range = ieee80211_mkk_channels;
  128. }