#!/bin/sh

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

ath79_setup_interfaces()
{
	local board="$1"

	case "$board" in
	aerohive,hiveap-121|\
	glinet,gl-e750)
		ucidef_set_interface_lan "eth0"
		;;
	domywifi,dw33d)
		ucidef_add_switch "switch0" \
			"0@eth0" "1:wan" "2:lan" "3:lan" "4:lan" "5:lan" "6@eth1"
		;;
	glinet,gl-ar750s-nor|\
	glinet,gl-ar750s-nor-nand)
		ucidef_add_switch "switch0" \
			"0@eth0" "2:lan:2" "3:lan:1" "1:wan"
		;;
	netgear,wndr3700-v4|\
	netgear,wndr4300|\
	netgear,wndr4300sw|\
	netgear,wndr4300-v2|\
	netgear,wndr4500-v3)
		ucidef_add_switch "switch0" \
			"0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
		;;
	netgear,wndr4300tn)
		ucidef_add_switch "switch0" \
			"0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
		;;
	zyxel,nbg6716)
		ucidef_add_switch "switch0" \
			"0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "6@eth1"
		;;
	*)
		ucidef_set_interfaces_lan_wan "eth0" "eth1"
		;;
	esac
}

ath79_setup_macs()
{
	local board="$1"

	case "$board" in
	netgear,wndr3700-v4|\
	netgear,wndr4300|\
	netgear,wndr4300sw|\
	netgear,wndr4300-v2|\
	netgear,wndr4500-v3)
		wan_mac=$(mtd_get_mac_binary caldata 0x6)
		;;
	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)
ath79_setup_interfaces $board
ath79_setup_macs $board
board_config_flush

exit 0
