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> {