[OpenWrt-Devel,2/2] base-files: rename SSID with EUI of mac address
diff mbox series

Message ID 20191108114841.1343-3-freifunk@adrianschmutzler.de
State Rejected
Delegated to: Adrian Schmutzler
Headers show
Series
  • introduce label_mac into hostname and SSID
Related show

Commit Message

Adrian Schmutzler Nov. 8, 2019, 11:48 a.m. UTC
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@rosinson.com>
Signed-off-by: Adrian Schmutzler <freifunk@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

Comments

Jonas Gorski Nov. 9, 2019, 9:37 a.m. UTC | #1
On Fri, 8 Nov 2019 at 12:49, Adrian Schmutzler
<freifunk@adrianschmutzler.de> wrote:
>
> 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.

Unfortunately since we detect wifi async these days this is quite
racy, and there is no guarantee /etc/config/wireless is fully
populated by the time the uci defaults are run. E.g. mwl8k takes quite
a while since it uses different firmwares for STA and AP modes, and it
needs to re-initialize to switch between them (triggered by by
mac80211.sh trying to detect the supporte features).


Regards
Jonas

>
> Suggested-by: Rosy Song <rosysong@rosinson.com>
> Signed-off-by: Adrian Schmutzler <freifunk@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"
> +}
> +
> +label_macaddr=$(get_mac_label)
> +
> +[ -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
> --
> 2.20.1
>
>
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Adrian Schmutzler Nov. 9, 2019, 11:04 a.m. UTC | #2
Hi,

> -----Original Message-----
> From: Jonas Gorski [mailto:jonas.gorski@gmail.com]
> Sent: Samstag, 9. November 2019 10:37
> To: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> Cc: OpenWrt Development List <openwrt-devel@lists.openwrt.org>; Rosy
> Song <rosysong@rosinson.com>
> Subject: Re: [OpenWrt-Devel] [PATCH 2/2] base-files: rename SSID with EUI
> of mac address
> 
> On Fri, 8 Nov 2019 at 12:49, Adrian Schmutzler
> <freifunk@adrianschmutzler.de> wrote:
> >
> > 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.
> 
> Unfortunately since we detect wifi async these days this is quite racy, and
> there is no guarantee /etc/config/wireless is fully populated by the time the
> uci defaults are run. E.g. mwl8k takes quite a while since it uses different
> firmwares for STA and AP modes, and it needs to re-initialize to switch
> between them (triggered by by mac80211.sh trying to detect the supporte
> features).

So, in the end, it might be like Manuel Giganto suggested in GitHub and one might
either have to wait in mac80211.sh until /etc/board.json is available (ugly) or
just put the same code (the few lines of SSID change) in both locations (uci_defaults AND mac80211.sh).

Best

Adrian

> 
> 
> Regards
> Jonas
> 
> >
> > Suggested-by: Rosy Song <rosysong@rosinson.com>
> > Signed-off-by: Adrian Schmutzler <freifunk@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-addre
> > +++ ss
> > @@ -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"
> > +}
> > +
> > +label_macaddr=$(get_mac_label)
> > +
> > +[ -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
> > --
> > 2.20.1
> >
> >
> > _______________________________________________
> > openwrt-devel mailing list
> > openwrt-devel@lists.openwrt.org
> > https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Jonas Gorski Nov. 9, 2019, 12:57 p.m. UTC | #3
On Sat, 9 Nov 2019 at 12:04, <mail@adrianschmutzler.de> wrote:
>
> Hi,
>
> > -----Original Message-----
> > From: Jonas Gorski [mailto:jonas.gorski@gmail.com]
> > Sent: Samstag, 9. November 2019 10:37
> > To: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> > Cc: OpenWrt Development List <openwrt-devel@lists.openwrt.org>; Rosy
> > Song <rosysong@rosinson.com>
> > Subject: Re: [OpenWrt-Devel] [PATCH 2/2] base-files: rename SSID with EUI
> > of mac address
> >
> > On Fri, 8 Nov 2019 at 12:49, Adrian Schmutzler
> > <freifunk@adrianschmutzler.de> wrote:
> > >
> > > 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.
> >
> > Unfortunately since we detect wifi async these days this is quite racy, and
> > there is no guarantee /etc/config/wireless is fully populated by the time the
> > uci defaults are run. E.g. mwl8k takes quite a while since it uses different
> > firmwares for STA and AP modes, and it needs to re-initialize to switch
> > between them (triggered by by mac80211.sh trying to detect the supporte
> > features).
>
> So, in the end, it might be like Manuel Giganto suggested in GitHub and one might
> either have to wait in mac80211.sh until /etc/board.json is available (ugly) or
> just put the same code (the few lines of SSID change) in both locations (uci_defaults AND mac80211.sh).

How about just generating the board.json at an earlier time before
loading the wifi drivers, so it's always there once mac80211.sh runs?

We already generate it in preinit (unless failsafe is disabled) to
configure the switch and find the proper lan if, we might as well make
it unconditional and then rely on it for mac80211.sh.


Regards
Jonas
Adrian Schmutzler Nov. 10, 2019, 9:01 p.m. UTC | #4
Hi,

> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces@lists.openwrt.org]
> On Behalf Of Jonas Gorski
> Sent: Samstag, 9. November 2019 13:57
> To: mail@adrianschmutzler.de
> Cc: OpenWrt Development List <openwrt-devel@lists.openwrt.org>; Rosy
> Song <rosysong@rosinson.com>
> Subject: Re: [OpenWrt-Devel] [PATCH 2/2] base-files: rename SSID with EUI
> of mac address
> 
> On Sat, 9 Nov 2019 at 12:04, <mail@adrianschmutzler.de> wrote:
> >
> > Hi,
> >
> > > -----Original Message-----
> > > From: Jonas Gorski [mailto:jonas.gorski@gmail.com]
> > > Sent: Samstag, 9. November 2019 10:37
> > > To: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> > > Cc: OpenWrt Development List <openwrt-devel@lists.openwrt.org>;
> Rosy
> > > Song <rosysong@rosinson.com>
> > > Subject: Re: [OpenWrt-Devel] [PATCH 2/2] base-files: rename SSID
> > > with EUI of mac address
> > >
> > > On Fri, 8 Nov 2019 at 12:49, Adrian Schmutzler
> > > <freifunk@adrianschmutzler.de> wrote:
> > > >
> > > > 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.
> > >
> > > Unfortunately since we detect wifi async these days this is quite
> > > racy, and there is no guarantee /etc/config/wireless is fully
> > > populated by the time the uci defaults are run. E.g. mwl8k takes
> > > quite a while since it uses different firmwares for STA and AP
> > > modes, and it needs to re-initialize to switch between them
> > > (triggered by by mac80211.sh trying to detect the supporte features).
> >
> > So, in the end, it might be like Manuel Giganto suggested in GitHub
> > and one might either have to wait in mac80211.sh until /etc/board.json
> > is available (ugly) or just put the same code (the few lines of SSID change)
> in both locations (uci_defaults AND mac80211.sh).
> 
> How about just generating the board.json at an earlier time before loading
> the wifi drivers, so it's always there once mac80211.sh runs?

in principle, yes. Thanks for this idea.

However, we have to be careful to not break anything in 02_network, e.g.
using $(cat /sys/class/net/eth0/address) or similar when we become too early.

I do not really have an overview of _all_ targets and what they do in 02_network or similar board.d files.

Despite, I introduced $(cat /sys/class/ieee80211/phy0/macaddress) retrieval into 02_network as workaround for the MAC address. However, I will try to change those lines to point to the proper original sources of the addresses.

> 
> We already generate it in preinit (unless failsafe is disabled) to configure the
> switch and find the proper lan if, we might as well make it unconditional and
> then rely on it for mac80211.sh.

Where would you put it?

Best

Adrian

> 
> 
> Regards
> Jonas
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Patch
diff mbox series

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"
+}
+
+label_macaddr=$(get_mac_label)
+
+[ -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