regulatory.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef __NET_REGULATORY_H
  2. #define __NET_REGULATORY_H
  3. /*
  4. * regulatory support structures
  5. *
  6. * Copyright 2008-2009 Luis R. Rodriguez <mcgrof@qca.qualcomm.com>
  7. *
  8. * Permission to use, copy, modify, and/or distribute this software for any
  9. * purpose with or without fee is hereby granted, provided that the above
  10. * copyright notice and this permission notice appear in all copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  13. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  15. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  16. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  17. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  18. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19. */
  20. /**
  21. * enum environment_cap - Environment parsed from country IE
  22. * @ENVIRON_ANY: indicates country IE applies to both indoor and
  23. * outdoor operation.
  24. * @ENVIRON_INDOOR: indicates country IE applies only to indoor operation
  25. * @ENVIRON_OUTDOOR: indicates country IE applies only to outdoor operation
  26. */
  27. enum environment_cap {
  28. ENVIRON_ANY,
  29. ENVIRON_INDOOR,
  30. ENVIRON_OUTDOOR,
  31. };
  32. /**
  33. * struct regulatory_request - used to keep track of regulatory requests
  34. *
  35. * @wiphy_idx: this is set if this request's initiator is
  36. * %REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This
  37. * can be used by the wireless core to deal with conflicts
  38. * and potentially inform users of which devices specifically
  39. * cased the conflicts.
  40. * @initiator: indicates who sent this request, could be any of
  41. * of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*)
  42. * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
  43. * regulatory domain. We have a few special codes:
  44. * 00 - World regulatory domain
  45. * 99 - built by driver but a specific alpha2 cannot be determined
  46. * 98 - result of an intersection between two regulatory domains
  47. * 97 - regulatory domain has not yet been configured
  48. * @intersect: indicates whether the wireless core should intersect
  49. * the requested regulatory domain with the presently set regulatory
  50. * domain.
  51. * @processed: indicates whether or not this requests has already been
  52. * processed. When the last request is processed it means that the
  53. * currently regulatory domain set on cfg80211 is updated from
  54. * CRDA and can be used by other regulatory requests. When a
  55. * the last request is not yet processed we must yield until it
  56. * is processed before processing any new requests.
  57. * @country_ie_checksum: checksum of the last processed and accepted
  58. * country IE
  59. * @country_ie_env: lets us know if the AP is telling us we are outdoor,
  60. * indoor, or if it doesn't matter
  61. * @list: used to insert into the reg_requests_list linked list
  62. */
  63. struct regulatory_request {
  64. int wiphy_idx;
  65. enum nl80211_reg_initiator initiator;
  66. char alpha2[2];
  67. bool intersect;
  68. bool processed;
  69. enum environment_cap country_ie_env;
  70. struct list_head list;
  71. };
  72. struct ieee80211_freq_range {
  73. u32 start_freq_khz;
  74. u32 end_freq_khz;
  75. u32 max_bandwidth_khz;
  76. };
  77. struct ieee80211_power_rule {
  78. u32 max_antenna_gain;
  79. u32 max_eirp;
  80. };
  81. struct ieee80211_reg_rule {
  82. struct ieee80211_freq_range freq_range;
  83. struct ieee80211_power_rule power_rule;
  84. u32 flags;
  85. };
  86. struct ieee80211_regdomain {
  87. u32 n_reg_rules;
  88. char alpha2[2];
  89. struct ieee80211_reg_rule reg_rules[];
  90. };
  91. #define MHZ_TO_KHZ(freq) ((freq) * 1000)
  92. #define KHZ_TO_MHZ(freq) ((freq) / 1000)
  93. #define DBI_TO_MBI(gain) ((gain) * 100)
  94. #define MBI_TO_DBI(gain) ((gain) / 100)
  95. #define DBM_TO_MBM(gain) ((gain) * 100)
  96. #define MBM_TO_DBM(gain) ((gain) / 100)
  97. #define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
  98. { \
  99. .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
  100. .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
  101. .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
  102. .power_rule.max_antenna_gain = DBI_TO_MBI(gain),\
  103. .power_rule.max_eirp = DBM_TO_MBM(eirp), \
  104. .flags = reg_flags, \
  105. }
  106. #endif