regdom.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2004, 2005 Reyk Floeter <reyk@vantronix.net>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /*
  17. * Basic regulation domain extensions for the IEEE 802.11 stack
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/string.h>
  21. #include "regdom.h"
  22. static const struct ath5k_regdommap {
  23. enum ath5k_regdom dmn;
  24. enum ath5k_regdom dmn5;
  25. enum ath5k_regdom dmn2;
  26. } r_map[] = {
  27. { DMN_DEFAULT, DMN_DEBUG, DMN_DEBUG },
  28. { DMN_NULL_WORLD, DMN_NULL, DMN_WORLD },
  29. { DMN_NULL_ETSIB, DMN_NULL, DMN_ETSIB },
  30. { DMN_NULL_ETSIC, DMN_NULL, DMN_ETSIC },
  31. { DMN_FCC1_FCCA, DMN_FCC1, DMN_FCCA },
  32. { DMN_FCC1_WORLD, DMN_FCC1, DMN_WORLD },
  33. { DMN_FCC2_FCCA, DMN_FCC2, DMN_FCCA },
  34. { DMN_FCC2_WORLD, DMN_FCC2, DMN_WORLD },
  35. { DMN_FCC2_ETSIC, DMN_FCC2, DMN_ETSIC },
  36. { DMN_FRANCE_NULL, DMN_ETSI3, DMN_ETSI3 },
  37. { DMN_FCC3_FCCA, DMN_FCC3, DMN_WORLD },
  38. { DMN_ETSI1_WORLD, DMN_ETSI1, DMN_WORLD },
  39. { DMN_ETSI3_ETSIA, DMN_ETSI3, DMN_WORLD },
  40. { DMN_ETSI2_WORLD, DMN_ETSI2, DMN_WORLD },
  41. { DMN_ETSI3_WORLD, DMN_ETSI3, DMN_WORLD },
  42. { DMN_ETSI4_WORLD, DMN_ETSI4, DMN_WORLD },
  43. { DMN_ETSI4_ETSIC, DMN_ETSI4, DMN_ETSIC },
  44. { DMN_ETSI5_WORLD, DMN_ETSI5, DMN_WORLD },
  45. { DMN_ETSI6_WORLD, DMN_ETSI6, DMN_WORLD },
  46. { DMN_ETSI_NULL, DMN_ETSI1, DMN_ETSI1 },
  47. { DMN_MKK1_MKKA, DMN_MKK1, DMN_MKKA },
  48. { DMN_MKK1_MKKB, DMN_MKK1, DMN_MKKA },
  49. { DMN_APL4_WORLD, DMN_APL4, DMN_WORLD },
  50. { DMN_MKK2_MKKA, DMN_MKK2, DMN_MKKA },
  51. { DMN_APL_NULL, DMN_APL1, DMN_NULL },
  52. { DMN_APL2_WORLD, DMN_APL2, DMN_WORLD },
  53. { DMN_APL2_APLC, DMN_APL2, DMN_WORLD },
  54. { DMN_APL3_WORLD, DMN_APL3, DMN_WORLD },
  55. { DMN_MKK1_FCCA, DMN_MKK1, DMN_FCCA },
  56. { DMN_APL2_APLD, DMN_APL2, DMN_APLD },
  57. { DMN_MKK1_MKKA1, DMN_MKK1, DMN_MKKA },
  58. { DMN_MKK1_MKKA2, DMN_MKK1, DMN_MKKA },
  59. { DMN_APL1_WORLD, DMN_APL1, DMN_WORLD },
  60. { DMN_APL1_FCCA, DMN_APL1, DMN_FCCA },
  61. { DMN_APL1_APLA, DMN_APL1, DMN_WORLD },
  62. { DMN_APL1_ETSIC, DMN_APL1, DMN_ETSIC },
  63. { DMN_APL2_ETSIC, DMN_APL2, DMN_ETSIC },
  64. { DMN_APL5_WORLD, DMN_APL5, DMN_WORLD },
  65. { DMN_WOR0_WORLD, DMN_WORLD, DMN_WORLD },
  66. { DMN_WOR1_WORLD, DMN_WORLD, DMN_WORLD },
  67. { DMN_WOR2_WORLD, DMN_WORLD, DMN_WORLD },
  68. { DMN_WOR3_WORLD, DMN_WORLD, DMN_WORLD },
  69. { DMN_WOR4_WORLD, DMN_WORLD, DMN_WORLD },
  70. { DMN_WOR5_ETSIC, DMN_WORLD, DMN_WORLD },
  71. { DMN_WOR01_WORLD, DMN_WORLD, DMN_WORLD },
  72. { DMN_WOR02_WORLD, DMN_WORLD, DMN_WORLD },
  73. { DMN_EU1_WORLD, DMN_ETSI1, DMN_WORLD },
  74. { DMN_WOR9_WORLD, DMN_WORLD, DMN_WORLD },
  75. { DMN_WORA_WORLD, DMN_WORLD, DMN_WORLD },
  76. };
  77. enum ath5k_regdom ath5k_regdom2flag(enum ath5k_regdom dmn, u16 mhz)
  78. {
  79. unsigned int i;
  80. for (i = 0; i < ARRAY_SIZE(r_map); i++) {
  81. if (r_map[i].dmn == dmn) {
  82. if (mhz >= 2000 && mhz <= 3000)
  83. return r_map[i].dmn2;
  84. if (mhz >= IEEE80211_CHANNELS_5GHZ_MIN &&
  85. mhz <= IEEE80211_CHANNELS_5GHZ_MAX)
  86. return r_map[i].dmn5;
  87. }
  88. }
  89. return DMN_DEBUG;
  90. }
  91. u16 ath5k_regdom_from_ieee(enum ath5k_regdom ieee)
  92. {
  93. u32 regdomain = (u32)ieee;
  94. /*
  95. * Use the default regulation domain if the value is empty
  96. * or not supported by the net80211 regulation code.
  97. */
  98. if (ath5k_regdom2flag(regdomain, IEEE80211_CHANNELS_5GHZ_MIN) ==
  99. DMN_DEBUG)
  100. return (u16)AR5K_TUNE_REGDOMAIN;
  101. /* It is supported, just return the value */
  102. return regdomain;
  103. }
  104. enum ath5k_regdom ath5k_regdom_to_ieee(u16 regdomain)
  105. {
  106. enum ath5k_regdom ieee = (enum ath5k_regdom)regdomain;
  107. return ieee;
  108. }