Blame view

net/wireless/genregdb.awk 3.38 KB
3b377ea9d   John W. Linville   wireless: support...
1
2
3
4
5
6
7
8
9
  #!/usr/bin/awk -f
  #
  # genregdb.awk -- generate regdb.c from db.txt
  #
  # Actually, it reads from stdin (presumed to be db.txt) and writes
  # to stdout (presumed to be regdb.c), but close enough...
  #
  # Copyright 2009 John W. Linville <linville@tuxdriver.com>
  #
3b77d5ec0   Luis R. Rodriguez   cfg80211: relicen...
10
11
12
  # Permission to use, copy, modify, and/or distribute this software for any
  # purpose with or without fee is hereby granted, provided that the above
  # copyright notice and this permission notice appear in all copies.
3b377ea9d   John W. Linville   wireless: support...
13
  #
3b77d5ec0   Luis R. Rodriguez   cfg80211: relicen...
14
15
16
17
18
19
20
  # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3b377ea9d   John W. Linville   wireless: support...
21
22
23
24
25
26
27
28
29
30
  
  BEGIN {
  	active = 0
  	rules = 0;
  	print "/*"
  	print " * DO NOT EDIT -- file generated from data in db.txt"
  	print " */"
  	print ""
  	print "#include <linux/nl80211.h>"
  	print "#include <net/cfg80211.h>"
2ea6fb6d1   John W. Linville   wireless: correct...
31
  	print "#include \"regdb.h\""
3b377ea9d   John W. Linville   wireless: support...
32
33
34
35
36
37
  	print ""
  	regdb = "const struct ieee80211_regdomain *reg_regdb[] = {
  "
  }
  
  /^[ \t]*#/ {
f83d664ee   John W. Linville   wireless: fix com...
38
  	# Ignore
3b377ea9d   John W. Linville   wireless: support...
39
40
41
  }
  
  !active && /^[ \t]*$/ {
f83d664ee   John W. Linville   wireless: fix com...
42
  	# Ignore
3b377ea9d   John W. Linville   wireless: support...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  }
  
  !active && /country/ {
  	country=$2
  	sub(/:/, "", country)
  	printf "static const struct ieee80211_regdomain regdom_%s = {
  ", country
  	printf "\t.alpha2 = \"%s\",
  ", country
  	printf "\t.reg_rules = {
  "
  	active = 1
  	regdb = regdb "\t&regdom_" country ",
  "
  }
  
  active && /^[ \t]*\(/ {
  	start = $1
  	sub(/\(/, "", start)
  	end = $3
  	bw = $5
  	sub(/\),/, "", bw)
  	gain = $6
  	sub(/\(/, "", gain)
  	sub(/,/, "", gain)
  	power = $7
  	sub(/\)/, "", power)
  	sub(/,/, "", power)
  	# power might be in mW...
  	units = $8
  	sub(/\)/, "", units)
  	sub(/,/, "", units)
  	if (units == "mW") {
  		if (power == 100) {
  			power = 20
  		} else if (power == 200) {
  			power = 23
  		} else if (power == 500) {
  			power = 27
  		} else if (power == 1000) {
  			power = 30
  		} else {
  			print "Unknown power value in database!"
  		}
  	}
  	flagstr = ""
  	for (i=8; i<=NF; i++)
  		flagstr = flagstr $i
  	split(flagstr, flagarray, ",")
  	flags = ""
  	for (arg in flagarray) {
  		if (flagarray[arg] == "NO-OFDM") {
  			flags = flags "
  \t\t\tNL80211_RRF_NO_OFDM | "
  		} else if (flagarray[arg] == "NO-CCK") {
  			flags = flags "
  \t\t\tNL80211_RRF_NO_CCK | "
  		} else if (flagarray[arg] == "NO-INDOOR") {
  			flags = flags "
  \t\t\tNL80211_RRF_NO_INDOOR | "
  		} else if (flagarray[arg] == "NO-OUTDOOR") {
  			flags = flags "
  \t\t\tNL80211_RRF_NO_OUTDOOR | "
  		} else if (flagarray[arg] == "DFS") {
  			flags = flags "
  \t\t\tNL80211_RRF_DFS | "
  		} else if (flagarray[arg] == "PTP-ONLY") {
  			flags = flags "
  \t\t\tNL80211_RRF_PTP_ONLY | "
  		} else if (flagarray[arg] == "PTMP-ONLY") {
  			flags = flags "
  \t\t\tNL80211_RRF_PTMP_ONLY | "
  		} else if (flagarray[arg] == "PASSIVE-SCAN") {
  			flags = flags "
  \t\t\tNL80211_RRF_PASSIVE_SCAN | "
  		} else if (flagarray[arg] == "NO-IBSS") {
  			flags = flags "
  \t\t\tNL80211_RRF_NO_IBSS | "
  		}
  	}
  	flags = flags "0"
  	printf "\t\tREG_RULE(%d, %d, %d, %d, %d, %s),
  ", start, end, bw, gain, power, flags
  	rules++
  }
  
  active && /^[ \t]*$/ {
  	active = 0
  	printf "\t},
  "
  	printf "\t.n_reg_rules = %d
  ", rules
  	printf "};
  
  "
  	rules = 0;
  }
  
  END {
  	print regdb "};"
  	print ""
  	print "int reg_regdb_size = ARRAY_SIZE(reg_regdb);"
  }