Import a suggested guide for regulatory db.txt.
[platform/upstream/crda.git] / regdb.h
1 #include <linux/types.h>
2
3 /*
4  * WARNING: This file needs to be kept in sync with
5  *  - the parser (dbparse.py)
6  *  - the generator code (db2bin.py)
7  */
8
9 /* spells "RGDB" */
10 #define REGDB_MAGIC     0x52474442
11
12 /*
13  * Only supported version now, start at arbitrary number
14  * to have some more magic. We still consider this to be
15  * "Version 1" of the file.
16  */
17 #define REGDB_VERSION   19
18
19 /*
20  * The signature at the end of the file is an RSA-signed
21  * SHA-1 hash of the file.
22  */
23
24 struct regdb_file_header {
25         /* must be REGDB_MAGIC */
26         __be32  magic;
27         /* must be REGDB_VERSION */
28         __be32  version;
29         /*
30          * Pointer (offset) into file where country list starts
31          * and number of countries. The country list is sorted
32          * alphabetically to allow binary searching (should it
33          * become really huge.)
34          */
35         __be32  reg_country_ptr;
36         __be32  reg_country_num;
37         /* length (in bytes) of the signature at the end of the file */
38         __be32  signature_length;
39 };
40
41 struct regdb_file_freq_range {
42         __be32  start_freq,
43                 end_freq,
44                 max_bandwidth;
45 };
46
47 /*
48  * Values of zero mean "not applicable", i.e. the regulatory
49  * does not limit a certain value.
50  */
51 struct regdb_file_power_rule {
52         /* antenna gain is in mBi (100 * dBi) */
53         __be32  max_antenna_gain;
54         /* this is in mBm (100 * dBm) */
55         __be32  max_eirp;
56 };
57
58 #define EDGE_POWER_SHIFT        11
59
60 enum reg_rule_flags {
61         RRF_NO_OFDM             = 1<<0,
62         RRF_NO_CCK              = 1<<1,
63         RRF_NO_INDOOR           = 1<<2,
64         RRF_NO_OUTDOOR          = 1<<3,
65         RRF_DFS                 = 1<<4,
66         RRF_PTP_ONLY            = 1<<5,
67         RRF_PTMP_ONLY           = 1<<6,
68         RRF_PASSIVE_SCAN        = 1<<7,
69         RRF_NO_IBSS             = 1<<8,
70         /* hole at 9 */
71         RRF_NO_HT40             = 1<<10,
72         RRF_EDGE_POWER_MASK     = 3<<EDGE_POWER_SHIFT,
73 };
74
75 /* TODO: flesh out what these mean! */
76 #define EDGE_POWER_NO   0
77 #define EDGE_POWER_1    1
78 #define EDGE_POWER_2    2
79 #define EDGE_POWER_3    3
80
81 struct regdb_file_reg_rule {
82         /* pointers (offsets) into the file */
83         __be32  freq_range_ptr,
84                 power_rule_ptr;
85         /* rule flags */
86         __be32 flags;
87 };
88
89 struct regdb_file_reg_rules_collection {
90         __be32  reg_rule_num;
91         /* pointers (offsets) into the file */
92         __be32  reg_rule_ptrs[];
93 };
94
95 struct regdb_file_reg_country {
96         __u8    alpha2[2];
97         __u8    PAD[2];
98         /* pointer (offset) into the file */
99         __be32  reg_collection_ptr;
100 };
101
102
103 /*
104  * Verify that no unexpected padding is added to structures
105  * for some reason.
106  */
107
108 #define ERROR_ON(cond) \
109         ((void)sizeof(char[1 - 2*!!(cond)]))
110
111 #define CHECK_STRUCT(name, size) \
112         ERROR_ON(sizeof(struct name) != size)
113
114 static inline void check_db_binary_structs(void)
115 {
116         CHECK_STRUCT(regdb_file_header, 20);
117         CHECK_STRUCT(regdb_file_freq_range, 12);
118         CHECK_STRUCT(regdb_file_power_rule, 8);
119         CHECK_STRUCT(regdb_file_reg_rule, 12);
120         CHECK_STRUCT(regdb_file_reg_rules_collection, 4);
121         CHECK_STRUCT(regdb_file_reg_country, 8);
122 }