diff mbox series

[v2,1/1] wireless-regdb: add country selection

Message ID 20200716125017.17669-1-fe@dev.tdt.de
State New
Delegated to: Felix Fietkau
Headers show
Series [v2,1/1] wireless-regdb: add country selection | expand

Commit Message

Florian Eckert July 16, 2020, 12:50 p.m. UTC
Until now it has not been possible to remove countries from the regdb.
The packages has been extended, so that it is now possible to add or
omit individual countries in the regdb during package compile time.

You can now add countries to a blacklist or whitelist to customize the
regdb. In the blacklist or whitelist the countries must be entered in a
comma separated list. So abbreviation for the countries are entered in
IS03166 ALPHA-2 notation.

If this option is not activated, then all countries in the regdb are taken
over as before.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
---
 package/firmware/wireless-regdb/Config.in | 47 ++++++++++++++++++++
 package/firmware/wireless-regdb/Makefile  | 52 ++++++++++++++++++++++-
 2 files changed, 98 insertions(+), 1 deletion(-)
 create mode 100644 package/firmware/wireless-regdb/Config.in
diff mbox series

Patch

diff --git a/package/firmware/wireless-regdb/Config.in b/package/firmware/wireless-regdb/Config.in
new file mode 100644
index 0000000000..1a37ff4d2b
--- /dev/null
+++ b/package/firmware/wireless-regdb/Config.in
@@ -0,0 +1,47 @@ 
+if PACKAGE_wireless-regdb
+
+config WIRELESS_REGDB_CUSTOM
+	bool "Customize wirelss regdb country selection"
+	default n
+	help
+	  Enabling this allows customization the wireless regdb
+	  in blacklist and whitelist.
+
+if WIRELESS_REGDB_CUSTOM
+
+menu "Settings"
+
+choice
+	prompt "Choose regdb handling"
+	default WIRELESS_REGDB_WHITELIST
+	help
+	  Choose which regdb handling you want to use during compile time.
+
+config WIRELESS_REGDB_WHITELIST
+	bool "whitelist"
+	help
+	  Add a comma separated list, which countries should be included
+	  in the regdb during package compile (ISO3166 ALPHA-2).
+
+config WIRELESS_REGDB_BLACKLIST
+	bool "blacklist"
+	help
+	  Add a comma seperate list which countries should NOT be included
+	  in the regdb during package compile (ISO3166 ALPHA-2).
+
+endchoice
+
+config WIRELESS_REGDB_COUNTRIES
+	string "Country list (ISO3166 ALPHA-2)"
+	help
+	  Add a comma separated country list for whitelist/blacklist
+	  handling in wireless regdb during compile time in
+	  ISO3166 ALPHA-2 notation.
+	  For example: DE,FR,US,ES
+
+endmenu
+
+endif
+
+endif
+
diff --git a/package/firmware/wireless-regdb/Makefile b/package/firmware/wireless-regdb/Makefile
index fc18d159b1..3ba95ce320 100644
--- a/package/firmware/wireless-regdb/Makefile
+++ b/package/firmware/wireless-regdb/Makefile
@@ -20,8 +20,58 @@  define Package/wireless-regdb
   TITLE:=Wireless Regulatory Database
 endef
 
+define Package/wireless-regdb/config
+	source "$(SOURCE)/Config.in
+endef
+
+define Build/Configure
+	$(CP) $(PKG_BUILD_DIR)/db.txt $(PKG_BUILD_DIR)/db-gen.txt
+	( \
+	if [ "$(CONFIG_WIRELESS_REGDB_CUSTOM)" = "y" ]; then \
+		echo "" > $(PKG_BUILD_DIR)/db-gen.txt; \
+		IFS='\n'; \
+		while read -r line; do \
+			if echo "$$$$line" | grep "^country" 1>/dev/null 2>/dev/null; then \
+				IFS_BAK=$$$$IFS; \
+				IFS=','; \
+				code=$$$${line:8:2}; \
+				countries=$(CONFIG_WIRELESS_REGDB_COUNTRIES); \
+				for country in $$$$countries; do \
+					if [ "$(CONFIG_WIRELESS_REGDB_WHITELIST)" = "y" ]; then \
+						if [ "$$$$code" = "$$$$country" ]; then \
+							match="yes"; \
+							break; \
+						else \
+							match="no"; \
+						fi; \
+					fi; \
+					if [ "$(CONFIG_WIRELESS_REGDB_BLACKLIST)" = "y" ]; then \
+						if [ "$$$$code" = "$$$$country" ]; then \
+							match="no"; \
+							break; \
+						else \
+							match="yes"; \
+						fi; \
+					fi; \
+				done; \
+				IFS=$$$$IFS_BAK; \
+			fi; \
+			if echo "$$$$line" | grep "^wmmrule ETSI:" 1>/dev/null 2>/dev/null; then \
+				match="yes"; \
+			fi; \
+			if [ "$$$$match" = "yes" ]; then \
+				printf "%s\n" "$$$$line" >> $(PKG_BUILD_DIR)/db-gen.txt; \
+			fi; \
+			if [ -z "$$$$line" ] && [ "$$$$match" = "yes" ]; then \
+				match="no"; \
+			fi; \
+		done < $(PKG_BUILD_DIR)/db.txt; \
+	fi; \
+	)
+endef
+
 define Build/Compile
-	$(STAGING_DIR_HOST)/bin/$(PYTHON) $(PKG_BUILD_DIR)/db2fw.py $(PKG_BUILD_DIR)/regulatory.db $(PKG_BUILD_DIR)/db.txt
+	$(STAGING_DIR_HOST)/bin/$(PYTHON) $(PKG_BUILD_DIR)/db2fw.py $(PKG_BUILD_DIR)/regulatory.db $(PKG_BUILD_DIR)/db-gen.txt
 endef
 
 define Package/wireless-regdb/install