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

mediatek_setup_interfaces()
{
	local board="$1"

	case $board in
	abt,asr3000|\
	cmcc,rax3000m|\
	cmcc,rax3000me|\
	h3c,magic-nx30-pro|\
	h3c,magic-nx30-pro-nmbm|\
	imou,lc-hx3001|\
	konka,komi-a31|\
	nokia,ea0326gmp|\
	zbtlink,zbt-z8103ax)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" eth1
		;;
	acelink,ew-7886cax)
		ucidef_set_interface_lan "eth0" "dhcp"
		;;
	acer,predator-w6|\
	acer,predator-w6d)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 game" eth1
		;;
	acer,vero-w6m)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" internet
		;;
	arcadyan,mozart)
		ucidef_set_interfaces_lan_wan "lan0 eth1" eth2
		;;
	asus,rt-ax59u|\
	cetron,ct3003|\
	cetron,ct3003-ubootmod|\
	cmcc,a10-stock|\
	cmcc,a10-ubootmod|\
	confiabits,mt7981|\
	cudy,wr3000-v1|\
	jcg,q30-pro|\
	keenetic,kn-3811|\
	livinet,zr-3020|\
	livinet,zr-3020-ubootmod|\
	qihoo,360t7|\
	routerich,ax3000|\
	routerich,ax3000-ubootmod|\
	tenbay,wr3000k)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" wan
		;;
	asus,tuf-ax4200|\
	jdcloud,re-cp-03|\
	mediatek,mt7981-rfb|\
	netcore,n60|\
	netcore,n60-pro|\
	nradio,c8-668gl|\
	ruijie,rg-x60-pro|\
	unielec,u7981-01*|\
	zbtlink,zbt-z8102ax|\
	zyxel,ex5601-t0-stock|\
	zyxel,ex5601-t0-ubootmod)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" eth1
		;;
	asus,tuf-ax6000|\
	glinet,gl-mt6000|\
	tplink,tl-xdr4288|\
	tplink,tl-xdr6088|\
	tplink,tl-xtr8488)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4 lan5" eth1
		;;
	bananapi,bpi-r3)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4 sfp2" "sfp1 wan"
		;;
	bananapi,bpi-r3-mini|\
	edgecore,eap111|\
	huasifei,wh3000-emmc)
		ucidef_set_interfaces_lan_wan eth0 eth1
		;;
	bananapi,bpi-r4)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 sfp-lan" "wan sfp-wan"
		;;
	bananapi,bpi-r4-poe)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan sfp-wan"
		;;
	comfast,cf-e393ax)
		ucidef_set_interfaces_lan_wan "lan1" eth1
		;;
	cudy,ap3000outdoor-v1|\
	cudy,ap3000-v1|\
	cudy,re3000-v1|\
	netgear,wax220|\
	ubnt,unifi-6-plus|\
	zyxel,nwa50ax-pro)
		ucidef_set_interface_lan "eth0"
		;;
	cudy,m3000-v1|\
	cudy,tr3000-v1|\
	cudy,tr3000-v1-ubootmod|\
	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|\
	dlink,aquila-pro-ai-m60-a1)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" internet
		;;
	keenetic,kn-3911|\
	smartrg,sdg-8622|\
	smartrg,sdg-8632|\
	smartrg,sdg-8733a|\
	yuncore,ax835)
		ucidef_set_interfaces_lan_wan lan wan
		;;
	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 lan4" eth1
		;;
	mediatek,mt7988a-rfb)
		ucidef_set_interfaces_lan_wan "lan0 lan1 lan2 lan3 eth2" eth1
		;;
	mercusys,mr90x-v1|\
	mercusys,mr90x-v1-ubi)
		ucidef_set_interfaces_lan_wan "lan0 lan1 lan2" eth1
		;;
	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
		;;
	*)
		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
	acer,predator-w6|\
	acer,predator-w6d|\
	acer,vero-w6m)
		wan_mac=$(mmc_get_mac_ascii u-boot-env WANMAC)
		lan_mac=$(mmc_get_mac_ascii u-boot-env LANMAC)
		;;
	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|\
	h3c,magic-nx30-pro-nmbm)
		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
		;;
	nradio,c8-668gl)
		lan_mac=$(mmc_get_mac_ascii bdinfo "fac_mac ")
		wan_mac=$(macaddr_add "$lan_mac" 2)
		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)
		;;
	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
