#!/bin/sh
#
# Copyright (c) 2014, 2021, The Linux Foundation. All rights reserved.
# Copyright (c) 2023, Qualcomm Innovation Center, Inc. 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

ipq53xx_setup_interfaces()
{
	local board="$1"

	case "$board" in
	qcom,ipq5332-ap-emulation |\
	qcom,ipq5332-db-mi01.1 |\
	qcom,ipq5332-db-mi02.1 |\
	qcom,ipq5332-db-mi03.1)
		ucidef_set_interfaces_lan_wan "eth1" "eth0"
			;;
	qcom,ipq5332-ap-mi01.2 |\
	qcom,ipq5332-ap-mi01.2-c2 |\
	qcom,ipq5332-ap-mi01.2-qcn9160-c1 |\
	qcom,ipq5332-ap-mi01.3 |\
	qcom,ipq5332-ap-mi01.3-c2 |\
	qcom,ipq5332-ap-mi01.3-c3 |\
	qcom,ipq5332-ap-mi01.4 |\
	qcom,ipq5332-ap-mi01.6 |\
	qcom,ipq5332-ap-mi01.7 |\
	qcom,ipq5332-ap-mi01.9 |\
	qcom,ipq5332-ap-mi01.12 |\
	qcom,ipq5332-ap-mi01.13 |\
	qcom,ipq5332-ap-mi01.14 |\
	qcom,ipq5332-ap-mi03.1 |\
	qcom,ipq5332-ap-mi04.1 |\
	qcom,ipq5332-ap-mi04.1-c2 |\
	qcom,ipq5332-ap-mi04.3)
		ucidef_set_interfaces_lan_wan "eth1" "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)
ipq53xx_setup_interfaces $board
board_config_flush

exit 0
