#!/bin/sh
#
# Copyright (c) 2014, 2021, The Linux Foundation. All rights reserved.
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

[ -e /etc/config/network ] && exit 0

touch /etc/config/network

CFG=/etc/board.json

. /lib/functions/uci-defaults.sh

ipq95xx_setup_interfaces()
{
	local board="$1"

	case "$board" in
	qcom,ipq9574-ap-al01-c1 |\
	qcom,ipq9574-ap-al02-c1 |\
	qcom,ipq9574-ap-al02-c2 |\
	qcom,ipq9574-ap-al02-c3 |\
	qcom,ipq9574-ap-al02-c4 |\
	qcom,ipq9574-ap-al02-c5 |\
	qcom,ipq9574-ap-al02-c6 |\
	qcom,ipq9574-ap-al02-c7 |\
	qcom,ipq9574-ap-al02-c8 |\
	qcom,ipq9574-ap-al02-c9 |\
	qcom,ipq9574-ap-al02-c11 |\
	qcom,ipq9574-ap-al02-c12 |\
	qcom,ipq9574-ap-al02-c13 |\
	qcom,ipq9574-ap-al02-c14 |\
	qcom,ipq9574-ap-al02-c15 |\
	qcom,ipq9574-ap-al02-c16 |\
	qcom,ipq9574-ap-al02-c17 |\
	qcom,ipq9574-ap-al02-c18 |\
	qcom,ipq9574-ap-al02-c19 |\
	qcom,ipq9574-db-al01-c1 |\
	qcom,ipq9574-db-al01-c2 |\
	qcom,ipq9574-db-al01-c3 |\
	qcom,ipq9574-db-al02-c1 |\
	qcom,ipq9574-db-al02-c2 |\
	qcom,ipq9574-db-al02-c3)
		ucidef_set_interfaces_lan_wan "eth1 eth2 eth3 eth4 eth5" "eth0"
		;;
	qcom,ipq9574-ap-al03-c1 |\
	qcom,ipq9574-ap-al03-c2)
		ucidef_set_interfaces_lan_wan "eth1 eth2 eth3 eth4" "eth0"
		;;
	qcom,ipq9574-ap-al02-c10)
		ucidef_set_interfaces_lan_wan "eth1 eth2" "eth0"
		ucidef_add_switch "switch1"
		ucidef_add_switch_attr "switch1" "enable" false
		;;
	*)
		echo "Unsupported hardware. Network interfaces not intialized"
		;;
	esac
}

board_config_update
board=$(board_name)
ipq95xx_setup_interfaces $board
board_config_flush

exit 0
