[ "$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-ubootmod)
		addr=$(get_mac_label)
		[ "$PHYNBR" = "0" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_setbit_la $(macaddr_add $addr 1) > /sys${DEVPATH}/macaddress
		;;
	acer,predator-w6)
		key_path="/var/qcidata/data"
		[ "$PHYNBR" = "0" ] && cat $key_path/2gMAC > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && cat $key_path/6gMAC > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "2" ] && cat $key_path/5gMAC > /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 mutiple 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)
		addr=$(macaddr_add $(cat /sys/class/net/eth0/address) 2)
		[ "$PHYNBR" = "0" ] && macaddr_unsetbit $addr 6 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_setbit $addr 6 > /sys${DEVPATH}/macaddress
		;;
	bananapi,bpi-r3-mini)
		addr=$(macaddr_generate_from_mmc_cid mmcblk0)
		[ "$PHYNBR" = "0" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
		wifi
		;;
	cetron,ct3003-ubootmod)
		addr=$(cat /sys/class/net/eth0/address)
		[ "$PHYNBR" = "0" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress
		;;
	cmcc,a10-ubootmod|\
	cmcc,rax3000m-nand-ubootmod)
		[ "$PHYNBR" = "1" ] && mtd_get_mac_binary Factory 0xa > /sys${DEVPATH}/macaddress
		;;
	cmcc,rax3000m)
		case "$(cmdline_get_var root)" in
		/dev/mmc*)
			addr=$(mmc_get_mac_binary factory 0xa)
			;;
		*)
			addr=$(mtd_get_mac_binary factory 0xa)
			;;
		esac
		[ "$PHYNBR" = "1" ] && echo "$addr" > /sys${DEVPATH}/macaddress
		;;
	cmcc,rax3000m-emmc-ubootmod)
		[ "$PHYNBR" = "1" ] && mmc_get_mac_binary factory 0xa > /sys${DEVPATH}/macaddress
		;;
	cudy,wr3000-v1)
		addr=$(mtd_get_mac_binary bdinfo 0xde00)
		# 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" ] && echo "$addr" > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_setbit_la $(macaddr_add $addr 1) > /sys${DEVPATH}/macaddress
		;;
	glinet,gl-mt6000)
		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|\
	h3c,magic-nx30-pro-nmbm)
		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
		;;
	imou,lc-hx3001-ubootmod)
		addr=$(mtd_get_mac_ascii u-boot-env mac)
		[ -n "$addr" ] || addr=$(macaddr_add $(mtd_get_mac_binary Factory 0x4) -1)
		[ "$PHYNBR" = "0" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
		;;
	jcg,q30-ubootmod)
		[ "$PHYNBR" = "1" ] && \
			macaddr_setbit_la "$(mtd_get_mac_binary Factory 0x4)" > /sys${DEVPATH}/macaddress
		;;
	livinet,zr-3020|\
	livinet,zr-3020-ubootmod)
		[ "$PHYNBR" = "0" ] && mtd_get_mac_ascii config2 wifi2gmac > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && mtd_get_mac_ascii config2 wifi5gmac > /sys${DEVPATH}/macaddress
		;;
	mercusys,mr90x-v1)
		addr=$(get_mac_binary "/tmp/tp_data/default-mac" 0)
		[ "$PHYNBR" = "0" ] && echo "$addr" > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $addr -1 > /sys${DEVPATH}/macaddress
		;;
	netgear,wax220)
		hw_mac_addr=$(mtd_get_mac_ascii u-boot-env mac)
		[ "$PHYNBR" = "0" ] && macaddr_add $hw_mac_addr 2 > /sys${DEVPATH}/macaddress
		[ "$PHYNBR" = "1" ] && macaddr_add $hw_mac_addr 3 > /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
		;;
	qihoo,360t7-ubootmod)
		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
		;;
	tplink,tl-xdr4288|\
	tplink,tl-xdr6086|\
	tplink,tl-xdr6088)
		[ "$PHYNBR" = "0" ] && get_mac_label > /sys${DEVPATH}/macaddress
		;;
	zyxel,ex5601-t0)
		addr=$(mtd_get_mac_binary "Factory" 0x4)
		[ "$PHYNBR" = "1" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress
		;;
	zyxel,nwa50ax-pro)
		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
