diff options
author | Gabor Juhos <juhosg@openwrt.org> | 2013-02-16 11:50:19 +0000 |
---|---|---|
committer | Gabor Juhos <juhosg@openwrt.org> | 2013-02-16 11:50:19 +0000 |
commit | 34fe9af0472041f32d393e5e755559bd0bd4f9d8 (patch) | |
tree | 676a9a421d48ddffa82f360a6e646ba7699bf7c9 /package/base-files/files/lib | |
parent | 8fec1177bfee532d9d351a11d0636f237ee835af (diff) | |
download | upstream-34fe9af0472041f32d393e5e755559bd0bd4f9d8.tar.gz upstream-34fe9af0472041f32d393e5e755559bd0bd4f9d8.tar.bz2 upstream-34fe9af0472041f32d393e5e755559bd0bd4f9d8.zip |
base-files: add mtd_get_mac_{ascii,binary} helpers
Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@35612 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/base-files/files/lib')
-rwxr-xr-x | package/base-files/files/lib/functions.sh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh index ae0257a5c5..2022e8a3aa 100755 --- a/package/base-files/files/lib/functions.sh +++ b/package/base-files/files/lib/functions.sh @@ -240,6 +240,40 @@ find_mtd_chardev() { echo "${INDEX:+$PREFIX$INDEX}" } +mtd_get_mac_ascii() +{ + local mtdname="$1" + local key="$2" + local part + local mac_dirty + + . /lib/functions.sh + + part=$(find_mtd_part "$mtdname") + if [ -z "$part" ]; then + echo "mtd_get_mac_ascii: partition $mtdname not found!" >&2 + return + fi + + mac_dirty=$(strings "$part" | sed -n 's/'"$key"'=//p') + # "canonicalize" mac + printf "%02x:%02x:%02x:%02x:%02x:%02x" 0x${mac_dirty//:/ 0x} +} + +mtd_get_mac_binary() { + local mtdname="$1" + local offset="$2" + local part + + part=$(find_mtd_part "$mtdname") + if [ -z "$part" ]; then + echo "mtd_get_mac_binary: partition $mtdname not found!" >&2 + return + fi + + dd bs=1 skip=$offset count=6 if=$part 2>/dev/null | hexdump -v -n 6 -e '5/1 "%02x:" 1/1 "%02x"' +} + strtok() { # <string> { <variable> [<separator>] ... } local tmp local val="$1" |