[ "$ACTION" == "add" ] || exit 0

PHYNBR=${DEVPATH##*/phy}

[ -n $PHYNBR ] || exit 0

. /lib/functions.sh
. /lib/functions/system.sh

board=$(board_name)

case "$board" in
	glinet,gl-mt1300)
		[ "$PHYNBR" = "1" ] && \
			macaddr_add "$(mtd_get_mac_binary factory 0x4)" 1 > /sys${DEVPATH}/macaddress
		;;
	h3c,tx1800-plus|\
	h3c,tx1801-plus|\
	h3c,tx1806)
		addr=$(macaddr_setbit $(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) 2) 7)
		[ "$PHYNBR" = "0" ] && echo -n ${addr:0:9}'1'${addr:10:7} > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && echo -n ${addr:0:9}'7'${addr:10:7} > /sys${DEVPATH}/macaddress
		;;
	jcg,q20)
		[ "$PHYNBR" = "1" ] && \
			macaddr_setbit_la "$(mtd_get_mac_binary Factory 0x4)" > /sys${DEVPATH}/macaddress
		;;
	jdcloud,re-sp-01b)
		local index="$(find_mtd_index "config")"
		local label_mac=$(macaddr_canonicalize $(dd if="/dev/mtd${index}" bs=12 skip=17449 iflag=skip_bytes count=1 2>/dev/null))
		[ "$PHYNBR" -eq 0 ] && echo $label_mac > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" -eq 1 ] && macaddr_add $label_mac 0x800000 > /sys${DEVPATH}/macaddress
		;;
	linksys,e5600|\
	linksys,ea7300-v1|\
	linksys,ea7300-v2|\
	linksys,ea7500-v2|\
	linksys,ea8100-v1)
		hw_mac_addr=$(mtd_get_mac_ascii devinfo hw_mac_addr)
		[ "$PHYNBR" = "0" ] && macaddr_add $hw_mac_addr 1 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $hw_mac_addr 2 > /sys${DEVPATH}/macaddress
		;;
	raisecom,msg1500-x-00)
		[ "$PHYNBR" = "0" ] && \
			macaddr_setbit_la "$(mtd_get_mac_ascii Config protest_lan_mac)" \
				> /sys${DEVPATH}/macaddress
		;;
	totolink,x5000r)
		hw_mac_addr="$(mtd_get_mac_binary factory 0x4)"
		[ "$PHYNBR" = "1" ] &&  macaddr_add $hw_mac_addr 4 > /sys${DEVPATH}/macaddress
		;;
	yuncore,ax820)
		[ "$PHYNBR" = "1" ] && \
			macaddr_setbit_la "$(mtd_get_mac_binary Factory 0xe000)" > /sys${DEVPATH}/macaddress
		;;
esac
