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 | # |
| 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 | |
| 15 | BEGIN { |
| 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>" |
| 24 | print "" |
| 25 | regdb = "const struct ieee80211_regdomain *reg_regdb[] = {\n" |
| 26 | } |
| 27 | |
| 28 | /^[ \t]*#/ { |
John W. Linville | f83d664 | 2009-12-25 16:35:43 -0800 | [diff] [blame] | 29 | # Ignore |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | !active && /^[ \t]*$/ { |
John W. Linville | f83d664 | 2009-12-25 16:35:43 -0800 | [diff] [blame] | 33 | # Ignore |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | !active && /country/ { |
| 37 | country=$2 |
| 38 | sub(/:/, "", country) |
| 39 | printf "static const struct ieee80211_regdomain regdom_%s = {\n", country |
| 40 | printf "\t.alpha2 = \"%s\",\n", country |
| 41 | printf "\t.reg_rules = {\n" |
| 42 | active = 1 |
| 43 | regdb = regdb "\t®dom_" country ",\n" |
| 44 | } |
| 45 | |
| 46 | active && /^[ \t]*\(/ { |
| 47 | start = $1 |
| 48 | sub(/\(/, "", start) |
| 49 | end = $3 |
| 50 | bw = $5 |
| 51 | sub(/\),/, "", bw) |
| 52 | gain = $6 |
| 53 | sub(/\(/, "", gain) |
| 54 | sub(/,/, "", gain) |
| 55 | power = $7 |
| 56 | sub(/\)/, "", power) |
| 57 | sub(/,/, "", power) |
| 58 | # power might be in mW... |
| 59 | units = $8 |
| 60 | sub(/\)/, "", units) |
| 61 | sub(/,/, "", units) |
| 62 | if (units == "mW") { |
| 63 | if (power == 100) { |
| 64 | power = 20 |
| 65 | } else if (power == 200) { |
| 66 | power = 23 |
| 67 | } else if (power == 500) { |
| 68 | power = 27 |
| 69 | } else if (power == 1000) { |
| 70 | power = 30 |
| 71 | } else { |
| 72 | print "Unknown power value in database!" |
| 73 | } |
| 74 | } |
| 75 | flagstr = "" |
| 76 | for (i=8; i<=NF; i++) |
| 77 | flagstr = flagstr $i |
| 78 | split(flagstr, flagarray, ",") |
| 79 | flags = "" |
| 80 | for (arg in flagarray) { |
| 81 | if (flagarray[arg] == "NO-OFDM") { |
| 82 | flags = flags "\n\t\t\tNL80211_RRF_NO_OFDM | " |
| 83 | } else if (flagarray[arg] == "NO-CCK") { |
| 84 | flags = flags "\n\t\t\tNL80211_RRF_NO_CCK | " |
| 85 | } else if (flagarray[arg] == "NO-INDOOR") { |
| 86 | flags = flags "\n\t\t\tNL80211_RRF_NO_INDOOR | " |
| 87 | } else if (flagarray[arg] == "NO-OUTDOOR") { |
| 88 | flags = flags "\n\t\t\tNL80211_RRF_NO_OUTDOOR | " |
| 89 | } else if (flagarray[arg] == "DFS") { |
| 90 | flags = flags "\n\t\t\tNL80211_RRF_DFS | " |
| 91 | } else if (flagarray[arg] == "PTP-ONLY") { |
| 92 | flags = flags "\n\t\t\tNL80211_RRF_PTP_ONLY | " |
| 93 | } else if (flagarray[arg] == "PTMP-ONLY") { |
| 94 | flags = flags "\n\t\t\tNL80211_RRF_PTMP_ONLY | " |
| 95 | } else if (flagarray[arg] == "PASSIVE-SCAN") { |
| 96 | flags = flags "\n\t\t\tNL80211_RRF_PASSIVE_SCAN | " |
| 97 | } else if (flagarray[arg] == "NO-IBSS") { |
| 98 | flags = flags "\n\t\t\tNL80211_RRF_NO_IBSS | " |
| 99 | } |
| 100 | } |
| 101 | flags = flags "0" |
| 102 | printf "\t\tREG_RULE(%d, %d, %d, %d, %d, %s),\n", start, end, bw, gain, power, flags |
| 103 | rules++ |
| 104 | } |
| 105 | |
| 106 | active && /^[ \t]*$/ { |
| 107 | active = 0 |
| 108 | printf "\t},\n" |
| 109 | printf "\t.n_reg_rules = %d\n", rules |
| 110 | printf "};\n\n" |
| 111 | rules = 0; |
| 112 | } |
| 113 | |
| 114 | END { |
| 115 | print regdb "};" |
| 116 | print "" |
| 117 | print "int reg_regdb_size = ARRAY_SIZE(reg_regdb);" |
| 118 | } |