#
# Copyright (c) 2015 The Linux Foundation. All rights reserved.
# Copyright (c) 2011-2015 OpenWrt.org
#

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

ipq60xx_setup_interfaces()
{
	local board="$1"

	case "$board" in
	8devices,mango-dvk)
		ucidef_set_interfaces_lan_wan "lan1 lan2" "wan"
		;;
	cambiumnetworks,xe3-4)
		ucidef_set_interface_lan "lan1 lan2" "dhcp"
		;;
	netgear,wax214)
		ucidef_set_interfaces_lan_wan "lan"
		;;
	qihoo,360v6)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" "wan"
		;;
	linksys,mr7350|\
	yuncore,fap650)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
		;;
	*)
		echo "Unsupported hardware. Network interfaces not initialized"
		;;
	esac
}

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

	case $board in
	linksys,mr7350)
		label_mac=$(mtd_get_mac_ascii devinfo hw_mac_addr)
		lan_mac=$label_mac
		wan_mac=$label_mac
		;;
	qihoo,360v6)
		lan_mac=$(mtd_get_mac_ascii factory lanMac)
		wan_mac=$(macaddr_add "$lan_mac" 1)
		label_mac=$lan_mac
		;;
	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)
ipq60xx_setup_interfaces $board
ipq60xx_setup_macs $board
board_config_flush

exit 0
