#!/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
	cig,wf188)
		ucidef_set_interface_lan "eth0"
		;;
	qcom,ipq6018-cp01|\
	qcom,ipq807x-hk01)
			ucidef_set_interface_lan "eth0 eth1 eth2 eth3 eth4"
		ucidef_set_interface_wan "eth5"
		;;
	cig,wf188n|\
	cig,wf194c|\
	octogate,ax-3000|\
	octogate,ax-3500|\
	sercomm,wallaby|\
	yuncore,ax840|\
	yuncore,ax860)
		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)
		ucidef_set_interface_lan "eth1"
		ucidef_set_interface_wan "eth0"
		;;
	esac
}

qcom_setup_macs()
{
	local board="$1"

	case $board in
	cig,wf194c)
		mac=$(grep BaseMacAddress= /dev/mtd14 | cut -dx -f2)
		wan_mac=$(macaddr_canonicalize $mac)
		lan_mac=$(macaddr_add "$wan_mac" 1)
		;;
	*)
		;;
	esac
	[ -n "$wan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
	[ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
}

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

exit 0
