From ddc839400a8466599a1c94e70b918b2a8ce19b0c Mon Sep 17 00:00:00 2001 From: ssmithx Date: Mon, 29 Jun 2026 16:08:35 +0000 Subject: [PATCH] fix(openwrt): use iw dev for wireless interface detection wlan0 doesn't exist on OpenWrt 25.x with mt76 drivers (Cudy TR1200); interfaces are named phy0-ap0 etc. `iw dev` handles all mac80211 naming styles. The old while-read loop also exited with code 1 when no match was found, causing run_ok to fail. Co-Authored-By: Claude Sonnet 4.6 --- core/openwrt/src/wifi_scan.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/core/openwrt/src/wifi_scan.rs b/core/openwrt/src/wifi_scan.rs index a39626e7..8cb569c0 100644 --- a/core/openwrt/src/wifi_scan.rs +++ b/core/openwrt/src/wifi_scan.rs @@ -19,18 +19,22 @@ pub fn scan_networks(router: &Router) -> Result> { } fn find_wireless_iface(router: &Router) -> Result { - let (_, code) = router.run("test -d /sys/class/net/wlan0/wireless")?; - if code == 0 { - return Ok("wlan0".to_string()); - } - let out = router.run_ok( - "ls /sys/class/net/ | while read i; do [ -d /sys/class/net/$i/wireless ] && echo $i && break; done", - )?; + // `iw dev` works on any mac80211 system and handles new-style interface names + // (phy0-ap0, phy0-sta0, etc.) used by OpenWrt 25.x mt76 drivers. + let (out, _) = router.run("iw dev 2>/dev/null | awk '/Interface/{print $2}' | head -1")?; let iface = out.trim().to_string(); - if iface.is_empty() { - anyhow::bail!("No wireless interface found on this router"); + if !iface.is_empty() { + return Ok(iface); } - Ok(iface) + // Fallback: any entry in /sys/class/net with a wireless subdir + let (out2, _) = router.run( + "for i in /sys/class/net/*/wireless; do [ -d \"$i\" ] && basename $(dirname $i) && break; done 2>/dev/null", + )?; + let iface2 = out2.trim().to_string(); + if !iface2.is_empty() { + return Ok(iface2); + } + anyhow::bail!("No wireless interface found on this router") } fn parse_iwinfo_scan(output: &str) -> Result> {