diff --git a/my-default-settings/Makefile b/my-default-settings/Makefile index e61fc65c3..f07cadd6b 100644 --- a/my-default-settings/Makefile +++ b/my-default-settings/Makefile @@ -10,7 +10,7 @@ include $(INCLUDE_DIR)/kernel.mk PKG_NAME:=my-default-settings PKG_VERSION:=2 -PKG_RELEASE:=15 +PKG_RELEASE:=16 include $(INCLUDE_DIR)/package.mk diff --git a/my-default-settings/files/sbin/mywifi b/my-default-settings/files/sbin/mywifi index 6d70b69e2..eb2c04ca2 100644 --- a/my-default-settings/files/sbin/mywifi +++ b/my-default-settings/files/sbin/mywifi @@ -63,7 +63,7 @@ while [ $# -gt 0 ]; do shift done -# 密码校验:如果传入了密码,校验其长度是否符合 WPA/WPA2/WPA3 规范(8~63位) +# 密码合法性校验 if [ $HAS_PASSWD -eq 1 ] && [ -n "$CUSTOM_PASSWD" ]; then pwd_len=${#CUSTOM_PASSWD} if [ "$pwd_len" -lt 8 ] || [ "$pwd_len" -gt 63 ]; then @@ -75,7 +75,67 @@ else SSID_PASSWD="" fi -# 2. 识别射频频段函数 (2g, 5g, 6g) +# 2. 深度就绪检测:确保内核PHY驱动、多频硬件、系统初始化状态和UCI配置全部真正就绪 +wait_wifi_ready() { + local max_wait=15 + local waited=0 + + while [ $waited -lt $max_wait ]; do + local phy_count=0 + local uci_count=0 + + # B. 检查内核物理无线设备 (PHY) + local phys="$(ls -d /sys/class/ieee80211/phy* 2>/dev/null)" + [ -n "$phys" ] && phy_count=$(echo "$phys" | wc -w) + + # C. 统计 UCI wireless 中实际已解析出的 wifi-device 节点数量(非文件大小) + if [ -s /etc/config/wireless ]; then + local uci_radios="$(uci -q show wireless 2>/dev/null | sed -n 's/^wireless\.\([^.]*\)=wifi-device/\1/p')" + [ -n "$uci_radios" ] && uci_count=$(echo "$uci_radios" | wc -w) + fi + + # D. 自动探测与配置补全: + # - 物理网卡已加载,但 UCI 配置中的 radio 数量少于物理网卡数量(多频网卡尚未完全生成配置) + # - 或者配置文件缺失/没有 radio 配置 + if [ $phy_count -gt 0 ] && [ $uci_count -lt $phy_count ]; then + [ -x /sbin/wifi ] && /sbin/wifi config >/dev/null 2>&1 + elif [ $phy_count -eq 0 ] && [ $uci_count -eq 0 ] && [ ! -s /etc/config/wireless ]; then + [ -x /sbin/wifi ] && /sbin/wifi config >/dev/null 2>&1 + fi + + # 重新同步一次 UCI radio 数量 + if [ -s /etc/config/wireless ]; then + local uci_radios_check="$(uci -q show wireless 2>/dev/null | sed -n 's/^wireless\.\([^.]*\)=wifi-device/\1/p')" + [ -n "$uci_radios_check" ] && uci_count=$(echo "$uci_radios_check" | wc -w) + fi + + # E. 判定就绪标准: + # 1) UCI 中有效 wifi-device 数量 > 0 + # 2) 若检测到物理 PHY,UCI radio 数量必须完全覆盖检测到的 PHY 数量 + if [ $uci_count -gt 0 ]; then + if [ $phy_count -eq 0 ] || [ $uci_count -ge $phy_count ]; then + return 0 + fi + fi + + sleep 1 + waited=$((waited + 1)) + done + + # 超时保护:只要至少有一个 radio 节点,允许降级继续 + if [ $uci_count -gt 0 ]; then + return 0 + fi + return 1 +} + +# 执行深度就绪等待 +if ! wait_wifi_ready; then + echo "[ERROR] 未检测到可用无线硬件或无线配置生成超时!" >&2 + exit 1 +fi + +# 3. 识别射频频段函数 (2g, 5g, 6g) detect_band() { local radio="$1" local band="$(uci -q get wireless.${radio}.band 2>/dev/null | tr 'A-Z' 'a-z')" @@ -86,9 +146,9 @@ detect_band() { *6g*) echo "6g"; return ;; esac - # 若未定义 band 属性,根据 channel(信道)推断 + # 信道 (channel) 推断 local channel="$(uci -q get wireless.${radio}.channel 2>/dev/null)" - if [ -n "$channel" ] && [ "$channel" -eq "$channel" ] 2>/dev/null; then + if [ -n "$channel" ] && [ "$channel" -eq "$channel" 2>/dev/null ]; then if [ "$channel" -ge 1 ] && [ "$channel" -le 14 ]; then echo "2g"; return elif [ "$channel" -ge 32 ] && [ "$channel" -le 177 ]; then @@ -98,7 +158,7 @@ detect_band() { fi fi - # 根据 hwmode 模式推断 + # hwmode 推断 local hwmode="$(uci -q get wireless.${radio}.hwmode 2>/dev/null | tr 'A-Z' 'a-z')" case "$hwmode" in *a*) echo "5g"; return ;; @@ -117,20 +177,6 @@ detect_band() { echo "2g" } -# 3. 检查并生成无线配置(非空探测,避免死等 10 秒) -if [ ! -s /etc/config/wireless ]; then - [ -x /sbin/wifi ] && /sbin/wifi config >/dev/null 2>&1 - for i in $(seq 1 10); do - [ -s /etc/config/wireless ] && break - sleep 1 - done -fi - -if [ ! -s /etc/config/wireless ]; then - echo "[ERROR] 未检测到无线配置或无可用无线设备!" >&2 - exit 1 -fi - # 4. 加载系统发行版信息(若存在) [ -f /etc/openwrt_release ] && . /etc/openwrt_release @@ -222,6 +268,7 @@ done # 提交配置 uci commit wireless 2>/dev/null +# 若存在 base_config(kiddin9 固件状态记录),更新状态 if uci -q get base_config.@status[0] >/dev/null 2>&1; then uci -q set base_config.@status[0].wifi=1 uci commit base_config 2>/dev/null