Fix a build dependency error
[platform/upstream/crda.git] / regdb.h
1 #ifndef REG_DB_H
2 #define REG_DB_H
3
4 #include <stdint.h>
5
6 /*
7  * WARNING: This file needs to be kept in sync with
8  *  - the parser (dbparse.py)
9  *  - the generator code (db2bin.py)
10  */
11
12 /* spells "RGDB" */
13 #define REGDB_MAGIC     0x52474442
14
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 /*
23  * The signature at the end of the file is an RSA-signed
24  * SHA-1 hash of the file.
25  */
26
27 /* db file starts with a struct regdb_file_header */
28
29 struct regdb_file_header {
30         /* must be REGDB_MAGIC */
31         uint32_t        magic;
32         /* must be REGDB_VERSION */
33         uint32_t        version;
34         /*
35          * Pointer (offset) into file where country list starts
36          * and number of countries. The country list is sorted
37          * alphabetically to allow binary searching (should it
38          * become really huge). Each country is described by a
39          * struct regdb_file_reg_country.
40          */
41         uint32_t        reg_country_ptr;
42         uint32_t        reg_country_num;
43         /* length (in bytes) of the signature at the end of the file */
44         uint32_t        signature_length;
45 };
46
47 struct regdb_file_freq_range {
48         uint32_t        start_freq,     /* in kHz */
49                 end_freq,       /* in kHz */
50                 max_bandwidth;  /* in kHz */
51 };
52
53 /*
54  * Values of zero mean "not applicable", i.e. the regulatory
55  * does not limit a certain value.
56  */
57 struct regdb_file_power_rule {
58         /* antenna gain is in mBi (100 * dBi) */
59         uint32_t        max_antenna_gain;
60         /* this is in mBm (100 * dBm) */
61         uint32_t        max_eirp;
62 };
63
64 /* must match <linux/nl80211.h> enum nl80211_reg_rule_flags */
65
66 enum reg_rule_flags {
67         RRF_NO_OFDM             = 1<<0, /* OFDM modulation not allowed */
68         RRF_NO_CCK              = 1<<1, /* CCK modulation not allowed */
69         RRF_NO_INDOOR           = 1<<2, /* indoor operation not allowed */
70         RRF_NO_OUTDOOR          = 1<<3, /* outdoor operation not allowed */
71         RRF_DFS                 = 1<<4, /* DFS support is required to be
72                                          * used */
73         RRF_PTP_ONLY            = 1<<5, /* this is only for Point To Point
74                                          * links */
75         RRF_PTMP_ONLY           = 1<<6, /* this is only for Point To Multi
76                                          * Point links */
77         RRF_PASSIVE_SCAN        = 1<<7, /* passive scan is required */
78         RRF_NO_IBSS             = 1<<8, /* IBSS is not allowed */
79 };
80
81 struct regdb_file_reg_rule {
82         /* pointers (offsets) into the file */
83         uint32_t        freq_range_ptr; /* pointer to a struct regdb_file_freq_range */
84         uint32_t        power_rule_ptr; /* pointer to a struct regdb_file_power_rule */
85         /* rule flags using enum reg_rule_flags */
86         uint32_t flags;
87 };
88
89 struct regdb_file_reg_rules_collection {
90         uint32_t        reg_rule_num;
91         /* pointers (offsets) into the file. There are reg_rule_num elements
92          * in the reg_rule_ptrs array pointing to struct
93          * regdb_file_reg_rule */
94         uint32_t        reg_rule_ptrs[];
95 };
96
97 struct regdb_file_reg_country {
98         uint8_t alpha2[2];
99         uint8_t PAD;
100         uint8_t creqs; /* first two bits define DFS region */
101         /* pointer (offset) into the file to a struct
102          * regdb_file_reg_rules_collection */
103         uint32_t        reg_collection_ptr;
104 };
105
106
107 /*
108  * Verify that no unexpected padding is added to structures
109  * for some reason.
110  */
111
112 #define ERROR_ON(cond) \
113         ((void)sizeof(char[1 - 2*!!(cond)]))
114
115 #define CHECK_STRUCT(name, size) \
116         ERROR_ON(sizeof(struct name) != size)
117
118 static inline void check_db_binary_structs(void)
119 {
120         CHECK_STRUCT(regdb_file_header, 20);
121         CHECK_STRUCT(regdb_file_freq_range, 12);
122         CHECK_STRUCT(regdb_file_power_rule, 8);
123         CHECK_STRUCT(regdb_file_reg_rule, 12);
124         CHECK_STRUCT(regdb_file_reg_rules_collection, 4);
125         CHECK_STRUCT(regdb_file_reg_country, 8);
126 }
127
128 #endif