# Copyright (C) 2006-2013 OpenWrt.org
local INDEX=$(find_mtd_index "$1")
[ -d /dev/mtd ] && PREFIX=/dev/mtd/
echo "${INDEX:+$PREFIX$INDEX}"
part=$(find_mtd_part "$mtdname")
echo "mtd_get_mac_ascii: partition $mtdname not found!" >&2
mac_dirty=$(strings "$part" | sed -n 's/^'"$key"'=//p')
[ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty"
part=$(find_mtd_part "$mtdname")
echo "mtd_get_mac_binary: partition $mtdname not found!" >&2
dd bs=1 skip=$offset count=6 if=$part 2>/dev/null | hexdump -v -n 6 -e '5/1 "%02x:" 1/1 "%02x"'
local first dev size erasesize name
while read dev size erasesize name; do
name=${name#'"'}; name=${name%'"'}
if [ "$name" = "$part_name" ]; then
nic=$(printf "%06x" $((0x${nic//:/} + $val & 0xffffff)) | sed 's/^\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)/\1:\2:\3/')
printf "%02x:%s" $((0x${mac%%:*} | 0x02)) ${mac#*:}
echo -ne \\x${mac//:/\\x}
mac=$(echo -n $mac | tr -d \")
[ ${#mac} -gt 17 ] && return
[ -n "${mac//[a-fA-F0-9\.: -]/}" ] && return
for octet in ${mac//[\.:-]/ }; do
octet="${octet:0:2} ${octet:2:2}"
octet="${octet:0:2} ${octet:2:2} ${octet:4:2} ${octet:6:2} ${octet:8:2} ${octet:10:2}"
canon=${canon}${canon:+ }${octet}
[ ${#canon} -ne 17 ] && return
printf "%02x:%02x:%02x:%02x:%02x:%02x" 0x${canon// / 0x} 2>/dev/null
local PART=$(grep "0:ART" /proc/mtd | awk -F: '{print $1}')
local fac_mac="00:00:00:00:00:00"
local INDEX="${PART##mtd}"
if [ "$fac_mac" == "00:00:00:00:00:00" ]; then
fac_mac="5C:B1:5F:71:00:00"
elif [ "$fac_mac" == "ff:ff:ff:ff:ff:ff" ]; then
fac_mac="5C:B1:5F:71:00:00"