blob: 53c143f5e770d3dacb649acbec621c63dd8b9a5a [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#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License version 2 as
12# published by the Free Software Foundation.
13#
14
15BEGIN {
16 active = 0
17 rules = 0;
18 print "/*"
19 print " * DO NOT EDIT -- file generated from data in db.txt"
20 print " */"
21 print ""
22 print "#include <linux/nl80211.h>"
23 print "#include <net/cfg80211.h>"
John W. Linville2ea6fb62010-07-20 12:29:14 -040024 print "#include \"regdb.h\""
John W. Linville3b377ea2009-12-18 17:59:01 -050025 print ""
26 regdb = "const struct ieee80211_regdomain *reg_regdb[] = {\n"
27}
28
29/^[ \t]*#/ {
John W. Linvillef83d6642009-12-25 16:35:43 -080030 # Ignore
John W. Linville3b377ea2009-12-18 17:59:01 -050031}
32
33!active && /^[ \t]*$/ {
John W. Linvillef83d6642009-12-25 16:35:43 -080034 # Ignore
John W. Linville3b377ea2009-12-18 17:59:01 -050035}
36
37!active && /country/ {
38 country=$2
39 sub(/:/, "", country)
40 printf "static const struct ieee80211_regdomain regdom_%s = {\n", country
41 printf "\t.alpha2 = \"%s\",\n", country
42 printf "\t.reg_rules = {\n"
43 active = 1
44 regdb = regdb "\t&regdom_" country ",\n"
45}
46
47active && /^[ \t]*\(/ {
48 start = $1
49 sub(/\(/, "", start)
50 end = $3
51 bw = $5
52 sub(/\),/, "", bw)
53 gain = $6
54 sub(/\(/, "", gain)
55 sub(/,/, "", gain)
56 power = $7
57 sub(/\)/, "", power)
58 sub(/,/, "", power)
59 # power might be in mW...
60 units = $8
61 sub(/\)/, "", units)
62 sub(/,/, "", units)
63 if (units == "mW") {
64 if (power == 100) {
65 power = 20
66 } else if (power == 200) {
67 power = 23
68 } else if (power == 500) {
69 power = 27
70 } else if (power == 1000) {
71 power = 30
72 } else {
73 print "Unknown power value in database!"
74 }
75 }
76 flagstr = ""
77 for (i=8; i<=NF; i++)
78 flagstr = flagstr $i
79 split(flagstr, flagarray, ",")
80 flags = ""
81 for (arg in flagarray) {
82 if (flagarray[arg] == "NO-OFDM") {
83 flags = flags "\n\t\t\tNL80211_RRF_NO_OFDM | "
84 } else if (flagarray[arg] == "NO-CCK") {
85 flags = flags "\n\t\t\tNL80211_RRF_NO_CCK | "
86 } else if (flagarray[arg] == "NO-INDOOR") {
87 flags = flags "\n\t\t\tNL80211_RRF_NO_INDOOR | "
88 } else if (flagarray[arg] == "NO-OUTDOOR") {
89 flags = flags "\n\t\t\tNL80211_RRF_NO_OUTDOOR | "
90 } else if (flagarray[arg] == "DFS") {
91 flags = flags "\n\t\t\tNL80211_RRF_DFS | "
92 } else if (flagarray[arg] == "PTP-ONLY") {
93 flags = flags "\n\t\t\tNL80211_RRF_PTP_ONLY | "
94 } else if (flagarray[arg] == "PTMP-ONLY") {
95 flags = flags "\n\t\t\tNL80211_RRF_PTMP_ONLY | "
96 } else if (flagarray[arg] == "PASSIVE-SCAN") {
97 flags = flags "\n\t\t\tNL80211_RRF_PASSIVE_SCAN | "
98 } else if (flagarray[arg] == "NO-IBSS") {
99 flags = flags "\n\t\t\tNL80211_RRF_NO_IBSS | "
100 }
101 }
102 flags = flags "0"
103 printf "\t\tREG_RULE(%d, %d, %d, %d, %d, %s),\n", start, end, bw, gain, power, flags
104 rules++
105}
106
107active && /^[ \t]*$/ {
108 active = 0
109 printf "\t},\n"
110 printf "\t.n_reg_rules = %d\n", rules
111 printf "};\n\n"
112 rules = 0;
113}
114
115END {
116 print regdb "};"
117 print ""
118 print "int reg_regdb_size = ARRAY_SIZE(reg_regdb);"
119}