diff options
author | Mathias Kresin <dev@kresin.me> | 2018-08-11 10:10:21 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-12-18 11:01:56 +0100 |
commit | d93bd72a9806e771f2d0d0578c610ac8bd4e45a0 (patch) | |
tree | 8816ed2f95abcd97e01a9b529fe400b4cec1ac40 /package/base-files/files | |
parent | 54278dfa69380cb84dce12438fd7057ca0634d85 (diff) | |
download | upstream-d93bd72a9806e771f2d0d0578c610ac8bd4e45a0.tar.gz upstream-d93bd72a9806e771f2d0d0578c610ac8bd4e45a0.tar.bz2 upstream-d93bd72a9806e771f2d0d0578c610ac8bd4e45a0.zip |
base-files: add function to get mac as text from flash
Add a function to get a mac stored as text from flash. The octets of
the mac address need to be separated by any separator supported by
macaddr_canonicalize().
Signed-off-by: Dmitry Tunin <hanipouspilot@gmail.com>
Signed-off-by: Mathias Kresin <dev@kresin.me>
(backported from dfee452713e6b3c10aafc6174f8087a920b54402)
Diffstat (limited to 'package/base-files/files')
-rw-r--r-- | package/base-files/files/lib/functions/system.sh | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh index e178f26f39..7ed62804a0 100644 --- a/package/base-files/files/lib/functions/system.sh +++ b/package/base-files/files/lib/functions/system.sh @@ -38,6 +38,29 @@ mtd_get_mac_ascii() { [ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty" } +mtd_get_mac_text() { + local mtdname=$1 + local offset=$2 + local part + local mac_dirty + + part=$(find_mtd_part "$mtdname") + if [ -z "$part" ]; then + echo "mtd_get_mac_text: partition $mtdname not found!" >&2 + return + fi + + if [ -z "$offset" ]; then + echo "mtd_get_mac_text: offset missing!" >&2 + return + fi + + mac_dirty=$(dd if="$part" bs=1 skip="$offset" count=17 2>/dev/null) + + # "canonicalize" mac + [ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty" +} + mtd_get_mac_binary() { local mtdname="$1" local offset="$2" |