From 1f7d2fdf740207f03283d786043a6759fe7053961219c67f369bb845a1a43d4e Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Tue, 1 Dec 2020 11:54:18 +0000 Subject: [PATCH] Accepting request 851854 from home:WernerFink:branches:hardware - Add patch crda-default.patch as well as template file crda.default for /usr/etc/default/crda to support WLAN USB dongles as well as mostly raspberry WLAN drivers not knowing about kernel builtin support for WLAN regular country domains (boo#1179308) OBS-URL: https://build.opensuse.org/request/show/851854 OBS-URL: https://build.opensuse.org/package/show/hardware/crda?expand=0&rev=37 --- crda-default.patch | 103 +++++++++++++++++++++++++++++++++++++++++++++ crda.changes | 8 ++++ crda.default | 8 ++++ crda.spec | 13 +++++- 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 crda-default.patch create mode 100644 crda.default diff --git a/crda-default.patch b/crda-default.patch new file mode 100644 index 0000000..cca5ed9 --- /dev/null +++ b/crda-default.patch @@ -0,0 +1,103 @@ +Provide an option to specify a reg code in /etc/default/crda +and also try a distribution configuration /usr/etc/default/crda. +This solves bug boo#1179308 + +--- + crda.8 | 17 ++++++++++++++++- + crda.c | 43 +++++++++++++++++++++++++++++++++++++++++-- + 2 files changed, 57 insertions(+), 3 deletions(-) + +diff --git a/crda.8 b/crda.8 +--- a/crda.8 ++++ b/crda.8 +@@ -68,7 +68,22 @@ An example udev rule which can be used ( + .B /lib/udev/rules.d/85-regulatory.rules + ): + +-.I KERNEL=="regulatory*", ACTION=="change", SUBSYSTEM=="platform", RUN+="/sbin/crda" ++.I KERNEL=="regulatory*", ACTION=="change", SUBSYSTEM=="platform", RUN+="/usr/sbin/crda" ++ ++.SS ++.SH Standard configuration ++in the file ++.I /usr/etc/default/crda ++the variable ++.B REGDOMAIN ++is set to the global WLAN default code ++.BR 00 . ++The local administrator might copy this file to ++.I /etc/default/crda ++and set the ISO / IEC 3166 alpha2 country code of the local area. Then ++any execution of ++.B crda ++will then send this as regulatory domain for that alpha2 to the kernel. + + .SS + .SH Environment variable +diff --git a/crda.c b/crda.c +--- a/crda.c ++++ b/crda.c +@@ -4,6 +4,7 @@ + * Userspace helper which sends regulatory domains to Linux via nl80211 + */ + ++#include + #include + #include + #include +@@ -156,6 +157,11 @@ int main(int argc, char **argv) + struct nlattr *nl_reg_rules; + const struct ieee80211_regdomain *rd = NULL; + ++ const char *default_paths[] = { ++ "/etc/default/crda", /* Users configuration if COUNTRY is not set */ ++ "/usr/etc/default/crda", /* General configuration if COUNTRY is not set */ ++ NULL ++ }; + const char *regdb_paths[] = { + "/usr/local/lib/crda/regulatory.bin", /* Users/preloads can override */ + "/usr/lib/crda/regulatory.bin", /* General distribution package usage */ +@@ -171,8 +177,41 @@ int main(int argc, char **argv) + + env_country = getenv("COUNTRY"); + if (!env_country) { +- fprintf(stderr, "COUNTRY environment variable not set.\n"); +- return -EINVAL; ++ const char **conf = default_paths; ++ while (*conf != NULL) { ++ fd = open(*conf, O_RDONLY); ++ if (fd >= 0) ++ break; ++ conf++; ++ } ++ if (fd >= 0) { ++ FILE *reg = fdopen(fd, "r"); ++ if (reg) { ++ char *line = NULL; ++ ssize_t nread; ++ size_t len = 0; ++ while ((nread = getline(&line, &len, reg)) != -1) { ++ char *ptr = line; ++ if (*ptr == '#' || *ptr == '\n') ++ continue; ++ while (isspace(*ptr)) ++ line++; ++ if (strncmp("REGDOMAIN=", ptr, 10) == 0) { ++ ptr += 10; ++ env_country = strndup(ptr, 2); ++ break; ++ } ++ } ++ if (line) ++ free(line); ++ fclose(reg); ++ } else ++ close(fd); ++ } ++ if (!env_country) { ++ fprintf(stderr, "COUNTRY environment variable not set.\n"); ++ return -EINVAL; ++ } + } + + if (!reglib_is_valid_regdom(env_country)) { diff --git a/crda.changes b/crda.changes index 0af6997..979ed20 100644 --- a/crda.changes +++ b/crda.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Mon Nov 30 13:40:28 UTC 2020 - Dr. Werner Fink + +- Add patch crda-default.patch as well as template file crda.default + for /usr/etc/default/crda to support WLAN USB dongles as well as + mostly raspberry WLAN drivers not knowing about kernel builtin + support for WLAN regular country domains (boo#1179308) + ------------------------------------------------------------------- Tue Nov 17 13:43:31 UTC 2020 - Ludwig Nussel diff --git a/crda.default b/crda.default new file mode 100644 index 0000000..0e19935 --- /dev/null +++ b/crda.default @@ -0,0 +1,8 @@ +# +# Used by the crda(8) helper to set the country code for the WLAN +# location. Outside the US or without self-managed WLAN devices +# it is helpful to copy this file to /etc/default/ and set the +# two letter specific ISO / IEC 3166 alpha2 country code. +# + +REGDOMAIN=00 diff --git a/crda.spec b/crda.spec index 0f687d3..eb9f8b6 100644 --- a/crda.spec +++ b/crda.spec @@ -26,7 +26,8 @@ Group: Hardware/Wifi URL: https://github.com/mcgrof/crda/commits/master Version: 4.14 Release: 0 -Source: http://kernel.org/pub/software/network/crda/crda-%{version}.tar.gz +Source0: http://kernel.org/pub/software/network/crda/crda-%{version}.tar.gz +Source1: crda.default BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: libgcrypt-devel BuildRequires: pkg-config @@ -45,6 +46,8 @@ Patch1: crda-python3.patch Patch2: crda-67f1e6ddbdfade357e234c9d58a30fe0a283fe60.patch # PATCH-FIX-UPSTREAM crda-f4ef2531698fb9ba006e8b31a223b3269be8bc7c.patch Patch3: crda-f4ef2531698fb9ba006e8b31a223b3269be8bc7c.patch +# PATCH-FIX-SUSE crda-default.patch +Patch4: crda-default.patch %description The crda binary provides access to the wireless-regdb to the kernel @@ -56,6 +59,7 @@ through udev. %patch1 -p1 %patch2 -p1 %patch3 -p1 +%patch4 -p1 # make install calls 'ldconfig' and fails if it cannot run it... ln -s /bin/true ldconfig @@ -67,6 +71,8 @@ make all_noverify %{?_smp_mflags} V=1 # to find ldconfig... export PATH=.:$PATH make DESTDIR=$RPM_BUILD_ROOT SBINDIR=%{_sbindir}/ UDEV_RULE_DIR=%{_udevrulesdir} LIBDIR=%{_libdir} install +mkdir -p %{buildroot}%{_prefix}%{_sysconfdir}/default +install -m 644 %{S:1} %{buildroot}%{_prefix}%{_sysconfdir}/default/%{name} %if !0%{?usrmerged} mkdir $RPM_BUILD_ROOT/sbin ln -sf %{_sbindir}/{crda,regdbdump} $RPM_BUILD_ROOT/sbin @@ -84,6 +90,11 @@ rm -r %{buildroot}/usr/include/reglib /sbin/crda /sbin/regdbdump %endif +%if 0%{?suse_version} < 1550 +%dir %{_prefix}%{_sysconfdir}/ +%dir %{_prefix}%{_sysconfdir}/default/ +%endif +%{_prefix}%{_sysconfdir}/default/%{name} %{_udevrulesdir}/85-regulatory.rules %{_mandir}/man8/crda.8.gz %{_mandir}/man8/regdbdump.8.gz