1 # Copyright (C) 2006-2013 OpenWrt.org
7 if ! [ -e "$path" ]; then
8 echo "get_mac_binary: file $path not found!" >&2
12 hexdump -v -n 6 -s $offset -e '5/1 "%02x:" 1/1 "%02x"' $path 2>/dev
/null
16 local basepath
="/proc/device-tree"
17 local macdevice
="$(cat "$basepath/aliases
/label-mac-device
" 2>/dev/null)"
20 [ -n "$macdevice" ] && macaddr
=$
(get_mac_binary
"$basepath/$macdevice/mac-address" 0 2>/dev
/null
)
21 [ -n "$macaddr" ] || macaddr
=$
(get_mac_binary
"$basepath/$macdevice/local-mac-address" 0 2>/dev
/null
)
26 local INDEX
=$
(find_mtd_index
"$1")
29 [ -d /dev
/mtd
] && PREFIX
=/dev
/mtd
/
30 echo "${INDEX:+$PREFIX$INDEX}"
39 part
=$
(find_mtd_part
"$mtdname")
40 if [ -z "$part" ]; then
41 echo "mtd_get_mac_ascii: partition $mtdname not found!" >&2
45 mac_dirty
=$
(strings "$part" |
sed -n 's/^'"$key"'=//p')
48 [ -n "$mac_dirty" ] && macaddr_canonicalize
"$mac_dirty"
57 part
=$
(find_mtd_part
"$mtdname")
58 if [ -z "$part" ]; then
59 echo "mtd_get_mac_text: partition $mtdname not found!" >&2
63 if [ -z "$offset" ]; then
64 echo "mtd_get_mac_text: offset missing!" >&2
68 mac_dirty
=$
(dd if="$part" bs
=1 skip
="$offset" count
=17 2>/dev
/null
)
71 [ -n "$mac_dirty" ] && macaddr_canonicalize
"$mac_dirty"
74 mtd_get_mac_binary
() {
79 part
=$
(find_mtd_part
"$mtdname")
80 get_mac_binary
"$part" "$offset"
83 mtd_get_mac_binary_ubi
() {
87 .
/lib
/upgrade
/nand.sh
89 local ubidev
=$
(nand_find_ubi
$CI_UBIPART)
90 local part
=$
(nand_find_volume
$ubidev $1)
92 get_mac_binary
"/dev/$part" "$offset"
97 local first dev size erasesize name
98 while read dev size erasesize name
; do
99 name
=${name#'"'}; name
=${name%'"'}
100 if [ "$name" = "$part_name" ]; then
110 local oui
=${mac%:*:*:*}
111 local nic
=${mac#*:*:*:}
113 nic
=$
(printf "%06x" $
((0x
${nic//:/} + $val & 0xffffff)) |
sed 's/^\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)/\1:\2:\3/')
117 macaddr_setbit_la
() {
120 printf "%02x:%s" $
((0x
${mac%%:*} |
0x02)) ${mac#*:}
126 echo -ne \\x
${mac//:/\\x}
129 macaddr_canonicalize
() {
133 mac
=$
(echo -n $mac |
tr -d \")
134 [ ${#mac} -gt 17 ] && return
135 [ -n "${mac//[a-fA-F0-9\.: -]/}" ] && return
137 for octet
in ${mac//[\.:-]/ }; do
145 octet
="${octet:0:2} ${octet:2:2}"
148 octet
="${octet:0:2} ${octet:2:2} ${octet:4:2} ${octet:6:2} ${octet:8:2} ${octet:10:2}"
154 canon
=${canon}${canon:+ }${octet}
157 [ ${#canon} -ne 17 ] && return
159 printf "%02x:%02x:%02x:%02x:%02x:%02x" 0x
${canon// / 0x} 2>/dev
/null