diff options
Diffstat (limited to 'db2fw.py')
-rwxr-xr-x | db2fw.py | 31 |
1 files changed, 28 insertions, 3 deletions
@@ -5,6 +5,7 @@ import struct import hashlib from dbparse import DBParser import sys +from math import log MAGIC = 0x52474442 VERSION = 20 @@ -26,6 +27,13 @@ def create_collections(countries): result[(c.permissions, c.dfs_region)] = 1 return list(result) +def create_wmms(countries): + result = {} + for c in countries.itervalues(): + for rule in c.permissions: + if rule.wmmrule is not None: + result[rule.wmmrule] = 1 + return list(result) def be32(output, val): output.write(struct.pack('>I', val)) @@ -63,6 +71,8 @@ rules = create_rules(countries) rules.sort() collections = create_collections(countries) collections.sort() +wmms = create_wmms(countries) +wmms.sort() output = BytesIO() @@ -79,10 +89,19 @@ for alpha2 in countrynames: country_ptrs[alpha2] = PTR(output) output.write(b'\x00' * 4) +wmmdb = {} +for w in wmms: + assert output.tell() & 3 == 0 + wmmdb[w] = output.tell() >> 2 + for r in w._as_tuple(): + ecw = int(log(r[0] + 1, 2)) << 4 | int(log(r[1] + 1, 2)) + ac = (ecw, r[2],r[3]) + output.write(struct.pack('>BBH', *ac)) + reg_rules = {} flags = 0 for reg_rule in rules: - freq_range, power_rule = reg_rule.freqband, reg_rule.power + freq_range, power_rule, wmm_rule = reg_rule.freqband, reg_rule.power, reg_rule.wmmrule reg_rules[reg_rule] = output.tell() assert power_rule.max_ant_gain == 0 flags = 0 @@ -102,13 +121,19 @@ for reg_rule in rules: cac_timeout = 0 # TODO if not (flags & 1<<2): cac_timeout = 0 - if cac_timeout: + if cac_timeout or wmm_rule: + rule_len += 2 + if wmm_rule is not None: rule_len += 2 output.write(struct.pack('>BBHIII', rule_len, flags, int(power_rule.max_eirp * 100), int(freq_range.start * 1000), int(freq_range.end * 1000), int(freq_range.maxbw * 1000), )) - if cac_timeout: + if rule_len > 16: output.write(struct.pack('>H', cac_timeout)) + + if rule_len > 18: + be16(output, wmmdb[wmm_rule]) + while rule_len % 4: output.write('\0') rule_len += 1 |