
. /lib/functions.sh
. /lib/functions/uci-defaults.sh
. /lib/functions/system.sh

mediatek_setup_interfaces()
{
	local board="$1"

	case $board in
	acer,predator-w6)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 game" eth1
		;;
	asus,tuf-ax4200)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" eth1
		;;
	netgear,wax220|\
	zyxel,nwa50ax-pro)
		ucidef_set_interface_lan "eth0"
		;;
	bananapi,bpi-r3)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4 sfp2" "eth1 wan"
		;;
	cudy,wr3000-v1)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" "wan"
		;;
	glinet,gl-mt3000)
		ucidef_set_interfaces_lan_wan eth1 eth0
		;;
	h3c,magic-nx30-pro)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" eth1
		;;
	mediatek,mt7986a-rfb)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4 lan6" "eth1 wan"
		;;
	mediatek,mt7986b-rfb)
		ucidef_set_interfaces_lan_wan "lan0 lan1 lan2 lan3" eth1
		;;
	mediatek,mt7988a-dsa-10g-spim-snand)
		ucidef_set_interfaces_lan_wan "lan0 lan1 lan2 lan3" "eth1 eth2"
		;;
	mercusys,mr90x-v1)
		ucidef_set_interfaces_lan_wan "lan0 lan1 lan2" eth1
		;;
	qihoo,360t7)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" wan
		;;
	tplink,tl-xdr4288|\
	tplink,tl-xdr6088)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4 lan5" eth1
		;;
	tplink,tl-xdr6086)
		ucidef_set_interfaces_lan_wan "lan1 lan2" eth1
		;;
	xiaomi,mi-router-wr30u-112m-nmbm|\
	xiaomi,mi-router-wr30u-stock|\
	xiaomi,mi-router-wr30u-ubootmod|\
	xiaomi,redmi-router-ax6000-stock|\
	xiaomi,redmi-router-ax6000-ubootmod)
		ucidef_set_interfaces_lan_wan "lan2 lan3 lan4" wan
		;;
	*)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" wan
		;;
	esac
}

mediatek_setup_macs()
{
	local board="$1"
	local lan_mac=""
	local wan_mac=""
	local label_mac=""

	case $board in
	asus,tuf-ax4200)
		CI_UBIPART="UBI_DEV"
		addr=$(mtd_get_mac_binary_ubi "Factory" 0x4)
		wan_mac="${addr}"
		lan_mac="${addr}"
		;;
	bananapi,bpi-r3)
		wan_mac=$(macaddr_add $(cat /sys/class/net/eth0/address) 1)
		;;
	h3c,magic-nx30-pro)
		wan_mac=$(mtd_get_mac_ascii pdt_data_1 ethaddr)
		lan_mac=$(macaddr_add "$wan_mac" 1)
		label_mac=$wan_mac
		;;
	mercusys,mr90x-v1)
		label_mac=$(get_mac_binary "/tmp/tp_data/default-mac" 0)
		lan_mac=$label_mac
		;;
	netgear,wax220)
		lan_mac=$(mtd_get_mac_ascii u-boot-env mac)
		label_mac=$lan_mac
		;;
	qihoo,360t7)
		lan_mac=$(mtd_get_mac_ascii factory lanMac)
		wan_mac=$(macaddr_add "$lan_mac" 1)
		label_mac=$wan_mac
		;;
	xiaomi,mi-router-wr30u-112m-nmbm|\
	xiaomi,mi-router-wr30u-stock|\
	xiaomi,mi-router-wr30u-ubootmod|\
	xiaomi,redmi-router-ax6000-stock|\
	xiaomi,redmi-router-ax6000-ubootmod)
		wan_mac=$(mtd_get_mac_ascii Bdata ethaddr_wan)
		label_mac=$wan_mac
		;;
	esac

	[ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
	[ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
	[ -n "$label_mac" ] && ucidef_set_label_macaddr $label_mac
}

board_config_update
board=$(board_name)
mediatek_setup_interfaces $board
mediatek_setup_macs $board
board_config_flush

exit 0
