]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - net/wireless/genregdb.awk
cfg80211: regulatory: allow getting DFS CAC time from userspace
[mirror_ubuntu-bionic-kernel.git] / net / wireless / genregdb.awk
1 #!/usr/bin/awk -f
2 #
3 # genregdb.awk -- generate regdb.c from db.txt
4 #
5 # Actually, it reads from stdin (presumed to be db.txt) and writes
6 # to stdout (presumed to be regdb.c), but close enough...
7 #
8 # Copyright 2009 John W. Linville <linville@tuxdriver.com>
9 #
10 # Permission to use, copy, modify, and/or distribute this software for any
11 # purpose with or without fee is hereby granted, provided that the above
12 # copyright notice and this permission notice appear in all copies.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21
22 BEGIN {
23 active = 0
24 rules = 0;
25 print "/*"
26 print " * DO NOT EDIT -- file generated from data in db.txt"
27 print " */"
28 print ""
29 print "#include <linux/nl80211.h>"
30 print "#include <net/cfg80211.h>"
31 print "#include \"regdb.h\""
32 print ""
33 regdb = "const struct ieee80211_regdomain *reg_regdb[] = {\n"
34 }
35
36 function parse_country_head() {
37 country=$2
38 sub(/:/, "", country)
39 printf "static const struct ieee80211_regdomain regdom_%s = {\n", country
40 printf "\t.alpha2 = \"%s\",\n", country
41 if ($NF ~ /DFS-ETSI/)
42 printf "\t.dfs_region = NL80211_DFS_ETSI,\n"
43 else if ($NF ~ /DFS-FCC/)
44 printf "\t.dfs_region = NL80211_DFS_FCC,\n"
45 else if ($NF ~ /DFS-JP/)
46 printf "\t.dfs_region = NL80211_DFS_JP,\n"
47 printf "\t.reg_rules = {\n"
48 active = 1
49 regdb = regdb "\t&regdom_" country ",\n"
50 }
51
52 function parse_reg_rule()
53 {
54 start = $1
55 sub(/\(/, "", start)
56 end = $3
57 bw = $5
58 sub(/\),/, "", bw)
59 gain = $6
60 sub(/\(/, "", gain)
61 sub(/,/, "", gain)
62 power = $7
63 sub(/\)/, "", power)
64 sub(/,/, "", power)
65 # power might be in mW...
66 units = $8
67 sub(/\)/, "", units)
68 sub(/,/, "", units)
69 dfs_cac = $9
70 if (units == "mW") {
71 if (power == 100) {
72 power = 20
73 } else if (power == 200) {
74 power = 23
75 } else if (power == 500) {
76 power = 27
77 } else if (power == 1000) {
78 power = 30
79 } else {
80 print "Unknown power value in database!"
81 }
82 } else {
83 dfs_cac = $8
84 }
85 sub(/,/, "", dfs_cac)
86 sub(/\(/, "", dfs_cac)
87 sub(/\)/, "", dfs_cac)
88 flagstr = ""
89 for (i=8; i<=NF; i++)
90 flagstr = flagstr $i
91 split(flagstr, flagarray, ",")
92 flags = ""
93 for (arg in flagarray) {
94 if (flagarray[arg] == "NO-OFDM") {
95 flags = flags "\n\t\t\tNL80211_RRF_NO_OFDM | "
96 } else if (flagarray[arg] == "NO-CCK") {
97 flags = flags "\n\t\t\tNL80211_RRF_NO_CCK | "
98 } else if (flagarray[arg] == "NO-INDOOR") {
99 flags = flags "\n\t\t\tNL80211_RRF_NO_INDOOR | "
100 } else if (flagarray[arg] == "NO-OUTDOOR") {
101 flags = flags "\n\t\t\tNL80211_RRF_NO_OUTDOOR | "
102 } else if (flagarray[arg] == "DFS") {
103 flags = flags "\n\t\t\tNL80211_RRF_DFS | "
104 } else if (flagarray[arg] == "PTP-ONLY") {
105 flags = flags "\n\t\t\tNL80211_RRF_PTP_ONLY | "
106 } else if (flagarray[arg] == "PTMP-ONLY") {
107 flags = flags "\n\t\t\tNL80211_RRF_PTMP_ONLY | "
108 } else if (flagarray[arg] == "PASSIVE-SCAN") {
109 flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
110 } else if (flagarray[arg] == "NO-IBSS") {
111 flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
112 } else if (flagarray[arg] == "NO-IR") {
113 flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
114 } else if (flagarray[arg] == "AUTO-BW") {
115 flags = flags "\n\t\t\tNL80211_RRF_AUTO_BW | "
116 }
117
118 }
119 flags = flags "0"
120 printf "\t\tREG_RULE_EXT(%d, %d, %d, %d, %d, %d, %s),\n", start, end, bw, gain, power, dfs_cac, flags
121 rules++
122 }
123
124 function print_tail_country()
125 {
126 active = 0
127 printf "\t},\n"
128 printf "\t.n_reg_rules = %d\n", rules
129 printf "};\n\n"
130 rules = 0;
131 }
132
133 /^[ \t]*#/ {
134 # Ignore
135 }
136
137 !active && /^[ \t]*$/ {
138 # Ignore
139 }
140
141 !active && /country/ {
142 parse_country_head()
143 }
144
145 active && /^[ \t]*\(/ {
146 parse_reg_rule()
147 }
148
149 active && /^[ \t]*$/ {
150 print_tail_country()
151 }
152
153 END {
154 if (active)
155 print_tail_country()
156 print regdb "};"
157 print ""
158 print "int reg_regdb_size = ARRAY_SIZE(reg_regdb);"
159 }