From 0340718863040919ecaba74b2173ed52ebc194ce Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Thu, 15 Aug 2019 15:13:21 +0200 Subject: [PATCH] base-files: add function to retrieve label MAC address To refer to the MAC address on a device's label, one can specify the alias label-mac-device in the DTS which should point to the bearer of the corresponding MAC address. With the function get_mac_label, the user can retrieve then retrieve this address and use it as a value that uniquely identifies his device. This is severely helpful for several downstream functionalities, e.g. define MAC addresses of custom netifs or change the SSID to be easily recognizable. Signed-off-by: Adrian Schmutzler --- package/base-files/files/lib/functions/system.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh index 5084c0052bab..3051ac8476cc 100644 --- a/package/base-files/files/lib/functions/system.sh +++ b/package/base-files/files/lib/functions/system.sh @@ -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 -- 2.30.2