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

PHYNBR=${DEVPATH##*/phy}

[ -n $PHYNBR ] || exit 0

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

board=$(board_name)

case "$board" in
	asus,tuf-ax4200)
		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)
		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
		;;
	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
		;;
	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
		;;
esac
