#!/bin/sh

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

qcom_setup_interfaces()
{
	local board="$1"
	ucidef_add_switch "switch0"
	ucidef_add_switch_attr "switch0" "enable" "false"
	ucidef_add_switch_attr "switch0" "reset" "false"

	case $board in
	hfcl,ion4xi|\
	hfcl,ion4xe)
		ucidef_set_interface_wan "eth0 eth1"
		ucidef_set_interface_lan ""
		;;
	cig,wf188|\
	tplink,ex227|\
	tplink,ex447)
		ucidef_set_interface_wan "eth0"
		ucidef_set_interface_lan ""
		;;
	qcom,ipq6018-cp01|\
	qcom,ipq807x-hk01)
		ucidef_set_interface_lan "eth0 eth1 eth2 eth3 eth4"
		ucidef_set_interface_wan "eth5"
		;;
	cig,wf194c|\
	cig,wf194c4|\
	edgecore,eap106|\
	qcom,ipq5018-mp03.3|\
	sercomm,wallaby)
		ucidef_set_interface_lan "eth0"
		ucidef_set_interface_wan "eth1"
		;;
	edgecore,eap101)
		ucidef_set_interface_lan "eth1 eth2"
		ucidef_set_interface_wan "eth0"
		;;
	edgecore,eap102|\
	wallys,dr6018|\
	cig,wf188n|\
	cig,wf196)
		ucidef_set_interface_lan "eth1"
		ucidef_set_interface_wan "eth0"
		;;
	qcom,ipq807x-hk14)
		ucidef_set_interface_lan "eth0 eth1 eth2 eth3"
		ucidef_set_interface_wan "eth4"
		;;
	wallys,dr6018-v4)
		ucidef_set_interface_lan "eth1 eth2 eth3 eth4"
		ucidef_set_interface_wan "eth0"
		;;
	esac
}

qcom_setup_macs()
{
	local board="$1"

	case $board in
	cig,wf194c|\
	cig,wf194c4)
		mac=$(grep BaseMacAddress= /dev/mtd14 | cut -dx -f2)
		wan_mac=$(macaddr_canonicalize $mac)
		lan_mac=$(macaddr_add "$wan_mac" 1)
		ucidef_set_network_device_mac eth0 $lan_mac
		ucidef_set_network_device_mac eth1 $wan_mac
		ucidef_set_label_macaddr $wan_mac
		;;
	*)
		wan_mac=$(cat /sys/class/net/eth0/address)
		lan_mac=$(macaddr_add "$wan_mac" 1)
		;;
	esac
	[ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
	[ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
}

board_config_update
board=$(board_name)
ucidef_set_bridge_device bridge
qcom_setup_interfaces $board
qcom_setup_macs $board
board_config_flush

exit 0
