base-files: add function to retrieve label MAC address
[openwrt/staging/mkresin.git] / package / base-files / files / lib / functions / system.sh
index 5084c0052babdf3d9078b1c3058100e3aa6931ba..3051ac8476cc1e35e517828756b7cc58a76124ae 100644 (file)
@@ -12,6 +12,16 @@ get_mac_binary() {
        hexdump -v -n 6 -s $offset -e '5/1 "%02x:" 1/1 "%02x"' $path 2>/dev/null
 }
 
+get_mac_label() {
+       local basepath="/proc/device-tree"
+       local macdevice="$(cat "$basepath/aliases/label-mac-device" 2>/dev/null)"
+       local macaddr
+
+       [ -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)
+       echo $macaddr
+}
+
 find_mtd_chardev() {
        local INDEX=$(find_mtd_index "$1")
        local PREFIX=/dev/mtd