#!/bin/sh # wifi-band-verify.sh — LOG-ONLY diagnostic. Compares UCI labels against the # PHYSICAL band each netdev is on and records the verdict to logread. # NEVER writes UCI: with ra0/rax0 ↔ dat binding random per boot (and band-content # invariant keeping physical always correct), mutating UCI oscillates across # wifi reloads. Logging the mismatch is enough — LuCI display patch (wireless.js # getActiveSSID) makes the UI match iwinfo truth regardless of UCI labels. # Triggered by rc.local at boot and mtwifi_cfg dispatcher tail. # Commit-only would still be loop-safe, but useless: detection is non-deterministic # across reloads, so any commit causes oscillation. Log-only is structurally stable. LOCK=/tmp/wifi-band-verify.lock NOW=$(date +%s) if [ -f "$LOCK" ]; then LAST=$(cat "$LOCK" 2>/dev/null) [ -n "$LAST" ] && [ $((NOW - LAST)) -lt 120 ] && exit 0 fi echo "$NOW" > "$LOCK" log() { logger -t wifi-band-verify -- "$*"; } get_ch() { iwinfo "$1" info 2>/dev/null | awk '/Channel:/ {print $4}'; } get_essid(){ iwinfo "$1" info 2>/dev/null | awk -F"\x22" '/ESSID:/ {print $2}'; } # Phase 1: wait until both radios report identical channels on two consecutive # 10s probes (guards against mid-init transient reads; max 18 rounds = 3min). ra0ch=""; rax0ch=""; stable=0; i=0 while [ $i -lt 18 ]; do c1=$(get_ch ra0); c2=$(get_ch rax0) case "$c1" in ""|*[!0-9]*) c1="" ;; esac case "$c2" in ""|*[!0-9]*) c2="" ;; esac if [ -n "$c1" ] && [ -n "$c2" ] && [ "$c1" = "$ra0ch" ] && [ "$c2" = "$rax0ch" ]; then stable=1; break fi ra0ch=$c1; rax0ch=$c2 i=$((i+1)); sleep 10 done [ $stable -eq 1 ] || { log "radios not stable after 3min; skipped"; exit 0; } # Phase 2: physical band from channel (2g ≤14, 5g ≥36) band_of() { [ "$1" -le 14 ] && echo 2g || echo 5g; } ra0band=$(band_of "$ra0ch"); rax0band=$(band_of "$rax0ch") [ "$ra0band" = "$rax0band" ] && { log "both radios on $ra0band ch$ra0ch/$rax0ch; abnormal"; exit 0; } # Phase 3: read UCI labels and live ESSIDs, log verdict — NO mutation. uci -q get wireless.MT7981_1_1 >/dev/null || exit 0 uci -q get wireless.MT7981_1_2 >/dev/null || exit 0 u1=$(uci -q get wireless.MT7981_1_1.band) u2=$(uci -q get wireless.MT7981_1_2.band) s1=$(uci -q get wireless.default_MT7981_1_1.ssid) s2=$(uci -q get wireless.default_MT7981_1_2.ssid) e1=$(get_essid ra0); e2=$(get_essid rax0) if [ "$u1" = "$ra0band" ] && [ "$u2" = "$rax0band" ] && [ "$s1" = "$e1" ] && [ "$s2" = "$e2" ]; then log "consistent: ra0=$ra0band ch$ra0ch [$e1], rax0=$rax0band ch$rax0ch [$e2]; uci=$u1/$u2" else log "MISMATCH (no-op): ra0=$ra0band ch$ra0ch [$e1], rax0=$rax0band ch$rax0ch [$e2]; uci=$u1/$u2 ssid=$s1/$s2" fi exit 0