From 8cc8ad3989d338eedae01d037728b358f0ebc69a Mon Sep 17 00:00:00 2001 From: Thomas Duckworth Date: Fri, 6 Feb 2026 13:20:55 +1100 Subject: [PATCH] Automatically set the wireless regulatory domain Automatically sets the wireless regulatory domain when a wireless device is connected, or on timezone change. Resolves #464 --- LICENSES/ISC.txt | 5 ++ mkosi.extra/usr/lib/iw-set-regdomain | 83 +++++++++++++++++++ .../systemd/system-preset/50-kde-linux.preset | 1 + .../system/kde-linux-iw-set-regdomain.path | 12 +++ .../system/kde-linux-iw-set-regdomain.service | 9 ++ .../lib/udev/rules.d/85-iw-regulatory.rules | 9 ++ 6 files changed, 119 insertions(+) create mode 100644 LICENSES/ISC.txt create mode 100755 mkosi.extra/usr/lib/iw-set-regdomain create mode 100644 mkosi.extra/usr/lib/systemd/system/kde-linux-iw-set-regdomain.path create mode 100644 mkosi.extra/usr/lib/systemd/system/kde-linux-iw-set-regdomain.service create mode 100644 mkosi.extra/usr/lib/udev/rules.d/85-iw-regulatory.rules diff --git a/LICENSES/ISC.txt b/LICENSES/ISC.txt new file mode 100644 index 0000000..7cc2812 --- /dev/null +++ b/LICENSES/ISC.txt @@ -0,0 +1,5 @@ + + +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. + +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. diff --git a/mkosi.extra/usr/lib/iw-set-regdomain b/mkosi.extra/usr/lib/iw-set-regdomain new file mode 100755 index 0000000..39c7486 --- /dev/null +++ b/mkosi.extra/usr/lib/iw-set-regdomain @@ -0,0 +1,83 @@ +#!/bin/sh + +# SPDX-License-Identifier: ISC +# SPDX-FileCopyrightText: 2025 Thomas Duckworth +# SPDX-FileCopyrightText: 2009-2014 Red Hat, Inc. +# SPDX-FileCopyrightText: 2025 Velocity Limitless, LLC. + +# See https://gitlab.com/VelocityLimitless/Projects/iw-setregdomain + +# Copyright 2009-2014 Red Hat, Inc. All rights reserved. +# +# 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. +# +# 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. +# + +REGDOMAIN=/etc/iw-regdomain +LOCALTIME=/etc/localtime + +LOGGER="/usr/bin/logger -t iw-set-regdomain" + +getcountry() { + while read c a z r + do + if [ "$z" = "$ZONE" ] + then + echo $c + break + fi + done < /usr/share/zoneinfo/zone.tab +} + +if [ -f $REGDOMAIN ] +then + # This should set COUNTRY + . $REGDOMAIN + if [ -n "$COUNTRY" ] + then + /usr/bin/iw reg set $COUNTRY + exit + fi +fi + +if [ -f "$LOCALTIME" ] +then + ZONE=$(readlink -f $LOCALTIME) + ZONE=${ZONE#/usr/share/zoneinfo/} +else + $LOGGER -s "Timezone information not found. Unable to set wireless regulatory domain." + exit 1 +fi + +if [ -z "$ZONE" -o "$ZONE" = "$LOCALTIME" ] +then + $LOGGER -s "Could not determine timezone. Unable to set wireless regulatory domain." + exit 1 +fi + +COUNTRY=$(getcountry) + +if [ -z "$COUNTRY" ] +then + case "$ZONE" in + UTC|UCT|Universal|Zulu|GMT|Etc/UTC|Etc/UCT|Etc/Universal|Etc/Zulu|Etc/GMT) + $LOGGER "Timezone is $ZONE, with no associated country. Not setting wireless regulatory domain." + exit 0 + ;; + esac + + $LOGGER -s "Could not determine country for $ZONE. Unable to set wireless regulatory domain." + exit 1 +fi + +$LOGGER "Setting regulatory domain to $COUNTRY based on timezone ($ZONE)." +/usr/bin/iw reg set $COUNTRY diff --git a/mkosi.extra/usr/lib/systemd/system-preset/50-kde-linux.preset b/mkosi.extra/usr/lib/systemd/system-preset/50-kde-linux.preset index 7e3ba15..a958feb 100644 --- a/mkosi.extra/usr/lib/systemd/system-preset/50-kde-linux.preset +++ b/mkosi.extra/usr/lib/systemd/system-preset/50-kde-linux.preset @@ -43,6 +43,7 @@ enable switcheroo-control.service enable kde-linux-bootloader-visibility.service enable kde-linux-btrfs.service enable kde-linux-configure-firefox.path +enable kde-linux-iw-set-regdomain.path enable kde-linux-live-setup.service enable kde-linux-powertop.service enable kde-linux-volatile-var-lib-flatpak.service diff --git a/mkosi.extra/usr/lib/systemd/system/kde-linux-iw-set-regdomain.path b/mkosi.extra/usr/lib/systemd/system/kde-linux-iw-set-regdomain.path new file mode 100644 index 0000000..1a778d3 --- /dev/null +++ b/mkosi.extra/usr/lib/systemd/system/kde-linux-iw-set-regdomain.path @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +# SPDX-FileCopyrightText: 2025 Thomas Duckworth + +[Unit] +Description=Monitor Timezone Changes to Set Wireless Regulatory Domain + +[Path] +PathChanged=/etc/localtime +Unit=kde-linux-iw-set-regdomain.service + +[Install] +WantedBy=multi-user.target diff --git a/mkosi.extra/usr/lib/systemd/system/kde-linux-iw-set-regdomain.service b/mkosi.extra/usr/lib/systemd/system/kde-linux-iw-set-regdomain.service new file mode 100644 index 0000000..a6e7cfc --- /dev/null +++ b/mkosi.extra/usr/lib/systemd/system/kde-linux-iw-set-regdomain.service @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +# SPDX-FileCopyrightText: 2025 Thomas Duckworth + +[Unit] +Description=Set Wireless Regulatory Domain on Timezone Change + +[Service] +Type=oneshot +ExecStart=/usr/lib/iw-set-regdomain diff --git a/mkosi.extra/usr/lib/udev/rules.d/85-iw-regulatory.rules b/mkosi.extra/usr/lib/udev/rules.d/85-iw-regulatory.rules new file mode 100644 index 0000000..150448f --- /dev/null +++ b/mkosi.extra/usr/lib/udev/rules.d/85-iw-regulatory.rules @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: ISC +# SPDX-FileCopyrightText: 2025 Thomas Duckworth +# SPDX-FileCopyrightText: 2009-2014 Red Hat, Inc. +# SPDX-FileCopyrightText: 2025 Velocity Limitless, LLC. + +# Set wireless regulatory domain at device creation +# For more information see https://gitlab.com/VelocityLimitless/Projects/iw-setregdomain + +SUBSYSTEM=="ieee80211", ACTION=="add", RUN+="/usr/lib/iw-set-regdomain"