blob: 9a8217d2a90882f872451833cabe30159a64953f [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{
John W. Linville3b377ea2009-12-18 17:59:01 -050054 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 if (units == "mW") {
70 if (power == 100) {
71 power = 20
72 } else if (power == 200) {
73 power = 23
74 } else if (power == 500) {
75 power = 27
76 } else if (power == 1000) {
77 power = 30
78 } else {
79 print "Unknown power value in database!"
80 }
81 }
82 flagstr = ""
83 for (i=8; i<=NF; i++)
84 flagstr = flagstr $i
85 split(flagstr, flagarray, ",")
86 flags = ""
87 for (arg in flagarray) {
88 if (flagarray[arg] == "NO-OFDM") {
89 flags = flags "\n\t\t\tNL80211_RRF_NO_OFDM | "
90 } else if (flagarray[arg] == "NO-CCK") {
91 flags = flags "\n\t\t\tNL80211_RRF_NO_CCK | "
92 } else if (flagarray[arg] == "NO-INDOOR") {
93 flags = flags "\n\t\t\tNL80211_RRF_NO_INDOOR | "
94 } else if (flagarray[arg] == "NO-OUTDOOR") {
95 flags = flags "\n\t\t\tNL80211_RRF_NO_OUTDOOR | "
96 } else if (flagarray[arg] == "DFS") {
97 flags = flags "\n\t\t\tNL80211_RRF_DFS | "
98 } else if (flagarray[arg] == "PTP-ONLY") {
99 flags = flags "\n\t\t\tNL80211_RRF_PTP_ONLY | "
100 } else if (flagarray[arg] == "PTMP-ONLY") {
101 flags = flags "\n\t\t\tNL80211_RRF_PTMP_ONLY | "
102 } else if (flagarray[arg] == "PASSIVE-SCAN") {
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200103 flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
John W. Linville3b377ea2009-12-18 17:59:01 -0500104 } else if (flagarray[arg] == "NO-IBSS") {
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200105 flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
106 } else if (flagarray[arg] == "NO-IR") {
107 flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
John W. Linville3b377ea2009-12-18 17:59:01 -0500108 }
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200109
John W. Linville3b377ea2009-12-18 17:59:01 -0500110 }
111 flags = flags "0"
112 printf "\t\tREG_RULE(%d, %d, %d, %d, %d, %s),\n", start, end, bw, gain, power, flags
113 rules++
114}
115
Luis R. Rodriguezaf9b2232013-10-28 03:19:45 +0100116function print_tail_country()
117{
John W. Linville3b377ea2009-12-18 17:59:01 -0500118 active = 0
119 printf "\t},\n"
120 printf "\t.n_reg_rules = %d\n", rules
121 printf "};\n\n"
122 rules = 0;
123}
124
Luis R. Rodriguezaf9b2232013-10-28 03:19:45 +0100125/^[ \t]*#/ {
126 # Ignore
127}
128
129!active && /^[ \t]*$/ {
130 # Ignore
131}
132
133!active && /country/ {
134 parse_country_head()
135}
136
137active && /^[ \t]*\(/ {
138 parse_reg_rule()
139}
140
141active && /^[ \t]*$/ {
142 print_tail_country()
143}
144
John W. Linville3b377ea2009-12-18 17:59:01 -0500145END {
Luis R. Rodriguezae689392013-10-28 03:19:46 +0100146 if (active)
147 print_tail_country()
John W. Linville3b377ea2009-12-18 17:59:01 -0500148 print regdb "};"
149 print ""
150 print "int reg_regdb_size = ARRAY_SIZE(reg_regdb);"
151}