Files
shenlei 530a3690da
Offline project checks / check (push) Canceled after 0s
feat: add WCN3990 Wi-Fi bringup service, battery protection, and bringup automation
- Add phone-dsp.openrc to initialize Hexagon DSP, rmtfs, pd-mapper, and ath10k_snoc
- Update phone-battery-guard threshold to 80% with power supply node fallbacks
- Enhance phone-cellular-setup with battery gate checks, RF locks, and unit tests
- Include bringup, flashing, and inspection automation scripts for platina
- Update candidate IPA v2.6 patches and package locks
2026-11-12 14:54:23 +09:00

121 lines
4.6 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Poll for en21 link activation, configure Xiaomi Mi 8 Lite network service,
and execute complete cellular & EasyTier mesh bringup once SSH is available.
"""
import socket
import subprocess
import sys
import time
TARGET_IP = "172.16.42.1"
SSH_KEY = "/Users/shenlei/Work/sshKey/oracle_tokyo_ARM.key"
def log(msg):
print(f"[{time.strftime('%H:%M:%S')}] {msg}", flush=True)
def is_en21_active():
res = subprocess.run(["ifconfig", "en21"], capture_output=True, text=True)
return "status: active" in res.stdout
def configure_network():
service = "Xiaomi Mi 8 Lite"
log(f"Configuring network service '{service}'...")
subprocess.run(["networksetup", "-setmanual", service, "172.16.42.2", "255.255.255.0", "172.16.42.1"], capture_output=True)
def run_ssh(cmd, timeout=30):
ssh_cmd = [
"ssh",
"-o", "StrictHostKeyChecking=no",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "ConnectTimeout=5",
"-i", SSH_KEY,
f"server@{TARGET_IP}",
cmd
]
res = subprocess.run(ssh_cmd, capture_output=True, text=True, timeout=timeout)
return res.returncode, res.stdout, res.stderr
def main():
log("=== Phone Online Watcher Started ===")
log("Monitoring 'en21' for active carrier link...")
active = False
start = time.time()
while time.time() - start < 180:
if is_en21_active():
log(">>> en21 link is ACTIVE! <<<")
active = True
break
time.sleep(1)
if not active:
log("Notice: en21 still inactive. A physical USB cable replug will trigger macOS NCM link sync.")
return 1
configure_network()
time.sleep(2)
log("Testing SSH port 22 on 172.16.42.1...")
ssh_up = False
start = time.time()
while time.time() - start < 60:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1.0)
try:
s.connect((TARGET_IP, 22))
s.close()
log(f"SUCCESS: SSH port 22 OPEN after {int(time.time() - start)}s!")
ssh_up = True
break
except Exception:
pass
time.sleep(1)
if not ssh_up:
log("ERROR: Timed out waiting for SSH port 22.")
return 1
time.sleep(2)
log("Logging into phone via SSH...")
code, out, err = run_ssh("uname -a; uptime; cat /sys/class/power_supply/qcom-battery/voltage_now; cat /sys/class/power_supply/qcom-battery/capacity")
log(f"System status (code={code}):\n{out.strip()}")
log("\n--- Checking blacklisted modules (expect empty) ---")
code, out, err = run_ssh("lsmod | grep -E 'qcom_q6v5_mss|ipa'")
log(f"Loaded modem modules:\n{out.strip()}")
log("\n--- Step 1: Check Battery Gate Policy ---")
code, out, err = run_ssh("sudo /usr/local/sbin/platina-cellular --battery-gate")
log(f"Battery gate result (code={code}):\n{out.strip()}")
log("\n--- Step 2: Start rmtfs and load modem/IPA modules safely ---")
code, out, err = run_ssh("sudo rc-service rmtfs start; sudo /usr/local/sbin/platina-cellular --load-modules")
log(f"Load modules result (code={code}):\n{out.strip()}")
log("\n--- Step 3: Verify IPA sysfs endpoints (expect fixed TX: 3, RX: 16) ---")
code, out, err = run_ssh("cat /sys/devices/platform/soc@0/14780000.ipa/modem/tx_endpoint_id; cat /sys/devices/platform/soc@0/14780000.ipa/modem/rx_endpoint_id")
log(f"IPA sysfs endpoints (code={code}):\n{out.strip()}")
log("\n--- Step 4: Lock RAT to LTE and bands to China Unicom (1,3), bring online ---")
code, out, err = run_ssh("sudo /usr/local/sbin/platina-cellular --optimize-rf --rat lte --bands 1,3; sudo /usr/local/sbin/platina-cellular --online")
log(f"RF lock and online result (code={code}):\n{out.strip()}")
log("\n--- Step 5: Activate cellular data connection ---")
code, out, err = run_ssh("sudo /usr/local/sbin/platina-cellular --auto --once")
log(f"Cellular data setup (code={code}):\n{out.strip()}")
log("\n--- Step 6: Test cellular data path ping ---")
code, out, err = run_ssh("ip addr show rmnet_ipa0 2>/dev/null; ip route; ping -c 4 -I rmnet_ipa0 1.1.1.1 2>/dev/null || ping -c 4 1.1.1.1")
log(f"Connectivity test (code={code}):\n{out.strip()}")
log("\n--- Step 7: Check EasyTier mesh status and ping Tokyo node ---")
code, out, err = run_ssh("sudo rc-service easytier status || sudo rc-service easytier start; sudo /usr/local/sbin/platina-mesh --status; ping -c 4 192.168.20.2")
log(f"EasyTier mesh status (code={code}):\n{out.strip()}")
log("\n=== Complete Platina Bringup Successful! ===")
return 0
if __name__ == "__main__":
sys.exit(main())