John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 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 | # |
Luis R. Rodriguez | 3b77d5e | 2011-12-20 12:23:38 -0800 | [diff] [blame] | 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. |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 13 | # |
Luis R. Rodriguez | 3b77d5e | 2011-12-20 12:23:38 -0800 | [diff] [blame] | 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. |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 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>" |
John W. Linville | 2ea6fb6 | 2010-07-20 12:29:14 -0400 | [diff] [blame] | 31 | print "#include \"regdb.h\"" |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 32 | print "" |
| 33 | regdb = "const struct ieee80211_regdomain *reg_regdb[] = {\n" |
| 34 | } |
| 35 | |
Luis R. Rodriguez | af9b223 | 2013-10-28 03:19:45 +0100 | [diff] [blame] | 36 | function parse_country_head() { |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 37 | country=$2 |
| 38 | sub(/:/, "", country) |
| 39 | printf "static const struct ieee80211_regdomain regdom_%s = {\n", country |
| 40 | printf "\t.alpha2 = \"%s\",\n", country |
Janusz Dziedzic | f0823475 | 2013-09-17 08:25:36 +0200 | [diff] [blame] | 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" |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 47 | printf "\t.reg_rules = {\n" |
| 48 | active = 1 |
| 49 | regdb = regdb "\t®dom_" country ",\n" |
| 50 | } |
| 51 | |
Luis R. Rodriguez | af9b223 | 2013-10-28 03:19:45 +0100 | [diff] [blame] | 52 | function parse_reg_rule() |
| 53 | { |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 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) |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 69 | dfs_cac = $9 |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 70 | if (units == "mW") { |
chaitanya.mgit@gmail.com | a9fb541 | 2014-05-26 18:01:44 +0530 | [diff] [blame] | 71 | power = 10 * log(power)/log(10) |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 72 | } else { |
| 73 | dfs_cac = $8 |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 74 | } |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 75 | sub(/,/, "", dfs_cac) |
| 76 | sub(/\(/, "", dfs_cac) |
| 77 | sub(/\)/, "", dfs_cac) |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 78 | flagstr = "" |
| 79 | for (i=8; i<=NF; i++) |
| 80 | flagstr = flagstr $i |
| 81 | split(flagstr, flagarray, ",") |
| 82 | flags = "" |
| 83 | for (arg in flagarray) { |
| 84 | if (flagarray[arg] == "NO-OFDM") { |
| 85 | flags = flags "\n\t\t\tNL80211_RRF_NO_OFDM | " |
| 86 | } else if (flagarray[arg] == "NO-CCK") { |
| 87 | flags = flags "\n\t\t\tNL80211_RRF_NO_CCK | " |
| 88 | } else if (flagarray[arg] == "NO-INDOOR") { |
| 89 | flags = flags "\n\t\t\tNL80211_RRF_NO_INDOOR | " |
| 90 | } else if (flagarray[arg] == "NO-OUTDOOR") { |
| 91 | flags = flags "\n\t\t\tNL80211_RRF_NO_OUTDOOR | " |
| 92 | } else if (flagarray[arg] == "DFS") { |
| 93 | flags = flags "\n\t\t\tNL80211_RRF_DFS | " |
| 94 | } else if (flagarray[arg] == "PTP-ONLY") { |
| 95 | flags = flags "\n\t\t\tNL80211_RRF_PTP_ONLY | " |
| 96 | } else if (flagarray[arg] == "PTMP-ONLY") { |
| 97 | flags = flags "\n\t\t\tNL80211_RRF_PTMP_ONLY | " |
| 98 | } else if (flagarray[arg] == "PASSIVE-SCAN") { |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 99 | flags = flags "\n\t\t\tNL80211_RRF_NO_IR | " |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 100 | } else if (flagarray[arg] == "NO-IBSS") { |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 101 | flags = flags "\n\t\t\tNL80211_RRF_NO_IR | " |
| 102 | } else if (flagarray[arg] == "NO-IR") { |
| 103 | flags = flags "\n\t\t\tNL80211_RRF_NO_IR | " |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 104 | } else if (flagarray[arg] == "AUTO-BW") { |
| 105 | flags = flags "\n\t\t\tNL80211_RRF_AUTO_BW | " |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 106 | } |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 107 | |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 108 | } |
| 109 | flags = flags "0" |
chaitanya.mgit@gmail.com | a9fb541 | 2014-05-26 18:01:44 +0530 | [diff] [blame] | 110 | printf "\t\tREG_RULE_EXT(%d, %d, %d, %d, %.0f, %d, %s),\n", start, end, bw, gain, power, dfs_cac, flags |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 111 | rules++ |
| 112 | } |
| 113 | |
Luis R. Rodriguez | af9b223 | 2013-10-28 03:19:45 +0100 | [diff] [blame] | 114 | function print_tail_country() |
| 115 | { |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 116 | active = 0 |
| 117 | printf "\t},\n" |
| 118 | printf "\t.n_reg_rules = %d\n", rules |
| 119 | printf "};\n\n" |
| 120 | rules = 0; |
| 121 | } |
| 122 | |
Luis R. Rodriguez | af9b223 | 2013-10-28 03:19:45 +0100 | [diff] [blame] | 123 | /^[ \t]*#/ { |
| 124 | # Ignore |
| 125 | } |
| 126 | |
| 127 | !active && /^[ \t]*$/ { |
| 128 | # Ignore |
| 129 | } |
| 130 | |
| 131 | !active && /country/ { |
| 132 | parse_country_head() |
| 133 | } |
| 134 | |
| 135 | active && /^[ \t]*\(/ { |
| 136 | parse_reg_rule() |
| 137 | } |
| 138 | |
| 139 | active && /^[ \t]*$/ { |
| 140 | print_tail_country() |
| 141 | } |
| 142 | |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 143 | END { |
Luis R. Rodriguez | ae68939 | 2013-10-28 03:19:46 +0100 | [diff] [blame] | 144 | if (active) |
| 145 | print_tail_country() |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 146 | print regdb "};" |
| 147 | print "" |
| 148 | print "int reg_regdb_size = ARRAY_SIZE(reg_regdb);" |
| 149 | } |