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

rockchip_setup_interfaces()
{
	local board="$1"

	case "$board" in
	friendlyarm,nanopi-r2c|\
	friendlyarm,nanopi-r2s|\
	friendlyarm,nanopi-r4s|\
	friendlyarm,nanopi-r4s-enterprise|\
	xunlong,orangepi-r1-plus|\
	xunlong,orangepi-r1-plus-lts)
		ucidef_set_interfaces_lan_wan 'eth1' 'eth0'
		;;
	friendlyarm,nanopi-r5c|\
	lunzn,fastrhino-r66s)
		ucidef_set_interfaces_lan_wan 'eth0' 'eth1'
		;;
	friendlyarm,nanopi-r5s)
		ucidef_set_interfaces_lan_wan 'eth1 eth2' 'eth0'
		;;
	lunzn,fastrhino-r68s)
		ucidef_set_interfaces_lan_wan 'eth0 eth1 eth3' 'eth2'
		;;
	*)
		ucidef_set_interface_lan 'eth0'
		;;
	esac
}

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

	case "$board" in
	friendlyarm,nanopi-r2c|\
	friendlyarm,nanopi-r2s|\
	lunzn,fastrhino-r66s|\
	lunzn,fastrhino-r68s)
		wan_mac=$(macaddr_generate_from_mmc_cid mmcblk0)
		lan_mac=$(macaddr_add "$wan_mac" 1)
		;;
	friendlyarm,nanopi-r4s|\
	friendlyarm,nanopi-r5c|\
	friendlyarm,nanopi-r5s)
		wan_mac=$(macaddr_generate_from_mmc_cid mmcblk1)
		lan_mac=$(macaddr_add "$wan_mac" 1)
		;;
	friendlyarm,nanopi-r4s-enterprise)
		wan_mac=$(get_mac_binary "/sys/bus/i2c/devices/2-0051/eeprom" 0xfa)
		lan_mac=$(macaddr_setbit_la "$wan_mac")
		;;
	xunlong,orangepi-r1-plus|\
	xunlong,orangepi-r1-plus-lts)
		lan_mac=$(cat /sys/class/net/eth1/address)
		wan_mac=$(macaddr_add "$lan_mac" -1)
		;;
	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)
rockchip_setup_interfaces $board
rockchip_setup_macs $board
board_config_flush

exit 0
