#!/bin/sh
# 99-custom-config - Apply TR3000-specific defaults on first boot
# Sets LAN IP, WiFi SSID/htmode/uapsd, dnsmasq, IPv6 RA, turboacc BBR
# Runs once (uci-defaults scripts auto-delete after running)
#
# v29 2026-07-22: HONEST labels. UCI idx=1=5g config (driver maps
# band=5g content to the 5G PHY whatever netdev it is this boot).
# idx=2=2g config (maps to 2.4G PHY). ra0/rax0 netdev binding is
# random per boot but physical broadcast always correct (band-content
# invariant). LuCI Overview shows iwinfo truth. Edit forms show UCI
# config. Do NOT use LuCI Save and Apply (triggers wifi reload);
# reboot to apply wireless changes.

. /lib/functions.sh

# ===== LAN IP =====
uci set network.lan.ipaddr="192.168.1.2"
uci set network.lan.netmask="255.255.255.0"
uci commit network

# ===== WiFi SSID + htmode + uapsd (honest labels) =====
uci set wireless.MT7981_1_1.phy="ra0"
uci set wireless.MT7981_1_1.band="5g"
uci set wireless.MT7981_1_1.hwmode="11a"
uci set wireless.MT7981_1_1.htmode="HE160"
uci set wireless.MT7981_1_1.country="CN"
uci set wireless.MT7981_1_1.channel="36"
uci set wireless.MT7981_1_1.dbdc_main="1"
uci set wireless.default_MT7981_1_1.ssid="ImmortalWrt-5G"
uci set wireless.default_MT7981_1_1.uapsd="0"
uci set wireless.default_MT7981_1_1.encryption="none"

uci set wireless.MT7981_1_2.phy="rax0"
uci set wireless.MT7981_1_2.band="2g"
uci set wireless.MT7981_1_2.hwmode="11g"
uci set wireless.MT7981_1_2.htmode="HE40"
uci set wireless.MT7981_1_2.country="CN"
uci set wireless.MT7981_1_2.channel="auto"
uci set wireless.MT7981_1_2.dbdc_main="0"
uci set wireless.default_MT7981_1_2.ssid="ImmortalWrt-2.4G"
uci set wireless.default_MT7981_1_2.uapsd="0"
uci set wireless.default_MT7981_1_2.encryption="none"

uci commit wireless

# ===== dnsmasq enable =====
/etc/init.d/dnsmasq enable

# ===== IPv6 RA disabled =====
uci set dhcp.lan.ra="disabled"
uci set dhcp.lan.dhcpv6="disabled"
uci commit dhcp

# ===== turboacc: BBR as default TCP CCA =====
# /etc/init.d/turboacc force-sets tcp_congestion_control from
# turboacc.config.tcpcca at every boot (S90, after sysctl.d), defaulting
# to cubic and clobbering sysctl.d/12-tcp-bbr.conf. Pin bbr here so the
# 网络加速 page shows BBR active out of the box.
uci set turboacc.config.tcpcca="bbr"
uci commit turboacc

# ===== Firewall: prepare for MSS clamp via hotplug =====
# fw4 reload wipes hotplug MSS clamp rules; the 30-mss-clamp hotplug
# re-adds them on every iface ifup. No static config needed here.

exit 0
