summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabor Juhos <juhosg@openwrt.org>2013-02-16 11:50:19 +0000
committerGabor Juhos <juhosg@openwrt.org>2013-02-16 11:50:19 +0000
commit70d40b2ddd2dd38f8528ba5a8067d17deb27eb9e (patch)
tree438d2083a832e0feae231c170c9393b89403d34c
parentdd77663fb01538888918f5861546005f6f240143 (diff)
downloadmtk-20170518-70d40b2ddd2dd38f8528ba5a8067d17deb27eb9e.zip
mtk-20170518-70d40b2ddd2dd38f8528ba5a8067d17deb27eb9e.tar.gz
mtk-20170518-70d40b2ddd2dd38f8528ba5a8067d17deb27eb9e.tar.bz2
base-files: add mtd_get_mac_{ascii,binary} helpers
Signed-off-by: Gabor Juhos <juhosg@openwrt.org> SVN-Revision: 35612
-rw-r--r--package/base-files/Makefile2
-rwxr-xr-xpackage/base-files/files/lib/functions.sh34
2 files changed, 35 insertions, 1 deletions
diff --git a/package/base-files/Makefile b/package/base-files/Makefile
index 99db435..26fa1b7 100644
--- a/package/base-files/Makefile
+++ b/package/base-files/Makefile
@@ -11,7 +11,7 @@ include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/version.mk
PKG_NAME:=base-files
-PKG_RELEASE:=131
+PKG_RELEASE:=132
PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
PKG_BUILD_DEPENDS:=opkg/host
diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh
index ae0257a..2022e8a 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"