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 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>" 31 print "#include \"regdb.h\"" 32 print "" 33 regdb = "const struct ieee80211_regdomain *reg_regdb[] = {\n" 34} 35 36/^[ \t]*#/ { 37 # Ignore 38} 39 40!active && /^[ \t]*$/ { 41 # Ignore 42} 43 44!active && /country/ { 45 country=$2 46 sub(/:/, "", country) 47 printf "static const struct ieee80211_regdomain regdom_%s = {\n", country 48 printf "\t.alpha2 = \"%s\",\n", country 49 printf "\t.reg_rules = {\n" 50 active = 1 51 regdb = regdb "\t®dom_" country ",\n" 52} 53 54active && /^[ \t]*\(/ { 55 start = $1 56 sub(/\(/, "", start) 57 end = $3 58 bw = $5 59 sub(/\),/, "", bw) 60 gain = $6 61 sub(/\(/, "", gain) 62 sub(/,/, "", gain) 63 power = $7 64 sub(/\)/, "", power) 65 sub(/,/, "", power) 66 # power might be in mW... 67 units = $8 68 sub(/\)/, "", units) 69 sub(/,/, "", units) 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 } 83 flagstr = "" 84 for (i=8; i<=NF; i++) 85 flagstr = flagstr $i 86 split(flagstr, flagarray, ",") 87 flags = "" 88 for (arg in flagarray) { 89 if (flagarray[arg] == "NO-OFDM") { 90 flags = flags "\n\t\t\tNL80211_RRF_NO_OFDM | " 91 } else if (flagarray[arg] == "NO-CCK") { 92 flags = flags "\n\t\t\tNL80211_RRF_NO_CCK | " 93 } else if (flagarray[arg] == "NO-INDOOR") { 94 flags = flags "\n\t\t\tNL80211_RRF_NO_INDOOR | " 95 } else if (flagarray[arg] == "NO-OUTDOOR") { 96 flags = flags "\n\t\t\tNL80211_RRF_NO_OUTDOOR | " 97 } else if (flagarray[arg] == "DFS") { 98 flags = flags "\n\t\t\tNL80211_RRF_DFS | " 99 } else if (flagarray[arg] == "PTP-ONLY") { 100 flags = flags "\n\t\t\tNL80211_RRF_PTP_ONLY | " 101 } else if (flagarray[arg] == "PTMP-ONLY") { 102 flags = flags "\n\t\t\tNL80211_RRF_PTMP_ONLY | " 103 } else if (flagarray[arg] == "PASSIVE-SCAN") { 104 flags = flags "\n\t\t\tNL80211_RRF_PASSIVE_SCAN | " 105 } else if (flagarray[arg] == "NO-IBSS") { 106 flags = flags "\n\t\t\tNL80211_RRF_NO_IBSS | " 107 } 108 } 109 flags = flags "0" 110 printf "\t\tREG_RULE(%d, %d, %d, %d, %d, %s),\n", start, end, bw, gain, power, flags 111 rules++ 112} 113 114active && /^[ \t]*$/ { 115 active = 0 116 printf "\t},\n" 117 printf "\t.n_reg_rules = %d\n", rules 118 printf "};\n\n" 119 rules = 0; 120} 121 122END { 123 print regdb "};" 124 print "" 125 print "int reg_regdb_size = ARRAY_SIZE(reg_regdb);" 126} 127