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

mediatek_setup_interfaces()
{
	local board="$1"

	case $board in
	acelink,ew-7886cax)
		ucidef_set_interface_lan "eth0" "dhcp"
		;;
	abt,asr3000|\
	cmcc,rax3000m|\
	h3c,magic-nx30-pro|\
	nokia,ea0326gmp|\
	zbtlink,zbt-z8103ax)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" eth1
		;;
	acer,predator-w6)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 game" eth1
		;;
	asus,rt-ax59u|\
	cetron,ct3003|\
	confiabits,mt7981|\
	cudy,wr3000-v1|\
	jcg,q30-pro|\
	qihoo,360t7|\
	routerich,ax3000)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" wan
		;;
	asus,tuf-ax4200|\
	jdcloud,re-cp-03|\
	mediatek,mt7981-rfb|\
	netcore,n60|\
	ruijie,rg-x60-pro|\
	unielec,u7981-01*|\
	zbtlink,zbt-z8102ax)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" eth1
		;;
	asus,tuf-ax6000)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4 lan5" eth1
		;;
	bananapi,bpi-r3)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4 sfp2" "eth1 wan"
		;;
	bananapi,bpi-r3-mini|\
	edgecore,eap111)
		ucidef_set_interfaces_lan_wan eth0 eth1
		;;
	bananapi,bpi-r4|\
	bananapi,bpi-r4-poe)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 eth1" "wan eth2"
		;;
	comfast,cf-e393ax)
		ucidef_set_interfaces_lan_wan "lan1" eth1
		;;
	cudy,m3000-v1|\
	cudy,tr3000-v1|\
	glinet,gl-mt2500|\
	glinet,gl-mt3000|\
	glinet,gl-x3000|\
	glinet,gl-xe3000|\
	openembed,som7981|\
	openwrt,one)
		ucidef_set_interfaces_lan_wan eth1 eth0
		;;
	dlink,aquila-pro-ai-m30-a1)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" internet
		;;
	glinet,gl-mt6000|\
	tplink,tl-xdr4288|\
	tplink,tl-xdr6088|\
	tplink,tl-xtr8488)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4 lan5" 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-rfb)
		ucidef_set_interfaces_lan_wan "lan0 lan1 lan2 lan3 eth1" eth2
		;;
	mercusys,mr90x-v1)
		ucidef_set_interfaces_lan_wan "lan0 lan1 lan2" eth1
		;;
	cudy,re3000-v1|\
	netgear,wax220|\
	ubnt,unifi-6-plus|\
	zyxel,nwa50ax-pro)
		ucidef_set_interface_lan "eth0"
		;;
	smartrg,sdg-8622|\
	smartrg,sdg-8632|\
	yuncore,ax835)
		ucidef_set_interfaces_lan_wan lan wan
		;;
	tplink,tl-xdr6086|\
	wavlink,wl-wn586x3)
		ucidef_set_interfaces_lan_wan "lan1 lan2" eth1
		;;
	tplink,re6000xd)
		ucidef_set_interface_lan "lan1 lan2 eth1"
		;;
	xiaomi,mi-router-ax3000t|\
	xiaomi,mi-router-ax3000t-ubootmod|\
	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
		;;
	zyxel,ex5601-t0-stock|\
	zyxel,ex5601-t0-ubootmod)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" eth1
		;;
	*)
		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
	bananapi,bpi-r3|\
	bananapi,bpi-r3-mini|\
	bananapi,bpi-r4)
		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|\
	tplink,re6000xd)
		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
		;;
	ruijie,rg-x60-pro)
		label_mac=$(mtd_get_mac_ascii product_info ethaddr)
		wan_mac=$label_mac
		lan_mac=$(macaddr_add "$label_mac" 1)
		;;
	smartrg,sdg-8612|\
	smartrg,sdg-8614|\
	smartrg,sdg-8622|\
	smartrg,sdg-8632|\
	smartrg,sdg-8733|\
	smartrg,sdg-8734)
		label_mac=$(mmc_get_mac_ascii mfginfo MFG_MAC)
		wan_mac=$label_mac
		lan_mac=$(macaddr_add "$label_mac" 1)
		;;
	xiaomi,mi-router-ax3000t|\
	xiaomi,mi-router-ax3000t-ubootmod|\
	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
		;;
	yuncore,ax835)
		label_mac=$(mtd_get_mac_binary "Factory" 0x4)
		;;
	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
