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

PHYNBR=${DEVPATH##*/phy}

[ -n $PHYNBR ] || exit 0

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

board=$(board_name)

case "$board" in
	abt,asr3000)
		addr=$(mtd_get_mac_binary "art" 0x6)
		[ "$PHYNBR" = "1" ] && \
			macaddr_setbit_la "$(macaddr_add $addr 0x600000)" > /sys${DEVPATH}/macaddress
		;;
	asus,tuf-ax4200|\
	asus,tuf-ax6000)
		CI_UBIPART="UBI_DEV"
		addr=$(mtd_get_mac_binary_ubi "Factory" 0x4)
		# Originally, phy0 is phy1 mac with LA bit set. However, this would conflict
		# addresses on multiple VIFs with the other radio. Set LA bit and increment
		# mac-address instead.
		[ "$PHYNBR" = "0" ] && macaddr_setbit_la $(macaddr_add $addr 1) > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && echo "$addr" > /sys${DEVPATH}/macaddress
		;;
	bananapi,bpi-r3|\
	bananapi,bpi-r3-mini)
		addr=$(cat /sys/class/net/eth0/address)
		[ "$PHYNBR" = "0" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
		;;
	bananapi,bpi-r4|\
	bananapi,bpi-r4-2g5|\
	bananapi,bpi-r4-poe)
		addr=$(cat /sys/class/net/eth0/address)
		[ "$PHYNBR" = "0" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "2" ] && macaddr_add $addr 4 > /sys${DEVPATH}/macaddress
		;;
	cetron,ct3003*)
		addr=$(mtd_get_mac_binary "art" 0)
		[ "$PHYNBR" = "0" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_setbit_la $(macaddr_add $addr 2) > /sys${DEVPATH}/macaddress
		;;
	cudy,tr3000*)
		addr=$(mtd_get_mac_binary bdinfo 0xde00)
		[ "$PHYNBR" = "0" ] && echo "$addr" > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_setbit_la $(macaddr_add $addr 1) > /sys${DEVPATH}/macaddress
		;;
	glinet,gl-mt6000|\
	glinet,gl-x3000|\
	glinet,gl-xe3000|\
	huasifei,wh3000-emmc)
		addr=$(mmc_get_mac_binary factory 0x04)
		[ "$PHYNBR" = "0" ] && echo "$addr" > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress
		;;
	h3c,magic-nx30-pro)
		addr=$(mtd_get_mac_ascii pdt_data_1 ethaddr)
		[ "$PHYNBR" = "0" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
		;;
	huasifei,ws3006)
		addr=$(mtd_get_mac_binary Factory 0x04)
		[ "$PHYNBR" = "1" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress
		;;
	imou,lc-hx3001)
		addr=$(mtd_get_mac_ascii u-boot-env mac)
		[ "$PHYNBR" = "0" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
		;;
	jcg,q30-pro|\
	netcore,n60|\
	netcore,n60-pro)
		# Originally, phy1 is phy0 mac with LA bit set. However, this would conflict
		# addresses on multiple VIFs with the other radio. Use label mac to set LA bit.
		[ "$PHYNBR" = "1" ] && macaddr_setbit_la $(get_mac_label) > /sys${DEVPATH}/macaddress
		;;
	konka,komi-a31)
		addr=$(mtd_get_mac_binary factory 0x2a)
		[ "$PHYNBR" = "0" ] && echo "$addr" > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress
		;;
	nokia,ea0326gmp)
		addr=$(mtd_get_mac_binary Factory 0x28)
		[ "$PHYNBR" = "1" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress
		;;
	openembed,som7981)
		[ "$PHYNBR" = "1" ] && cat /sys/class/net/eth0/address > /sys${DEVPATH}/macaddress
		;;
	qihoo,360t7)
		addr=$(mtd_get_mac_ascii factory lanMac)
		[ "$PHYNBR" = "0" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
		;;
	ruijie,rg-x60-pro)
		addr=$(mtd_get_mac_ascii product_info ethaddr)
		[ "$PHYNBR" = "0" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
		;;
	tplink,tl-xdr4288|\
	tplink,tl-xdr6086|\
	tplink,tl-xdr6088)
		[ "$PHYNBR" = "1" ] && macaddr_add $(get_mac_label) 2 > /sys${DEVPATH}/macaddress
		;;
	tplink,tl-xtr8488)
		[ "$PHYNBR" = "2" ] && macaddr_add $(get_mac_label) 2 > /sys${DEVPATH}/macaddress
		;;
esac
