. /lib/functions.sh

case "$(board_name)" in
	aqara,zhwg11lm |\
	xiaomi,dgnwg05lm )
		# Only the access point is started on a fresh install, so that
		# the user can connect and join an uplink network from LuCI
		# (Network -> Wireless -> Scan). The STA is added by LuCI as
		# a second wifi-iface of the same radio (rtw88 supports AP+STA).
		# Keep the base MAC available for the STA.
		mac1="$(ucode /usr/share/hostap/wdev.uc phy0 get_macaddr id=1)" || exit 1
		uci delete wireless.@wifi-device[0].disabled
		uci delete wireless.@wifi-iface[0].disabled
		uci set wireless.@wifi-device[0].channel='1'
		uci set wireless.@wifi-device[0].band='2g'
		uci set wireless.@wifi-device[0].country='US'
		uci set "wireless.@wifi-iface[0].macaddr=$mac1"
		uci commit wireless

		# The AP vif is attached to br-lan by netifd (network=lan), so it
		# must not be listed as a bridge port; keep the bridge up on its own.
		uci delete network.@device[0].ports
		uci set network.@device[0].bridge_empty='1'

		# create wwan interface as it is the default for scanned networks
		uci set network.wwan='interface'
		uci set network.wwan.proto='dhcp'
		uci commit network

		# and add wwan to wan zone in firewall
		uci set firewall.@zone[1].network='wwan wan wan6'
		uci commit firewall
	;;
	geniatech,gtw360 )
		# create wwan zone as it is the default for scanned networks
		uci set network.wwan='interface'
		uci set network.wwan.proto='dhcp'
		uci commit network

		# and add wwan to wan zone in firewall
		uci set firewall.@zone[1].network='wwan wan wan6'
		uci commit firewall

		uci delete wireless.@wifi-device[0].disabled
		uci delete wireless.@wifi-iface[0].disabled
		uci set wireless.@wifi-device[0].channel='1'
		uci set wireless.@wifi-device[0].band='2g'
		uci set wireless.@wifi-device[0].country='US'
		uci delete wireless.@wifi-device[0].htmode
		uci commit wireless
	;;
esac

exit 0
