1 # Copyright (C) 2006-2013 OpenWrt.org
4 local INDEX
=$
(find_mtd_index
"$1")
7 [ -d /dev
/mtd
] && PREFIX
=/dev
/mtd
/
8 echo "${INDEX:+$PREFIX$INDEX}"
18 part
=$
(find_mtd_part
"$mtdname")
19 if [ -z "$part" ]; then
20 echo "mtd_get_mac_ascii: partition $mtdname not found!" >&2
24 mac_dirty
=$
(strings "$part" |
sed -n 's/^'"$key"'=//p')
27 [ -n "$mac_dirty" ] && macaddr_canonicalize
"$mac_dirty"
30 mtd_get_mac_binary
() {
35 part
=$
(find_mtd_part
"$mtdname")
36 if [ -z "$part" ]; then
37 echo "mtd_get_mac_binary: partition $mtdname not found!" >&2
41 dd bs
=1 skip
=$offset count
=6 if=$part 2>/dev
/null |
hexdump -v -n 6 -e '5/1 "%02x:" 1/1 "%02x"'
46 local first dev size erasesize name
47 while read dev size erasesize name
; do
48 name
=${name#'"'}; name
=${name%'"'}
49 if [ "$name" = "$part_name" ]; then
59 local oui
=${mac%:*:*:*}
60 local nic
=${mac#*:*:*:}
62 nic
=$
(printf "%06x" $
((0x
${nic//:/} + $val & 0xffffff)) |
sed 's/^\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)/\1:\2:\3/')
70 printf "%02x:%s" $
((0x
${mac%%:*} |
0x02)) ${mac#*:}
77 echo -ne \\x
${mac//:/\\x}
80 macaddr_canonicalize
()
85 [ ${#mac} -gt 17 ] && return
86 [ -n "${mac//[a-fA-F0-9\.: -]/}" ] && return
88 for octet
in ${mac//[\.:-]/ }; do
96 octet
="${octet:0:2} ${octet:2:2}"
99 octet
="${octet:0:2} ${octet:2:2} ${octet:4:2} ${octet:6:2} ${octet:8:2} ${octet:10:2}"
105 canon
=${canon}${canon:+ }${octet}
108 [ ${#canon} -ne 17 ] && return
110 printf "%02x:%02x:%02x:%02x:%02x:%02x" 0x
${canon// / 0x} 2>/dev
/null