Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scripts/customize-wireless-regdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ def transform(lines: list[str]) -> tuple[list[str], bool]:
out = list(lines)
if out and not out[-1].endswith("\n"):
out[-1] = f"{out[-1]}\n"
if out and out[-1].strip():
out.append("\n")
out.append("country BJ:\n")
out.extend(f"{rule}\n" for rule in TEMPLATE_LINES)
return out, True
Expand All @@ -58,7 +56,9 @@ def main() -> int:
transformed, added = transform(original)

rendered = "".join(transformed)
if "country BJ:\n" not in rendered or " (5150 - 5350 @ 160), (36)\n" not in rendered or " (5925 - 7125 @ 320), (36)\n" not in rendered:
if "country BJ:\n" not in rendered or (
added and any(f"{rule}\n" not in rendered for rule in TEMPLATE_LINES)
):
print("wireless-regdb customization failed: BJ template validation failed", file=sys.stderr)
return 1

Expand Down
26 changes: 25 additions & 1 deletion scripts/verify-custom-regdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,33 @@ test -s "$REGDB" || fail "regulatory.db is absent from the root filesystem"
test -n "$MANIFEST" || fail "firmware manifest was not found"

extract_country() {
awk -v header="country $1:" '$0 == header { inside = 1 } inside { if ($0 ~ /^country [A-Z0-9][A-Z0-9]:/ && $0 != header) exit; print }' "$2"
awk -v country="$1" '
$0 ~ ("^country " country ":") { inside = 1 }
inside {
if ($0 ~ /^country [A-Z0-9][A-Z0-9]:/ && $0 !~ ("^country " country ":")) exit
print
}
' "$2"
}

country_codes() {
awk '/^country [A-Z0-9][A-Z0-9]:/ { print substr($2, 1, 2) }' "$1"
}

stock_countries="$(country_codes "$STOCK_DB_TXT")"
if grep -Fxq 'BJ' <<< "$stock_countries"; then
expected_countries="$stock_countries"
else
expected_countries="${stock_countries}"$'\nBJ'
fi
custom_countries="$(country_codes "$DB_TXT")"
diff -u <(printf '%s\n' "$expected_countries") <(printf '%s\n' "$custom_countries") >/dev/null || fail "country list was modified unexpectedly"

while IFS= read -r country; do
test -n "$country" || continue
diff -u <(extract_country "$country" "$STOCK_DB_TXT") <(extract_country "$country" "$DB_TXT") >/dev/null || fail "country $country was modified"
done <<< "$stock_countries"

grep -qx 'country BJ:' "$DB_TXT" || fail "country BJ is absent"
stock_world="$(extract_country 00 "$STOCK_DB_TXT")"
custom_world="$(extract_country 00 "$DB_TXT")"
Expand Down