Add conversion utitlies, standardize printing
[platform/upstream/crda.git] / regdb.h
1 #ifndef REG_DB_H
2 #define REG_DB_H
3
4 #include <linux/types.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         __be32  magic;
32         /* must be REGDB_VERSION */
33         __be32  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         __be32  reg_country_ptr;
42         __be32  reg_country_num;
43         /* length (in bytes) of the signature at the end of the file */
44         __be32  signature_length;
45 };
46
47 struct regdb_file_freq_range {
48         __be32  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         __be32  max_antenna_gain;
60         /* this is in mBm (100 * dBm) */
61         __be32  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         __be32  freq_range_ptr; /* pointer to a struct regdb_file_freq_range */
84         __be32  power_rule_ptr; /* pointer to a struct regdb_file_power_rule */
85         /* rule flags using enum reg_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. There are reg_rule_num elements
92          * in the reg_rule_ptrs array pointing to struct
93          * regdb_file_reg_rule */
94         __be32  reg_rule_ptrs[];
95 };
96
97 struct regdb_file_reg_country {
98         __u8    alpha2[2];
99         __u8    PAD[2];
100         /* pointer (offset) into the file to a struct
101          * regdb_file_reg_rules_collection */
102         __be32  reg_collection_ptr;
103 };
104
105
106 /*
107  * Verify that no unexpected padding is added to structures
108  * for some reason.
109  */
110
111 #define ERROR_ON(cond) \
112         ((void)sizeof(char[1 - 2*!!(cond)]))
113
114 #define CHECK_STRUCT(name, size) \
115         ERROR_ON(sizeof(struct name) != size)
116
117 static inline void check_db_binary_structs(void)
118 {
119         CHECK_STRUCT(regdb_file_header, 20);
120         CHECK_STRUCT(regdb_file_freq_range, 12);
121         CHECK_STRUCT(regdb_file_power_rule, 8);
122         CHECK_STRUCT(regdb_file_reg_rule, 12);
123         CHECK_STRUCT(regdb_file_reg_rules_collection, 4);
124         CHECK_STRUCT(regdb_file_reg_country, 8);
125 }
126
127 #endif