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

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

[ -f /lib/functions/target-defaults.sh ] && \
	. /lib/functions/target-defaults.sh

setup_json() {
	local model="$(mnf_info --name)" 2>/dev/null;
	local hw_ver="$(cut -c -2 /sys/mnf_info/hwver)"
	local branch_path="/sys/mnf_info/branch"
	local branch
	[ -f "$branch_path" ] && branch="$(cut -c -2 $branch_path)"

	case "$model" in
	RUTX08*)
		ucidef_set_interfaces_lan_wan "eth0" "eth1"
		ucidef_add_switch "switch0" \
			"0u@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "0u@eth1" "5:wan"
		ucidef_set_usb_jack "/usb1/1-1/"
		ucidef_set_hwinfo usb ethernet ios hw_nat nat_offloading multi_tag port_link gigabit_port
		ucidef_set_network_options "vlans" 128 "max_mtu" 9000 "readonly_vlans" 2
		;;
	RUTX09*)
		ucidef_set_interfaces_lan_wan "eth0" "eth1"
		ucidef_add_switch "switch0" \
			"0u@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "0u@eth1" "5:wan"
		ucidef_add_static_modem_info "$model" "3-1" "primary" "gps_out"
		ucidef_set_usb_jack "/usb1/1-1/"
		ucidef_set_hwinfo dual_sim usb gps mobile ethernet ios hw_nat nat_offloading multi_tag port_link gigabit_port
		ucidef_set_network_options "vlans" 128 "max_mtu" 9000 "readonly_vlans" 2
		;;
	RUTX10*)
		ucidef_set_interfaces_lan_wan "eth0" "eth1"
		ucidef_add_switch "switch0" \
			"0u@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "0u@eth1" "5:wan"
		ucidef_set_usb_jack "/usb1/1-1/"
		ucidef_add_wlan_bssid_limit "wlan0" 16
		ucidef_add_wlan_bssid_limit "wlan1" 16
		ucidef_set_hwinfo bluetooth usb wifi dual_band_ssid ethernet ios hw_nat nat_offloading multi_tag port_link gigabit_port
		ucidef_set_network_options "vlans" 128 "max_mtu" 9000 "readonly_vlans" 2
		;;
	RUTX11*)
		ucidef_set_interfaces_lan_wan "eth0" "eth1"
		ucidef_add_switch "switch0" \
			"0u@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "0u@eth1" "5:wan"
		ucidef_add_wlan_bssid_limit "wlan0" 16
		ucidef_add_wlan_bssid_limit "wlan1" 16
		ucidef_add_static_modem_info "$model" "3-1" "primary" "gps_out"
		ucidef_set_usb_jack "/usb1/1-1/"
		ucidef_set_hwinfo dual_sim usb gps mobile wifi dual_band_ssid bluetooth ethernet ios hw_nat nat_offloading multi_tag port_link \
			gigabit_port
		ucidef_set_network_options "vlans" 128 "max_mtu" 9000 "readonly_vlans" 2
		;;
	RUTXR1*)
		ucidef_set_interfaces_lan_wan "eth0" "eth1"
		ucidef_add_switch "switch0" \
			"0u@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "0u@eth1" "5:wan#s"
		ucidef_add_wlan_bssid_limit "wlan0" 16
		ucidef_add_wlan_bssid_limit "wlan1" 16
		ucidef_add_static_modem_info "$model" "3-1" "primary"
		ucidef_set_hwinfo dual_sim usb mobile wifi dual_band_ssid ethernet sfp_port sfp_switch console hw_nat nat_offloading multi_tag \
			port_link gigabit_port
		ucidef_set_usb_jack "/usb1/1-1/1-1.2/"
		ucidef_add_serial_capabilities "rsconsole" \
			"300 600 1200 2400 4800 9600 19200 38400 57600 115200" \
			"7 8" \
			"rts/cts xon/xoff none" \
			"1 2" \
			"even odd mark space none" \
			"none" \
			"/usb1/1-1/1-1.3/"
		ucidef_set_release_version "2.3.1"
		ucidef_set_network_options "vlans" 128 "max_mtu" 9000 "readonly_vlans" 2
		;;
	RUTX12*)
		ucidef_set_interfaces_lan_wan "eth0" "eth1"
		ucidef_add_switch "switch0" \
			"0u@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "0u@eth1" "5:wan"
		ucidef_add_wlan_bssid_limit "wlan0" 16
		ucidef_add_wlan_bssid_limit "wlan1" 16
		# builtin and primary should be first modem
		ucidef_add_static_modem_info "$model" "3-1" "primary" "gps_out"
		ucidef_add_static_modem_info "$model" "1-1.2"
		ucidef_set_usb_jack "/usb1/1-1/1-1.3/"
		ucidef_set_hwinfo usb gps mobile wifi dual_band_ssid bluetooth ethernet ios dual_modem hw_nat nat_offloading multi_tag port_link \
			gigabit_port
		ucidef_set_release_version "2.3.1"
		ucidef_set_network_options "vlans" 128 "max_mtu" 9000 "readonly_vlans" 2
		;;
	RUTX14*)
		ucidef_set_interfaces_lan_wan "eth0" "eth1"
		ucidef_add_switch "switch0" \
			"0u@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "0u@eth1" "5:wan"
		ucidef_add_wlan_bssid_limit "wlan0" 16
		ucidef_add_wlan_bssid_limit "wlan1" 16
		ucidef_add_static_modem_info "$model" "1-1" "primary" "gps_out"
		ucidef_set_usb_jack "/usb3/3-1/"
		ucidef_set_hwinfo usb gps dual_sim mobile wifi dual_band_ssid bluetooth ethernet ios at_sim hw_nat nat_offloading multi_tag \
			port_link gigabit_port
		ucidef_set_release_version "2.6.1"
		ucidef_set_network_options "vlans" 128 "max_mtu" 9000 "readonly_vlans" 2
		;;
	RUTX18*)
		ucidef_set_interfaces_lan_wan "eth0" "eth1"
		ucidef_add_switch "switch0" \
			"0u@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "0u@eth1" "5:wan"
		ucidef_add_wlan_bssid_limit "wlan0" 16
		ucidef_add_wlan_bssid_limit "wlan1" 16
		ucidef_add_static_modem_info "$model" "2-1" "primary" "gps_out"
		ucidef_set_usb_jack "/usb1/1-1/"
		ucidef_set_hwinfo usb gps dual_sim mobile wifi dual_band_ssid bluetooth ethernet ios hw_nat nat_offloading multi_tag port_link \
			gigabit_port
		ucidef_set_network_options "vlans" 128 "max_mtu" 9000 "readonly_vlans" 2
		;;
	RUTX50*)
		ucidef_set_interfaces_lan_wan "eth0" "eth1"
		ucidef_add_switch "switch0" \
			"0u@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "0u@eth1" "5:wan"
		ucidef_add_wlan_bssid_limit "wlan0" 16
		ucidef_add_wlan_bssid_limit "wlan1" 16
		ucidef_add_static_modem_info "$model" "2-1" "primary" "gps_out"
		ucidef_set_usb_jack "/usb3/3-1/"
		ucidef_set_hwinfo dual_sim usb gps mobile wifi dual_band_ssid ethernet ios at_sim hw_nat nat_offloading multi_tag port_link \
			gigabit_port
		ucidef_set_release_version "7.2.8"
		ucidef_set_network_options "vlans" 128 "max_mtu" 9000 "readonly_vlans" 2
		;;
	TRB245* |\
	TRB255*)
		ucidef_set_interface_lan "eth0"
		ucidef_add_static_modem_info "$model" "1-1.4" "primary" "gps_out"
		ucidef_add_serial_capabilities "rs232" \
			"300 600 1200 2400 4800 9600 19200 38400 57600 115200" \
			"7 8" \
			"rts/cts xon/xoff none" \
			"1 2" \
			"even odd mark space none" \
			"none" \
			"/usb1/1-1/1-1.3/"
		ucidef_add_serial_capabilities "rs485" \
			"300 600 1200 2400 4800 9600 19200 38400 57600 115200 \
			 230400 460800 921600 1000000 3000000" \
			"7 8" \
			"none" \
			"1 2" \
			"even odd mark space none" \
			"half full" \
			"/usb1/1-1/1-1.2/"
		ucidef_set_hwinfo dual_sim mobile gps ethernet ios rs232 rs485 nat_offloading
		ucidef_set_network_options "vlans" 16 "max_mtu" 1500
		;;
	TRB246* |\
	TRB256*)
		ucidef_set_interface_lan "eth0"
		ucidef_usbcheck "/sys/bus/usb/drivers/usb/1-1/1-1.4"
		ucidef_add_static_modem_info "$model" "1-1.4" "primary" "gps_out"
		ucidef_add_serial_capabilities "rs232" \
			"300 600 1200 2400 4800 9600 19200 38400 57600 115200" \
			"7 8" \
			"rts/cts xon/xoff none" \
			"1 2" \
			"even odd mark space none" \
			"none" \
			"/usb1/1-1/1-1.3/"
		ucidef_add_serial_capabilities "rs485" \
			"300 600 1200 2400 4800 9600 19200 38400 57600 115200 230400" \
			"5 6 7 8" \
			"xon/xoff none" \
			"1 2" \
			"even odd mark space none" \
			"half full" \
			"/tty/ttyS1"
		ucidef_set_hwinfo dual_sim mobile gps ethernet ios rs232 rs485 sw_rst_on_init
		ucidef_set_network_options "vlans" 16 "max_mtu" 1500 "vlan0" true
		;;
	NTP001*)
		ucidef_set_interface_lan "eth0"
		ucidef_usbcheck "/sys/bus/usb/drivers/usb/1-1/1-1.4"
		ucidef_add_static_modem_info "$model" "1-1.4" "primary" "gps_out"
		ucidef_add_serial_capabilities "rs232" \
			"300 600 1200 2400 4800 9600 19200 38400 57600 115200" \
			"7 8" \
			"rts/cts xon/xoff none" \
			"1 2" \
			"even odd mark space none" \
			"none" \
			"/usb1/1-1/1-1.3/"
		ucidef_add_serial_capabilities "rs485" \
			"300 600 1200 2400 4800 9600 19200 38400 57600 115200 230400" \
			"5 6 7 8" \
			"xon/xoff none" \
			"1 2" \
			"even odd mark space none" \
			"half full" \
			"/tty/ttyS1"
		ucidef_set_hwinfo gps ethernet ios rs232 rs485 sw_rst_on_init
		ucidef_set_network_options "vlans" 16 "max_mtu" 1500 "vlan0" true
		;;
	RUT14*)
		ucidef_add_switch "switch0" "1:lan" "0:wan:2" "6@eth0"
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_set_interface_default_macaddr "lan" "$(mtd_get_mac_binary config 0x0)"
		ucidef_set_interface_default_macaddr "wan" "$(macaddr_add "$(mtd_get_mac_binary config 0x0)" 1)"
		if [ "${model:5:1}" = "2" ]; then
			ucidef_set_hwinfo wifi nat_offloading ethernet rs232 port_link
			ucidef_add_serial_capabilities "rs232" \
				"300 600 1200 2400 4800 9600 19200 38400 57600 115200" \
				"5 6 7 8" \
				"rts/cts xon/xoff none" \
				"1 2" \
				"even odd mark space none" \
				"none" \
				"/usb1/1-1/1-1:1.0/"
		else
			ucidef_set_hwinfo wifi nat_offloading ethernet port_link
		fi
		ucidef_set_network_options "vlans" 16 "max_mtu" 1500 "readonly_vlans" 2 "vlan0" true
		;;
	RUT361* |\
	RUT200* |\
	RUT241* |\
	RUT271* |\
	RUT260*)
		ucidef_add_switch "switch0" "1:lan" "0:wan:2" "6@eth0"
		ucidef_usbcheck "/sys/bus/usb/drivers/usb/1-1"
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_set_interface_default_macaddr "lan" "$(mtd_get_mac_binary config 0x0)"
		ucidef_set_interface_default_macaddr "wan" "$(macaddr_add "$(mtd_get_mac_binary config 0x0)" 1)"
		ucidef_add_static_modem_info "$model" "1-1" "primary"
		opt_io="ios"
		opt_sim=""
		[ "${model:3:1}" = "3" ] && [ "${model:7:1}" = "1" ] && opt_io=""
		[ "${model:3:1}" = "2" ] && [ "${model:6:1}" = "1" ] && opt_io=""
		[ "${model:4:2}" = "60" ] && ucidef_set_release_version "7.4.1"
		[ "${model:6:1}" = "2" ] && [ "${model::6}" = "RUT241" ] && {
			ucidef_set_esim
			opt_sim="dual_sim"
		}
		[ "${model::6}" = "RUT271" ] && ucidef_set_release_version "7.8.1"
		ucidef_set_network_options "vlans" 16 "max_mtu" 1500 "readonly_vlans" 2 "vlan0" true
		ucidef_set_hwinfo mobile wifi ethernet nat_offloading port_link "$opt_io" "$opt_sim"
		[ "${model::4}" = "RUT2" ] && ucidef_check_dual_sim
		;;
	RUT206*)
		ucidef_add_switch "switch0" "1:lan" "0:wan:2" "6@eth0"
		ucidef_usbcheck "/sys/bus/usb/drivers/usb/1-1"
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_set_interface_default_macaddr "lan" "$(mtd_get_mac_binary config 0x0)"
		ucidef_set_interface_default_macaddr "wan" "$(macaddr_add "$(mtd_get_mac_binary config 0x0)" 1)"
		ucidef_add_static_modem_info "$model" "1-1.2" "2" "primary"
		ucidef_set_hwinfo mobile wifi ethernet nat_offloading port_link dual_sim sd_card rs232 rs485
		ucidef_set_network_options "vlans" 16 "max_mtu" 1500 "readonly_vlans" 2 "vlan0" true
		ucidef_add_serial_capabilities "rs232" \
			"300 600 1200 2400 4800 9600 19200 38400 57600 115200 230400" \
			"5 6 7 8" \
			"xon/xoff none" \
			"1 2" \
			"even odd mark space none" \
			"none" \
			"/tty/ttyS1"
		ucidef_add_serial_capabilities "rs485" \
			"300 600 1200 2400 4800 9600 19200 38400 57600 115200 \
			 230400 460800 921600 1500000 2000000" \
			"5 6 7 8" \
			"none" \
			"1 2" \
			"even odd mark space none" \
			"half" \
			"usb1/1-1/1-1.4/1-1.4:1.0/"
		;;
	RUT300*)
		ucidef_set_interface_wan "eth1"
		ucidef_set_usb_jack "/usb1/1-1/"
		ucidef_add_switch "switch0" \
			"0@eth0" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
		ucidef_set_hwinfo usb ethernet ios nat_offloading
		ucidef_set_network_options "vlans" 16 "max_mtu" 1500 "readonly_vlans" 1
		;;
	RUT301*)
		ucidef_add_switch "switch0" "0:lan:1" "1:lan:2" "2:lan:3" \
			"3:lan:4" "4:wan" "6@eth0"
		ucidef_set_usb_jack "/usb2/2-1/"
		ucidef_set_interface_default_macaddr "wan" "$(macaddr_add "$(mtd_get_mac_binary config 0x0)" 1)"
		ucidef_set_hwinfo usb ethernet ios nat_offloading port_link
		ucidef_set_network_options "vlans" 16 "max_mtu" 1500 "readonly_vlans" 2 "vlan0" true
		;;
	RUT360*)
		ucidef_set_interfaces_lan_wan "eth0" "eth1"
		ucidef_add_wlan_bssid_limit "wlan0" 8
		ucidef_add_static_modem_info "$model" "1-1" "primary"
		ucidef_set_hwinfo mobile wifi dual_band_ssid ethernet ios nat_offloading
		ucidef_set_network_options "vlans" 16 "max_mtu" 1500
		;;
	TRB140*)
		ucidef_set_interface_lan "eth0 rndis0"
		[ "${model:7:1}" = "2" ] && ucidef_set_hwinfo mobile ethernet micro_usb port_link gigabit_port || \
			ucidef_set_hwinfo mobile ethernet ios micro_usb port_link gigabit_port
		ucidef_set_network_options "vlans" 4094 "max_mtu" 1500
		[ "${model:6:1}" = "4" ] && \
			ucidef_set_release_version "7.4.2"
		;;
	TRB143*)
		ucidef_set_interface_lan "eth0 rndis0"
		[ "${model:7:1}" = "2" ] && ucidef_set_hwinfo mobile ethernet micro_usb port_link gigabit_port mbus || \
			ucidef_set_hwinfo mobile ethernet ios micro_usb port_link gigabit_port mbus
		ucidef_add_serial_capabilities "mbus" \
			"300 600 1200 2400 4800 9600" \
			"8" \
			"none" \
			"1" \
			"even" \
			"half" \
			"/tty/ttyHS0"
		if [ "${model:6:1}" = "4" ]; then
			ucidef_set_release_version "7.4.3"
		else
			ucidef_set_release_version "7.1.7"
		fi
		ucidef_set_network_options "vlans" 4094 "max_mtu" 1500
		;;
	TRB141*)
		ucidef_set_interface_lan "rndis0"
		ucidef_set_hwinfo mobile ios micro_usb
		ucidef_set_network_options "vlans" 4094 "max_mtu" 1500
		[ "${model:6:1}" = "4" ] && \
			ucidef_set_release_version "7.4.3"
		;;
	TRB142*)
		ucidef_set_interface_lan "rndis0"
		[ "${model:7:1}" = "2" ] && ucidef_set_hwinfo mobile rs232 rs232_control micro_usb || \
			ucidef_set_hwinfo mobile ios rs232 rs232_control micro_usb
		ucidef_add_serial_capabilities "rs232" \
			"300 600 1200 2400 4800 9600 19200 38400 57600 115200" \
			"5 6 7 8" \
			"rts/cts xon/xoff none" \
			"1 2" \
			"even odd mark space none" \
			"none" \
			"/tty/ttyHS0"
		if [ "${model:6:1}" = "3" ]; then
			ucidef_set_release_version "7.1"
		elif [ "${model:6:1}" = "4" ]; then
			ucidef_set_release_version "7.4.3"
		fi
		ucidef_set_network_options "vlans" 4094 "max_mtu" 1500
		;;
	TRB145*)
		ucidef_set_interface_lan "rndis0"
		[ "${model:7:1}" = "2" ] && ucidef_set_hwinfo mobile rs485 micro_usb || \
			ucidef_set_hwinfo mobile ios rs485 micro_usb
		ucidef_add_serial_capabilities "rs485" \
			"300 600 1200 2400 4800 9600 19200 38400 57600 115200 \
			 230400 460800 921600 1000000 3000000" \
			"5 6 7 8" \
			"xon/xoff none" \
			"1 2" \
			"even odd mark space none" \
			"half full" \
			"/tty/ttyHS0"
		if [ "${model:6:1}" = "2" ]; then
			ucidef_set_release_version "7.1"
		elif [ "${model:6:1}" = "4" ]; then
			ucidef_set_release_version "7.4.3"
		fi
		ucidef_set_network_options "vlans" 4094 "max_mtu" 1500
		;;
	TCR100*)
		ucidef_set_interfaces_lan_wan "eth0" "eth1"
		ucidef_add_wlan_bssid_limit "wlan0" 8
		ucidef_add_wlan_bssid_limit "wlan1" 8
		ucidef_set_interface guest proto static type bridge \
		guest 1 _wireless true _dhcp true
		ucidef_add_static_modem_info "$model" "1-1" "primary"
		ucidef_set_hwinfo mobile wifi dual_band_ssid wps ethernet nat_offloading
		ucidef_set_release_version "7.2.4"
		ucidef_set_network_options "vlans" 16 "max_mtu" 1500
		;;
	OTD140*)
		ucidef_add_switch "switch0" "4:lan:1" "1:lan:2" "6@eth0"
		ucidef_set_interface_default_macaddr "lan" "$(mtd_get_mac_binary config 0x0)"
		ucidef_set_interface "lan" "default_ip" "%%LAN_IP%%"
		ucidef_add_static_modem_info "$model" "1-1" "primary"
		ucidef_set_poe "i2c-0" 2 15400 1 "_lan1" "3" 15400
		ucidef_set_poe_chip "0X77" "0:_lan1"
		ucidef_set_poe_chip "0X2F" "1:_lan1"
		ucidef_set_hwinfo dual_sim mobile ethernet nat_offloading poe port_link
		ucidef_set_network_options "vlans" 16 "max_mtu" 1500 "readonly_vlans" 1 "vlan0" true
		;;
	OTD500*)
		ucidef_set_interface_lan "lan1 lan2"
		ucidef_set_poe "i2c-0" 2 15400 1 "_lan2" "3" 15400
		ucidef_set_poe_chip "0X77" "0:_lan2"
		ucidef_set_poe_chip "0X2F" "1:_lan2"
		ucidef_add_static_modem_info "$model" "2-1" "primary"
		ucidef_set_hwinfo ethernet mobile dual_sim at_sim dsa hw_nat nat_offloading multi_tag \
			port_link gigabit_port poe
		ucidef_set_network_options "vlans" 4094 "max_mtu" 2030 "readonly_vlans" 1
		;;
	TAP100*)
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_set_interface_lan "eth0"
		ucidef_set_interface "lan" "ipv6" "1"
		ucidef_set_interface_default_macaddr "lan" "$(mtd_get_mac_binary config 0x0)"
		ucidef_set_hwinfo wifi ethernet sw_rst_on_init
		ucidef_set_network_options "ula" false "disable_vlan" true "ip6assign" false "vlans" 16 "no_metric" true "max_mtu" 1500
		ucidef_set_interface "dhcp" "device" "@lan" "proto" "dhcp"
		;;
	TAP200*)
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_add_wlan_bssid_limit "wlan1" 4
		ucidef_set_interface_lan "eth1"
		ucidef_set_interface "lan" "default_ip" "%%LAN_IP%%" "ipv6" "1"
		ucidef_set_interface_default_macaddr "lan" "$(mtd_get_mac_binary config 0x0)"
		ucidef_set_hwinfo wifi ethernet sw_rst_on_init dual_band_ssid
		ucidef_set_network_options "ula" false "disable_vlan" true "ip6assign" false "vlans" 16 "no_metric" true "max_mtu" 2030
		ucidef_set_interface "dhcp" "device" "@lan" "proto" "dhcp"
		;;
	TAP400*)
		ucidef_set_interface_lan "eth1"
		ucidef_set_interface "lan" "default_ip" "%%LAN_IP%%" "ipv6" "1"
		ucidef_set_interface_default_macaddr "lan" "$(mtd_get_mac_binary config 0x0)"
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_add_wlan_bssid_limit "wlan1" 4
		ucidef_set_hwinfo wifi ethernet dual_band_ssid dsa gigabit_port 2_5_gigabit_port
		ucidef_set_network_options "ula" false "disable_vlan" true "ip6assign" false "vlans" 16 "no_metric" true "max_mtu" 2022
		ucidef_set_interface "dhcp" "device" "@lan" "proto" "dhcp"
		;;
	TRB500*)
		ucidef_set_interface_lan "eth0 ecm0"
		ucidef_set_interface_default_macaddr "lan" "$(mtd_get_mac_binary mnf_info 0x0)" \
			"$(macaddr_add "$(mtd_get_mac_binary mnf_info 0x0)" 1)"
		ucidef_set_hwinfo mobile ethernet ios micro_usb port_link gigabit_port
		ucidef_set_network_options "vlans" 4094 "max_mtu" 1500
		;;
	TRB501*)
		ucidef_set_interface_lan "eth0 usb0"
		ucidef_set_interface_default_macaddr "lan" "$(mtd_get_mac_binary mnf_info 0x0)" \
			"$(macaddr_add "$(mtd_get_mac_binary mnf_info 0x0)" 1)"
		ucidef_set_hwinfo mobile ethernet ios micro_usb port_link gigabit_port 2_5_gigabit_port
		ucidef_set_network_options "vlans" 4094 "max_mtu" 1500
		;;
	TRB160*)
		ucidef_set_interface_lan "eth0 usb0"
		ucidef_set_interface_default_macaddr "lan" "$(mtd_get_mac_binary mnf_info 0x0)" \
			"$(macaddr_add "$(mtd_get_mac_binary mnf_info 0x0)" 1)"
		ucidef_set_hwinfo mobile ethernet ios micro_usb port_link gigabit_port
		ucidef_set_network_options "vlans" 4094 "max_mtu" 1500
		;;
	RUTM50*)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
		ucidef_set_usb_jack "/usb1/1-2/"
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_add_wlan_bssid_limit "wlan1" 4
		if [ "$branch" == "A" ]; then
			ucidef_set_release_version "7.7"
			hw_opt="m2_modem"
			gps=""
		else
			hw_opt="gps"
			gps="gps_out"
		fi
		ucidef_add_static_modem_info "$model" "2-1" "primary" "$gps"
		ucidef_set_hwinfo usb ethernet ios mobile wifi dual_band_ssid dual_sim at_sim dsa hw_nat nat_offloading multi_tag \
			port_link soft_port_mirror gigabit_port "$hw_opt"
		ucidef_set_network_options "vlans" 4094 "max_mtu" 2030 "readonly_vlans" 1
		;;
	RUTM51*)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
		ucidef_set_usb_jack "/usb1/1-2/"
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_add_wlan_bssid_limit "wlan1" 4
		ucidef_add_static_modem_info "$model" "2-1" "primary"
		ucidef_set_hwinfo usb ethernet ios mobile wifi dual_band_ssid dual_sim at_sim dsa hw_nat nat_offloading multi_tag \
			soft_port_mirror port_link gigabit_port
		ucidef_set_network_options "vlans" 4094 "max_mtu" 2030 "readonly_vlans" 1
		ucidef_set_release_version "7.4.4"
		;;
	RUTM52*)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_add_wlan_bssid_limit "wlan1" 4
		ucidef_add_static_modem_info "$model" "2-1.1" "primary"
		ucidef_add_static_modem_info "$model" "2-1.2"
		ucidef_set_hwinfo gps ethernet ios mobile wifi dual_band_ssid at_sim dsa hw_nat nat_offloading multi_tag \
			soft_port_mirror port_link gigabit_port dual_modem custom_usbcfg
		ucidef_set_network_options "vlans" 4094 "max_mtu" 2030 "readonly_vlans" 1
		ucidef_set_release_version "7.7"
		;;
	ATRM50*)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" "wan"
		ucidef_set_usb_jack "/usb1/1-2/"
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_add_wlan_bssid_limit "wlan1" 4
		ucidef_add_static_modem_info "$model" "2-1" "primary" "gps_out"
		ucidef_set_hwinfo usb ethernet power_ios gps mobile wifi dual_band_ssid dual_sim at_sim dsa hw_nat nat_offloading multi_tag \
			port_link soft_port_mirror gigabit_port sd_card
		ucidef_set_network_options "vlans" 4094 "max_mtu" 2030 "readonly_vlans" 1
		;;
	RUTC50*)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_add_wlan_bssid_limit "wlan1" 4
		ucidef_set_usb_jack "/usb1/1-1/1-1.3/"
		ucidef_usbhubcheck "2-1 1-1" "pcie_reset"
		ucidef_add_static_modem_info "$model" "2-1.1" "primary" "gps_out"
		ucidef_set_hwinfo usb ethernet ios gps mobile wifi dual_sim at_sim dual_band_ssid dsa hw_nat nat_offloading port_link soft_port_mirror \
			gigabit_port multi_tag
		ucidef_set_network_options "vlans" 4094 "max_mtu" 2022 "readonly_vlans" 1
		;;
	RUTM08*)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" "wan"
		ucidef_set_usb_jack "/usb1/1-1/"
		ucidef_set_hwinfo usb ethernet ios dsa hw_nat nat_offloading multi_tag port_link soft_port_mirror gigabit_port
		ucidef_set_network_options "vlans" 4094 "max_mtu" 2030 "readonly_vlans" 1
		ucidef_set_release_version "7.6.1"
		;;
	RUTM09*)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" "wan"
		ucidef_add_static_modem_info "$model" "1-2" "primary" "gps_out"
		ucidef_set_usb_jack "/usb1/1-1/"
		ucidef_set_hwinfo usb ethernet ios gps mobile dual_sim dsa hw_nat nat_offloading multi_tag port_link soft_port_mirror \
			gigabit_port
		ucidef_set_network_options "vlans" 4094 "max_mtu" 2030 "readonly_vlans" 1
		ucidef_set_release_version "7.6.1"
		;;
	RUTM10*)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" "wan"
		ucidef_set_usb_jack "/usb1/1-1/"
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_add_wlan_bssid_limit "wlan1" 4
		ucidef_set_hwinfo usb ethernet ios wifi dual_band_ssid dsa hw_nat nat_offloading multi_tag port_link soft_port_mirror \
			gigabit_port
		ucidef_set_network_options "vlans" 4094 "max_mtu" 2030 "readonly_vlans" 1
		ucidef_set_release_version "7.6.1"
		;;
	RUTM11*)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" "wan"
		ucidef_set_usb_jack "/usb1/1-1/"
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_add_wlan_bssid_limit "wlan1" 4
		ucidef_add_static_modem_info "$model" "1-2" "primary" "gps_out"
		ucidef_set_hwinfo usb ethernet ios gps mobile wifi dual_band_ssid dual_sim dsa hw_nat nat_offloading multi_tag \
			port_link soft_port_mirror gigabit_port
		ucidef_set_network_options "vlans" 4094 "max_mtu" 2030 "readonly_vlans" 1
		ucidef_set_release_version "7.6.1"
		;;
	RUTM12*)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_add_wlan_bssid_limit "wlan1" 4
		ucidef_add_static_modem_info "$model" "1-1" "primary" "gps_out"
		ucidef_add_static_modem_info "$model" "1-2"
		ucidef_set_hwinfo ethernet ios gps mobile wifi dual_band_ssid dual_modem dsa hw_nat nat_offloading multi_tag \
			port_link soft_port_mirror gigabit_port custom_usbcfg
		ucidef_set_network_options "vlans" 4094 "max_mtu" 2030 "readonly_vlans" 1
		ucidef_set_release_version "7.9"
		;;
	RUTM13*)
		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" "wan"
		ucidef_set_usb_jack "/usb1/1-1/"
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_add_wlan_bssid_limit "wlan1" 4
		ucidef_add_static_modem_info "$model" "1-2" "primary" "gps_out"
		ucidef_set_hwinfo usb ethernet ios gps mobile wifi dual_band_ssid dual_sim dsa hw_nat nat_offloading multi_tag \
			port_link soft_port_mirror gigabit_port
		ucidef_set_network_options "vlans" 4094 "max_mtu" 2030 "readonly_vlans" 1
		;;

	x86)
		ucidef_set_interface_wan "eth0"
		ucidef_set_interface_lan "eth1"
		ucidef_add_wlan_bssid_limit "wlan0" 4
		ucidef_add_wlan_bssid_limit "wlan1" 4
		ucidef_set_hwinfo usb wifi dual_band_ssid ethernet
		ucidef_set_network_options "vlans" 4094 "max_mtu" 9000
		;;
	*)
		echo "Unsupported hardware. Network interfaces not intialized"
		;;
	esac

	ucidef_set_interface "lan" "default_ip" "%%LAN_IP%%"

	type ucidef_target_defaults &> /dev/null && \
		ucidef_target_defaults "$model"
}


platform="$(cat /proc/device-tree/platform)" 2>/dev/null

board_config_update
setup_json
ucidef_set_board_platform "$platform"
ucidef_check_esim
board_config_flush

exit 0
