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

PHYNBR=${DEVPATH##*/phy}

[ -n $PHYNBR ] || exit 0

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

board=$(board_name)

case "$board" in
	beeline,smartbox-flash)
		hw_mac_addr=$(macaddr_add $(mtd_get_mac_encrypted_arcadyan "board_data") 1)
		[ "$PHYNBR" = "0" ] && echo -n "$hw_mac_addr" > /sys${DEVPATH}/macaddress
		hw_mac_addr=$(macaddr_setbit   $hw_mac_addr 26)
		hw_mac_addr=$(macaddr_unsetbit $hw_mac_addr 27)
		hw_mac_addr=$(macaddr_unsetbit $hw_mac_addr 28)
		[ "$PHYNBR" = "1" ] && macaddr_setbit_la $hw_mac_addr > /sys${DEVPATH}/macaddress
		;;
	cudy,x6)
		hw_mac_addr="$(mtd_get_mac_binary factory 0x4)"
		macaddr_add $hw_mac_addr "$PHYNBR" > /sys${DEVPATH}/macaddress
		;;
	dlink,dir-853-a3)
		[ "$PHYNBR" = "0" ] && \
			macaddr_setbit_la "$(mtd_get_mac_binary factory 0xe000)" \
				> /sys${DEVPATH}/macaddress
		;;
	dlink,dir-853-r1|\
	phicomm,k2p)
		if [ "$PHYNBR" = "0" ]; then
			base_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x4)" -1)
			macaddr_setbit_la "$base_mac" > /sys${DEVPATH}/macaddress
		fi
		;;
	glinet,gl-mt1300)
		[ "$PHYNBR" = "1" ] && \
			macaddr_add "$(mtd_get_mac_binary factory 0x4)" 1 > /sys${DEVPATH}/macaddress
		;;
	iptime,a3002mesh|\
	iptime,a3004t)
		hw_mac_addr="$(mtd_get_mac_binary factory 0x4)"
		[ "$PHYNBR" = "0" ] && \
			macaddr_setbit_la "$(macaddr_add $hw_mac_addr 3)" > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && echo -n "$hw_mac_addr" > /sys${DEVPATH}/macaddress
		;;
	iptime,ax2004m)
		if [ "$PHYNBR" = "1" ]; then
			hw_mac_addr="$(mtd_get_mac_binary factory 0x4)"
			macaddr_setbit_la "$(macaddr_add $hw_mac_addr 3)" > /sys${DEVPATH}/macaddress
		fi
		;;
	jcg,q20)
		[ "$PHYNBR" = "1" ] && \
			macaddr_setbit_la "$(mtd_get_mac_binary Factory 0x4)" > /sys${DEVPATH}/macaddress
		;;
	jcg,y2)
		[ "$PHYNBR" = "1" ] && \
			macaddr_setbit_la "$(mtd_get_mac_binary factory 0x4)" > /sys${DEVPATH}/macaddress
		;;
	linksys,e5600|\
	linksys,ea6350-v4|\
	linksys,ea7300-v1|\
	linksys,ea7300-v2|\
	linksys,ea7500-v2|\
	linksys,ea8100-v1|\
	linksys,ea8100-v2)
		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
		;;
	netgear,wax202)
		hw_mac_addr=$(mtd_get_mac_ascii Config mac)
		[ "$PHYNBR" = "0" ] && macaddr_add $hw_mac_addr 2 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $hw_mac_addr 3 > /sys${DEVPATH}/macaddress
		;;
	mercusys,mr70x-v1|\
	tplink,archer-ax23-v1)
		hw_mac_addr="$(mtd_get_mac_binary config 0x8)"
		[ "$PHYNBR" = "1" ] &&  macaddr_add "$hw_mac_addr" -1 > "/sys${DEVPATH}/macaddress"
		;;
	mts,wg430223)
		hw_mac_addr=$(macaddr_add $(mtd_get_mac_encrypted_arcadyan "board_data") 1)
		[ "$PHYNBR" = "0" ] && echo -n "$hw_mac_addr" > /sys${DEVPATH}/macaddress
		hw_mac_addr=$(macaddr_unsetbit $hw_mac_addr 26)
		hw_mac_addr=$(macaddr_setbit   $hw_mac_addr 27)
		hw_mac_addr=$(macaddr_unsetbit $hw_mac_addr 28)
		[ "$PHYNBR" = "1" ] && macaddr_setbit_la $hw_mac_addr > /sys${DEVPATH}/macaddress
		;;
	oraybox,x3a)
		if [ "$PHYNBR" = "1" ]; then
			hw_mac_addr="$(mtd_get_mac_binary factory 0x4)"
			macaddr_setbit_la "$(macaddr_add $hw_mac_addr 0x100000)" > /sys${DEVPATH}/macaddress
		fi
		;;
	raisecom,msg1500-x-00)
		[ "$PHYNBR" = "0" ] && \
			macaddr_setbit_la "$(mtd_get_mac_ascii Config protest_lan_mac)" \
				> /sys${DEVPATH}/macaddress
		;;
	tenbay,t-mb5eu-v01)
		hw_mac_addr="$(mtd_get_mac_binary factory 0x4)"
		[ "$PHYNBR" = "1" ] &&  macaddr_add $hw_mac_addr "0x100000" > /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
		;;
	tplink,eap615-wall-v1)
		hw_mac_addr="$(mtd_get_mac_binary product-info 0x8)"
		macaddr_add "$hw_mac_addr" "$PHYNBR" > "/sys${DEVPATH}/macaddress"
		;;
	yuncore,ax820)
		[ "$PHYNBR" = "1" ] && \
			macaddr_setbit_la "$(mtd_get_mac_binary Factory 0xe000)" > /sys${DEVPATH}/macaddress
		;;
	zyxel,nwa50ax|\
	zyxel,nwa55axe)
		hw_mac_addr="$(mtd_get_mac_binary mrd 0x1fff8)"
		[ "$PHYNBR" = "0" ] && macaddr_add $hw_mac_addr 1 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $hw_mac_addr 2 > /sys${DEVPATH}/macaddress
		;;
esac
