regulatory.txt 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. Linux wireless regulatory documentation
  2. ---------------------------------------
  3. This document gives a brief review over how the Linux wireless
  4. regulatory infrastructure works.
  5. More up to date information can be obtained at the project's web page:
  6. http://wireless.kernel.org/en/developers/Regulatory
  7. Keeping regulatory domains in userspace
  8. ---------------------------------------
  9. Due to the dynamic nature of regulatory domains we keep them
  10. in userspace and provide a framework for userspace to upload
  11. to the kernel one regulatory domain to be used as the central
  12. core regulatory domain all wireless devices should adhere to.
  13. How to get regulatory domains to the kernel
  14. -------------------------------------------
  15. Userspace gets a regulatory domain in the kernel by having
  16. a userspace agent build it and send it via nl80211. Only
  17. expected regulatory domains will be respected by the kernel.
  18. A currently available userspace agent which can accomplish this
  19. is CRDA - central regulatory domain agent. Its documented here:
  20. http://wireless.kernel.org/en/developers/Regulatory/CRDA
  21. Essentially the kernel will send a udev event when it knows
  22. it needs a new regulatory domain. A udev rule can be put in place
  23. to trigger crda to send the respective regulatory domain for a
  24. specific ISO/IEC 3166 alpha2.
  25. Below is an example udev rule which can be used:
  26. # Example file, should be put in /etc/udev/rules.d/regulatory.rules
  27. KERNEL=="regulatory*", ACTION=="change", SUBSYSTEM=="platform", RUN+="/sbin/crda"
  28. The alpha2 is passed as an environment variable under the variable COUNTRY.
  29. Who asks for regulatory domains?
  30. --------------------------------
  31. * Users
  32. Users can use iw:
  33. http://wireless.kernel.org/en/users/Documentation/iw
  34. An example:
  35. # set regulatory domain to "Costa Rica"
  36. iw reg set CR
  37. This will request the kernel to set the regulatory domain to
  38. the specificied alpha2. The kernel in turn will then ask userspace
  39. to provide a regulatory domain for the alpha2 specified by the user
  40. by sending a uevent.
  41. * Wireless subsystems for Country Information elements
  42. The kernel will send a uevent to inform userspace a new
  43. regulatory domain is required. More on this to be added
  44. as its integration is added.
  45. * Drivers
  46. If drivers determine they need a specific regulatory domain
  47. set they can inform the wireless core using regulatory_hint().
  48. They have two options -- they either provide an alpha2 so that
  49. crda can provide back a regulatory domain for that country or
  50. they can build their own regulatory domain based on internal
  51. custom knowledge so the wireless core can respect it.
  52. *Most* drivers will rely on the first mechanism of providing a
  53. regulatory hint with an alpha2. For these drivers there is an additional
  54. check that can be used to ensure compliance based on custom EEPROM
  55. regulatory data. This additional check can be used by drivers by
  56. registering on its struct wiphy a reg_notifier() callback. This notifier
  57. is called when the core's regulatory domain has been changed. The driver
  58. can use this to review the changes made and also review who made them
  59. (driver, user, country IE) and determine what to allow based on its
  60. internal EEPROM data. Devices drivers wishing to be capable of world
  61. roaming should use this callback. More on world roaming will be
  62. added to this document when its support is enabled.
  63. Device drivers who provide their own built regulatory domain
  64. do not need a callback as the channels registered by them are
  65. the only ones that will be allowed and therefore *additional*
  66. channels cannot be enabled.
  67. Example code - drivers hinting an alpha2:
  68. ------------------------------------------
  69. This example comes from the zd1211rw device driver. You can start
  70. by having a mapping of your device's EEPROM country/regulatory
  71. domain value to a specific alpha2 as follows:
  72. static struct zd_reg_alpha2_map reg_alpha2_map[] = {
  73. { ZD_REGDOMAIN_FCC, "US" },
  74. { ZD_REGDOMAIN_IC, "CA" },
  75. { ZD_REGDOMAIN_ETSI, "DE" }, /* Generic ETSI, use most restrictive */
  76. { ZD_REGDOMAIN_JAPAN, "JP" },
  77. { ZD_REGDOMAIN_JAPAN_ADD, "JP" },
  78. { ZD_REGDOMAIN_SPAIN, "ES" },
  79. { ZD_REGDOMAIN_FRANCE, "FR" },
  80. Then you can define a routine to map your read EEPROM value to an alpha2,
  81. as follows:
  82. static int zd_reg2alpha2(u8 regdomain, char *alpha2)
  83. {
  84. unsigned int i;
  85. struct zd_reg_alpha2_map *reg_map;
  86. for (i = 0; i < ARRAY_SIZE(reg_alpha2_map); i++) {
  87. reg_map = &reg_alpha2_map[i];
  88. if (regdomain == reg_map->reg) {
  89. alpha2[0] = reg_map->alpha2[0];
  90. alpha2[1] = reg_map->alpha2[1];
  91. return 0;
  92. }
  93. }
  94. return 1;
  95. }
  96. Lastly, you can then hint to the core of your discovered alpha2, if a match
  97. was found. You need to do this after you have registered your wiphy. You
  98. are expected to do this during initialization.
  99. r = zd_reg2alpha2(mac->regdomain, alpha2);
  100. if (!r)
  101. regulatory_hint(hw->wiphy, alpha2);
  102. Example code - drivers providing a built in regulatory domain:
  103. --------------------------------------------------------------
  104. [NOTE: This API is not currently available, it can be added when required]
  105. If you have regulatory information you can obtain from your
  106. driver and you *need* to use this we let you build a regulatory domain
  107. structure and pass it to the wireless core. To do this you should
  108. kmalloc() a structure big enough to hold your regulatory domain
  109. structure and you should then fill it with your data. Finally you simply
  110. call regulatory_hint() with the regulatory domain structure in it.
  111. Bellow is a simple example, with a regulatory domain cached using the stack.
  112. Your implementation may vary (read EEPROM cache instead, for example).
  113. Example cache of some regulatory domain
  114. struct ieee80211_regdomain mydriver_jp_regdom = {
  115. .n_reg_rules = 3,
  116. .alpha2 = "JP",
  117. //.alpha2 = "99", /* If I have no alpha2 to map it to */
  118. .reg_rules = {
  119. /* IEEE 802.11b/g, channels 1..14 */
  120. REG_RULE(2412-20, 2484+20, 40, 6, 20, 0),
  121. /* IEEE 802.11a, channels 34..48 */
  122. REG_RULE(5170-20, 5240+20, 40, 6, 20,
  123. NL80211_RRF_NO_IR),
  124. /* IEEE 802.11a, channels 52..64 */
  125. REG_RULE(5260-20, 5320+20, 40, 6, 20,
  126. NL80211_RRF_NO_IR|
  127. NL80211_RRF_DFS),
  128. }
  129. };
  130. Then in some part of your code after your wiphy has been registered:
  131. struct ieee80211_regdomain *rd;
  132. int size_of_regd;
  133. int num_rules = mydriver_jp_regdom.n_reg_rules;
  134. unsigned int i;
  135. size_of_regd = sizeof(struct ieee80211_regdomain) +
  136. (num_rules * sizeof(struct ieee80211_reg_rule));
  137. rd = kzalloc(size_of_regd, GFP_KERNEL);
  138. if (!rd)
  139. return -ENOMEM;
  140. memcpy(rd, &mydriver_jp_regdom, sizeof(struct ieee80211_regdomain));
  141. for (i=0; i < num_rules; i++)
  142. memcpy(&rd->reg_rules[i],
  143. &mydriver_jp_regdom.reg_rules[i],
  144. sizeof(struct ieee80211_reg_rule));
  145. regulatory_struct_hint(rd);
  146. Statically compiled regulatory database
  147. ---------------------------------------
  148. In most situations the userland solution using CRDA as described
  149. above is the preferred solution. However in some cases a set of
  150. rules built into the kernel itself may be desirable. To account
  151. for this situation, a configuration option has been provided
  152. (i.e. CONFIG_CFG80211_INTERNAL_REGDB). With this option enabled,
  153. the wireless database information contained in net/wireless/db.txt is
  154. used to generate a data structure encoded in net/wireless/regdb.c.
  155. That option also enables code in net/wireless/reg.c which queries
  156. the data in regdb.c as an alternative to using CRDA.
  157. The file net/wireless/db.txt should be kept up-to-date with the db.txt
  158. file available in the git repository here:
  159. git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-regdb.git
  160. Again, most users in most situations should be using the CRDA package
  161. provided with their distribution, and in most other situations users
  162. should be building and using CRDA on their own rather than using
  163. this option. If you are not absolutely sure that you should be using
  164. CONFIG_CFG80211_INTERNAL_REGDB then _DO_NOT_USE_IT_.