blob: baf2426b555a31c7aeb2fbaa48205c9b422f0cbf [file] [log] [blame]
John W. Linville3b377ea2009-12-18 17:59:01 -05001#!/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#
Luis R. Rodriguez3b77d5e2011-12-20 12:23:38 -080010# 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.
John W. Linville3b377ea2009-12-18 17:59:01 -050013#
Luis R. Rodriguez3b77d5e2011-12-20 12:23:38 -080014# 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.
John W. Linville3b377ea2009-12-18 17:59:01 -050021
22BEGIN {
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>"
John W. Linville2ea6fb62010-07-20 12:29:14 -040031 print "#include \"regdb.h\""
John W. Linville3b377ea2009-12-18 17:59:01 -050032 print ""
33 regdb = "const struct ieee80211_regdomain *reg_regdb[] = {\n"
34}
35
Luis R. Rodriguezaf9b2232013-10-28 03:19:45 +010036function parse_country_head() {
John W. Linville3b377ea2009-12-18 17:59:01 -050037 country=$2
38 sub(/:/, "", country)
39 printf "static const struct ieee80211_regdomain regdom_%s = {\n", country
40 printf "\t.alpha2 = \"%s\",\n", country
Janusz Dziedzicf08234752013-09-17 08:25:36 +020041 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"
John W. Linville3b377ea2009-12-18 17:59:01 -050047 printf "\t.reg_rules = {\n"
48 active = 1
49 regdb = regdb "\t&regdom_" country ",\n"
50}
51
Luis R. Rodriguezaf9b2232013-10-28 03:19:45 +010052function parse_reg_rule()
53{
Luis R. Rodriguezfa96aab2014-07-14 14:19:49 -070054 flag_starts_at = 7
55
John W. Linville3b377ea2009-12-18 17:59:01 -050056 start = $1
57 sub(/\(/, "", start)
58 end = $3
59 bw = $5
60 sub(/\),/, "", bw)
Luis R. Rodriguezfa96aab2014-07-14 14:19:49 -070061 gain = 0
62 power = $6
John W. Linville3b377ea2009-12-18 17:59:01 -050063 # power might be in mW...
Luis R. Rodriguezfa96aab2014-07-14 14:19:49 -070064 units = $7
65 dfs_cac = 0
66
67 sub(/\(/, "", power)
68 sub(/\),/, "", power)
69 sub(/\),/, "", units)
John W. Linville3b377ea2009-12-18 17:59:01 -050070 sub(/\)/, "", units)
Luis R. Rodriguezfa96aab2014-07-14 14:19:49 -070071
John W. Linville3b377ea2009-12-18 17:59:01 -050072 if (units == "mW") {
Luis R. Rodriguezfa96aab2014-07-14 14:19:49 -070073 flag_starts_at = 8
chaitanya.mgit@gmail.coma9fb5412014-05-26 18:01:44 +053074 power = 10 * log(power)/log(10)
Luis R. Rodriguezfa96aab2014-07-14 14:19:49 -070075 if ($8 ~ /[[:digit:]]/) {
76 flag_starts_at = 9
77 dfs_cac = $8
78 }
Janusz Dziedzic089027e2014-02-21 19:46:12 +010079 } else {
Luis R. Rodriguezfa96aab2014-07-14 14:19:49 -070080 if ($7 ~ /[[:digit:]]/) {
81 flag_starts_at = 8
82 dfs_cac = $7
83 }
John W. Linville3b377ea2009-12-18 17:59:01 -050084 }
Janusz Dziedzic089027e2014-02-21 19:46:12 +010085 sub(/\(/, "", dfs_cac)
Luis R. Rodriguezfa96aab2014-07-14 14:19:49 -070086 sub(/\),/, "", dfs_cac)
John W. Linville3b377ea2009-12-18 17:59:01 -050087 flagstr = ""
Luis R. Rodriguezfa96aab2014-07-14 14:19:49 -070088 for (i=flag_starts_at; i<=NF; i++)
John W. Linville3b377ea2009-12-18 17:59:01 -050089 flagstr = flagstr $i
90 split(flagstr, flagarray, ",")
91 flags = ""
92 for (arg in flagarray) {
93 if (flagarray[arg] == "NO-OFDM") {
94 flags = flags "\n\t\t\tNL80211_RRF_NO_OFDM | "
95 } else if (flagarray[arg] == "NO-CCK") {
96 flags = flags "\n\t\t\tNL80211_RRF_NO_CCK | "
97 } else if (flagarray[arg] == "NO-INDOOR") {
98 flags = flags "\n\t\t\tNL80211_RRF_NO_INDOOR | "
99 } else if (flagarray[arg] == "NO-OUTDOOR") {
100 flags = flags "\n\t\t\tNL80211_RRF_NO_OUTDOOR | "
101 } else if (flagarray[arg] == "DFS") {
102 flags = flags "\n\t\t\tNL80211_RRF_DFS | "
103 } else if (flagarray[arg] == "PTP-ONLY") {
104 flags = flags "\n\t\t\tNL80211_RRF_PTP_ONLY | "
105 } else if (flagarray[arg] == "PTMP-ONLY") {
106 flags = flags "\n\t\t\tNL80211_RRF_PTMP_ONLY | "
107 } else if (flagarray[arg] == "PASSIVE-SCAN") {
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200108 flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
John W. Linville3b377ea2009-12-18 17:59:01 -0500109 } else if (flagarray[arg] == "NO-IBSS") {
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200110 flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
111 } else if (flagarray[arg] == "NO-IR") {
112 flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +0100113 } else if (flagarray[arg] == "AUTO-BW") {
114 flags = flags "\n\t\t\tNL80211_RRF_AUTO_BW | "
John W. Linville3b377ea2009-12-18 17:59:01 -0500115 }
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200116
John W. Linville3b377ea2009-12-18 17:59:01 -0500117 }
118 flags = flags "0"
chaitanya.mgit@gmail.coma9fb5412014-05-26 18:01:44 +0530119 printf "\t\tREG_RULE_EXT(%d, %d, %d, %d, %.0f, %d, %s),\n", start, end, bw, gain, power, dfs_cac, flags
John W. Linville3b377ea2009-12-18 17:59:01 -0500120 rules++
121}
122
Luis R. Rodriguezaf9b2232013-10-28 03:19:45 +0100123function print_tail_country()
124{
John W. Linville3b377ea2009-12-18 17:59:01 -0500125 active = 0
126 printf "\t},\n"
127 printf "\t.n_reg_rules = %d\n", rules
128 printf "};\n\n"
129 rules = 0;
130}
131
Luis R. Rodriguezaf9b2232013-10-28 03:19:45 +0100132/^[ \t]*#/ {
133 # Ignore
134}
135
136!active && /^[ \t]*$/ {
137 # Ignore
138}
139
140!active && /country/ {
141 parse_country_head()
142}
143
144active && /^[ \t]*\(/ {
145 parse_reg_rule()
146}
147
148active && /^[ \t]*$/ {
149 print_tail_country()
150}
151
John W. Linville3b377ea2009-12-18 17:59:01 -0500152END {
Luis R. Rodriguezae689392013-10-28 03:19:46 +0100153 if (active)
154 print_tail_country()
John W. Linville3b377ea2009-12-18 17:59:01 -0500155 print regdb "};"
156 print ""
157 print "int reg_regdb_size = ARRAY_SIZE(reg_regdb);"
158}