base-files: provide option to specify label MAC address in board.d
authorAdrian Schmutzler <freifunk@adrianschmutzler.de>
Thu, 15 Aug 2019 13:13:27 +0000 (15:13 +0200)
committerPetr Štetiar <ynezz@true.cz>
Thu, 19 Sep 2019 21:43:27 +0000 (23:43 +0200)
For many devices, MAC addresses cannot be retrieved via the
device tree alias.

To still provide the label MAC address for those, this implements
a second mechanism that will put the address into uci config.
Note that this stores the actual MAC address, whereas in DTS
we reference the bearing device.

This is based on the work of Rosy Song <rosysong@rosinson.com>

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
package/base-files/files/bin/config_generate
package/base-files/files/lib/functions/system.sh
package/base-files/files/lib/functions/uci-defaults.sh

index 3ca035ca8b20d460644698636a025b6b5e3e2e5d..0b26afe57f445cd2fee145166826b0a27ad0fcb0 100755 (executable)
@@ -260,6 +260,11 @@ generate_static_system() {
                                uci -q set "system.@system[-1].hostname=$hostname"
                        fi
 
+                       local label_macaddr
+                       if json_get_var label_macaddr label_macaddr; then
+                               uci -q set "system.@system[-1].label_macaddr=$label_macaddr"
+                       fi
+
                        if json_is_a ntpserver array; then
                                local keys key
                                json_get_keys keys ntpserver
index 3051ac8476cc1e35e517828756b7cc58a76124ae..cb0508fe9cd84ba49dfd777c7ba7fc6820f7ad2f 100644 (file)
@@ -19,6 +19,7 @@ get_mac_label() {
 
        [ -n "$macdevice" ] && macaddr=$(get_mac_binary "$basepath/$macdevice/mac-address" 0 2>/dev/null)
        [ -n "$macaddr" ] || macaddr=$(get_mac_binary "$basepath/$macdevice/local-mac-address" 0 2>/dev/null)
+       [ -n "$macaddr" ] || macaddr=$(uci -q get system.@system[0].label_macaddr)
        echo $macaddr
 }
 
index 2fb7555969850eb0af2d181dd721980a0606c42b..c2c6dc3fdc241528fdd45a93aada4faf88460b26 100755 (executable)
@@ -307,6 +307,14 @@ ucidef_set_interface_macaddr() {
        ucidef_set_interface "$network" macaddr "$macaddr"
 }
 
+ucidef_set_label_macaddr() {
+       local macaddr="$1"
+
+       json_select_object system
+               json_add_string label_macaddr "$macaddr"
+       json_select ..
+}
+
 ucidef_add_atm_bridge() {
        local vpi="$1"
        local vci="$2"