[OpenWrt-Devel] [PATCH 2/2] base-files: rename SSID with EUI of mac address

Adrian Schmutzler freifunk at adrianschmutzler.de
Fri Nov 8 06:48:41 EST 2019

If the label MAC address is provided for a device, the default SSID
will be set to contain the EUI of this address, e.g. OpenWrt-ddeeff.

With multiple routers, this will help the user to identify his device
based on the MAC address printed on the device.

If no label MAC address is specified, this will use "OpenWrt" as
done before.

Using a uci-defaults script for this is necessary as mac80211.sh is
executed before /etc/board.json is created, so label MAC addresses
set in 02_network would not be available there.

Suggested-by: Rosy Song <rosysong at rosinson.com>
Signed-off-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>


This effectively uses a workaround to prevent SSID from being reset
after upgrade (match SSID vs. "OpenWrt"). If there is a nicer option,
please propose it.

Another option for this would be to explicitly mark the wireless uci
config as 'default setup' by a to-be-introduced option, which is
to be removed in a late uci-defaults script. This could then be
exploited for several other objectives, e.g. further config-dependent
WiFi setup tasks.
 .../etc/uci-defaults/15_wifi-ssid-mac-address | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 package/base-files/files/etc/uci-defaults/15_wifi-ssid-mac-address

diff --git a/package/base-files/files/etc/uci-defaults/15_wifi-ssid-mac-address b/package/base-files/files/etc/uci-defaults/15_wifi-ssid-mac-address
new file mode 100644
index 0000000000..aeb46e39c0
--- /dev/null
+++ b/package/base-files/files/etc/uci-defaults/15_wifi-ssid-mac-address
@@ -0,0 +1,22 @@
+. /lib/functions.sh
+. /lib/functions/system.sh
+set_wifi_ssid() {
+	local iface="$1"
+	[ "$(uci get "wireless.${iface}.ssid")" = "OpenWrt" ] && \
+		uci set "wireless.${iface}.ssid=$ssid"
+[ -n "$label_macaddr" ] || exit 0
+ssid="OpenWrt-$(macaddr_geteui $label_macaddr)"
+config_load wireless
+config_foreach set_wifi_ssid wifi-iface
+uci commit wireless
+exit 0

openwrt-devel mailing list
openwrt-devel at lists.openwrt.org

More information about the openwrt-devel mailing list