resetting manifest requested domain to floor
[platform/upstream/crda.git] / reglib.h
1 #ifndef REG_LIB_H
2 #define REG_LIB_H
3
4 #include <stdlib.h>
5 #include <stdint.h>
6
7 /* Common regulatory structures, functions and helpers */
8
9 /* This matches the kernel's data structures */
10 struct ieee80211_freq_range {
11         uint32_t start_freq_khz;
12         uint32_t end_freq_khz;
13         uint32_t max_bandwidth_khz;
14 };
15
16 struct ieee80211_power_rule {
17         uint32_t max_antenna_gain;
18         uint32_t max_eirp;
19 };
20
21 struct ieee80211_reg_rule {
22         struct ieee80211_freq_range freq_range;
23         struct ieee80211_power_rule power_rule;
24         uint32_t flags;
25 };
26
27 struct ieee80211_regdomain {
28         uint32_t n_reg_rules;
29         char alpha2[2];
30         uint8_t dfs_region;
31         struct ieee80211_reg_rule reg_rules[];
32 };
33
34 static inline int is_world_regdom(const char *alpha2)
35 {
36         if (alpha2[0] == '0' && alpha2[1] == '0')
37                 return 1;
38         return 0;
39 }
40
41 static inline int isalpha_upper(char letter)
42 {
43         if (letter >= 'A' && letter <= 'Z')
44                 return 1;
45         return 0;
46 }
47
48 static inline int is_alpha2(const char *alpha2)
49 {
50         if (isalpha_upper(alpha2[0]) && isalpha_upper(alpha2[1]))
51                 return 1;
52         return 0;
53 }
54
55 static inline int is_valid_regdom(const char *alpha2)
56 {
57         if (!is_alpha2(alpha2) && !is_world_regdom(alpha2))
58                 return 0;
59
60         return 1;
61 }
62
63 static inline uint32_t max(uint32_t a, uint32_t b)
64 {
65         return (a > b) ? a : b;
66 }
67
68 static inline uint32_t min(uint32_t a, uint32_t b)
69 {
70         return (a > b) ? b : a;
71 }
72
73 void *crda_get_file_ptr(uint8_t *db, int dblen, int structlen, uint32_t ptr);
74 int crda_verify_db_signature(uint8_t *db, int dblen, int siglen);
75
76 struct ieee80211_regdomain *
77 reglib_get_rd_idx(unsigned int idx, const char *file);
78
79 #define reglib_for_each_country(__rd, __idx, __file)                    \
80         for (__rd = reglib_get_rd_idx(__idx, __file);           \
81              __rd != NULL;                                              \
82              __rd = reglib_get_rd_idx(__idx, __file),           \
83              __idx++)
84
85 struct ieee80211_regdomain *
86 reglib_get_rd_alpha2(const char *alpha2, const char *file);
87
88 /* reg helpers */
89 void print_regdom(struct ieee80211_regdomain *rd);
90
91 #endif