regulatory.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef __NET_REGULATORY_H
  2. #define __NET_REGULATORY_H
  3. /*
  4. * regulatory support structures
  5. *
  6. * Copyright 2008-2009 Luis R. Rodriguez <lrodriguez@atheros.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. /**
  13. * enum environment_cap - Environment parsed from country IE
  14. * @ENVIRON_ANY: indicates country IE applies to both indoor and
  15. * outdoor operation.
  16. * @ENVIRON_INDOOR: indicates country IE applies only to indoor operation
  17. * @ENVIRON_OUTDOOR: indicates country IE applies only to outdoor operation
  18. */
  19. enum environment_cap {
  20. ENVIRON_ANY,
  21. ENVIRON_INDOOR,
  22. ENVIRON_OUTDOOR,
  23. };
  24. /**
  25. * struct regulatory_request - used to keep track of regulatory requests
  26. *
  27. * @wiphy_idx: this is set if this request's initiator is
  28. * %REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This
  29. * can be used by the wireless core to deal with conflicts
  30. * and potentially inform users of which devices specifically
  31. * cased the conflicts.
  32. * @initiator: indicates who sent this request, could be any of
  33. * of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*)
  34. * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
  35. * regulatory domain. We have a few special codes:
  36. * 00 - World regulatory domain
  37. * 99 - built by driver but a specific alpha2 cannot be determined
  38. * 98 - result of an intersection between two regulatory domains
  39. * 97 - regulatory domain has not yet been configured
  40. * @intersect: indicates whether the wireless core should intersect
  41. * the requested regulatory domain with the presently set regulatory
  42. * domain.
  43. * @processed: indicates whether or not this requests has already been
  44. * processed. When the last request is processed it means that the
  45. * currently regulatory domain set on cfg80211 is updated from
  46. * CRDA and can be used by other regulatory requests. When a
  47. * the last request is not yet processed we must yield until it
  48. * is processed before processing any new requests.
  49. * @country_ie_checksum: checksum of the last processed and accepted
  50. * country IE
  51. * @country_ie_env: lets us know if the AP is telling us we are outdoor,
  52. * indoor, or if it doesn't matter
  53. * @list: used to insert into the reg_requests_list linked list
  54. */
  55. struct regulatory_request {
  56. int wiphy_idx;
  57. enum nl80211_reg_initiator initiator;
  58. char alpha2[2];
  59. bool intersect;
  60. bool processed;
  61. enum environment_cap country_ie_env;
  62. struct list_head list;
  63. };
  64. struct ieee80211_freq_range {
  65. u32 start_freq_khz;
  66. u32 end_freq_khz;
  67. u32 max_bandwidth_khz;
  68. };
  69. struct ieee80211_power_rule {
  70. u32 max_antenna_gain;
  71. u32 max_eirp;
  72. };
  73. struct ieee80211_reg_rule {
  74. struct ieee80211_freq_range freq_range;
  75. struct ieee80211_power_rule power_rule;
  76. u32 flags;
  77. };
  78. struct ieee80211_regdomain {
  79. u32 n_reg_rules;
  80. char alpha2[2];
  81. struct ieee80211_reg_rule reg_rules[];
  82. };
  83. #define MHZ_TO_KHZ(freq) ((freq) * 1000)
  84. #define KHZ_TO_MHZ(freq) ((freq) / 1000)
  85. #define DBI_TO_MBI(gain) ((gain) * 100)
  86. #define MBI_TO_DBI(gain) ((gain) / 100)
  87. #define DBM_TO_MBM(gain) ((gain) * 100)
  88. #define MBM_TO_DBM(gain) ((gain) / 100)
  89. #define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
  90. { \
  91. .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
  92. .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
  93. .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
  94. .power_rule.max_antenna_gain = DBI_TO_MBI(gain),\
  95. .power_rule.max_eirp = DBM_TO_MBM(eirp), \
  96. .flags = reg_flags, \
  97. }
  98. #endif