genregdb.awk 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. BEGIN {
  22. active = 0
  23. rules = 0;
  24. print "/*"
  25. print " * DO NOT EDIT -- file generated from data in db.txt"
  26. print " */"
  27. print ""
  28. print "#include <linux/nl80211.h>"
  29. print "#include <net/cfg80211.h>"
  30. print "#include \"regdb.h\""
  31. print ""
  32. regdb = "const struct ieee80211_regdomain *reg_regdb[] = {\n"
  33. }
  34. /^[ \t]*#/ {
  35. # Ignore
  36. }
  37. !active && /^[ \t]*$/ {
  38. # Ignore
  39. }
  40. !active && /country/ {
  41. country=$2
  42. sub(/:/, "", country)
  43. printf "static const struct ieee80211_regdomain regdom_%s = {\n", country
  44. printf "\t.alpha2 = \"%s\",\n", country
  45. printf "\t.reg_rules = {\n"
  46. active = 1
  47. regdb = regdb "\t&regdom_" country ",\n"
  48. }
  49. active && /^[ \t]*\(/ {
  50. start = $1
  51. sub(/\(/, "", start)
  52. end = $3
  53. bw = $5
  54. sub(/\),/, "", bw)
  55. gain = $6
  56. sub(/\(/, "", gain)
  57. sub(/,/, "", gain)
  58. power = $7
  59. sub(/\)/, "", power)
  60. sub(/,/, "", power)
  61. # power might be in mW...
  62. units = $8
  63. sub(/\)/, "", units)
  64. sub(/,/, "", units)
  65. if (units == "mW") {
  66. if (power == 100) {
  67. power = 20
  68. } else if (power == 200) {
  69. power = 23
  70. } else if (power == 500) {
  71. power = 27
  72. } else if (power == 1000) {
  73. power = 30
  74. } else {
  75. print "Unknown power value in database!"
  76. }
  77. }
  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") {
  99. flags = flags "\n\t\t\tNL80211_RRF_PASSIVE_SCAN | "
  100. } else if (flagarray[arg] == "NO-IBSS") {
  101. flags = flags "\n\t\t\tNL80211_RRF_NO_IBSS | "
  102. }
  103. }
  104. flags = flags "0"
  105. printf "\t\tREG_RULE(%d, %d, %d, %d, %d, %s),\n", start, end, bw, gain, power, flags
  106. rules++
  107. }
  108. active && /^[ \t]*$/ {
  109. active = 0
  110. printf "\t},\n"
  111. printf "\t.n_reg_rules = %d\n", rules
  112. printf "};\n\n"
  113. rules = 0;
  114. }
  115. END {
  116. print regdb "};"
  117. print ""
  118. print "int reg_regdb_size = ARRAY_SIZE(reg_regdb);"
  119. }