regdb.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #ifndef REG_DB_H
  2. #define REG_DB_H
  3. #include <stdint.h>
  4. /*
  5. * WARNING: This file needs to be kept in sync with
  6. * - the parser (dbparse.py)
  7. * - the generator code (db2bin.py)
  8. *
  9. * As it is only Linux is using these so we have a direct one to
  10. * one map for flags. Each respective OS flag is listed where
  11. * appropriate.
  12. */
  13. /* spells "RGDB" */
  14. #define REGDB_MAGIC 0x52474442
  15. /*
  16. * Only supported version now, start at arbitrary number
  17. * to have some more magic. We still consider this to be
  18. * "Version 1" of the file.
  19. */
  20. #define REGDB_VERSION 19
  21. /*
  22. * The signature at the end of the file is an RSA-signed
  23. * SHA-1 hash of the file.
  24. */
  25. /* db file starts with a struct regdb_file_header */
  26. struct regdb_file_header {
  27. /* must be REGDB_MAGIC */
  28. uint32_t magic;
  29. /* must be REGDB_VERSION */
  30. uint32_t version;
  31. /*
  32. * Pointer (offset) into file where country list starts
  33. * and number of countries. The country list is sorted
  34. * alphabetically to allow binary searching (should it
  35. * become really huge). Each country is described by a
  36. * struct regdb_file_reg_country.
  37. */
  38. uint32_t reg_country_ptr;
  39. uint32_t reg_country_num;
  40. /* length (in bytes) of the signature at the end of the file */
  41. uint32_t signature_length;
  42. };
  43. struct regdb_file_freq_range {
  44. uint32_t start_freq, /* in kHz */
  45. end_freq, /* in kHz */
  46. max_bandwidth; /* in kHz */
  47. };
  48. /*
  49. * Values of zero mean "not applicable", i.e. the regulatory
  50. * does not limit a certain value.
  51. */
  52. struct regdb_file_power_rule {
  53. /* antenna gain is in mBi (100 * dBi) */
  54. uint32_t max_antenna_gain;
  55. /* this is in mBm (100 * dBm) */
  56. uint32_t max_eirp;
  57. };
  58. /*
  59. * The Linux map defined in <linux/uapi/nl80211.h> enum nl80211_reg_rule_flags
  60. */
  61. enum reg_rule_flags {
  62. RRF_NO_OFDM = 1<<0, /* OFDM modulation not allowed */
  63. RRF_NO_CCK = 1<<1, /* CCK modulation not allowed */
  64. RRF_NO_INDOOR = 1<<2, /* indoor operation not allowed */
  65. RRF_NO_OUTDOOR = 1<<3, /* outdoor operation not allowed */
  66. RRF_DFS = 1<<4, /* DFS support is required to be
  67. * used */
  68. RRF_PTP_ONLY = 1<<5, /* this is only for Point To Point
  69. * links */
  70. RRF_PTMP_ONLY = 1<<6, /* this is only for Point To Multi
  71. * Point links */
  72. RRF_NO_IR = 1<<7, /* do not initiate radiation */
  73. __RRF_NO_IBSS = 1<<8, /* old no-IBSS rule, maps to no-ir */
  74. RRF_AUTO_BW = 1<<11, /* Auto BW calculations */
  75. };
  76. #define RRF_NO_IR_ALL (RRF_NO_IR | __RRF_NO_IBSS)
  77. /**
  78. * enum regdb_dfs_regions - regulatory DFS regions
  79. *
  80. * @REGDB_DFS_UNSET: Country has no DFS master region specified
  81. * @REGDB_DFS_FCC: Country follows DFS master rules from FCC
  82. * @REGDB_DFS_ETSI: Country follows DFS master rules from ETSI
  83. * @REGDB_DFS_JP: Country follows DFS master rules from JP/MKK/Telec
  84. */
  85. enum regdb_dfs_regions {
  86. REGDB_DFS_UNSET = 0,
  87. REGDB_DFS_FCC = 1,
  88. REGDB_DFS_ETSI = 2,
  89. REGDB_DFS_JP = 3,
  90. };
  91. struct regdb_file_reg_rule {
  92. /* pointers (offsets) into the file */
  93. uint32_t freq_range_ptr; /* pointer to a struct regdb_file_freq_range */
  94. uint32_t power_rule_ptr; /* pointer to a struct regdb_file_power_rule */
  95. /* rule flags using enum reg_rule_flags */
  96. uint32_t flags;
  97. };
  98. struct regdb_file_reg_rules_collection {
  99. uint32_t reg_rule_num;
  100. /* pointers (offsets) into the file. There are reg_rule_num elements
  101. * in the reg_rule_ptrs array pointing to struct
  102. * regdb_file_reg_rule */
  103. uint32_t reg_rule_ptrs[];
  104. };
  105. struct regdb_file_reg_country {
  106. uint8_t alpha2[2];
  107. uint8_t PAD;
  108. uint8_t creqs; /* first two bits define DFS region */
  109. /* pointer (offset) into the file to a struct
  110. * regdb_file_reg_rules_collection */
  111. uint32_t reg_collection_ptr;
  112. };
  113. /*
  114. * Verify that no unexpected padding is added to structures
  115. * for some reason.
  116. */
  117. #define ERROR_ON(cond) \
  118. ((void)sizeof(char[1 - 2*!!(cond)]))
  119. #define CHECK_STRUCT(name, size) \
  120. ERROR_ON(sizeof(struct name) != size)
  121. static inline void check_db_binary_structs(void)
  122. {
  123. CHECK_STRUCT(regdb_file_header, 20);
  124. CHECK_STRUCT(regdb_file_freq_range, 12);
  125. CHECK_STRUCT(regdb_file_power_rule, 8);
  126. CHECK_STRUCT(regdb_file_reg_rule, 12);
  127. CHECK_STRUCT(regdb_file_reg_rules_collection, 4);
  128. CHECK_STRUCT(regdb_file_reg_country, 8);
  129. }
  130. #endif