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 <noreply@anthropic.com>
This commit is contained in:
parent
9a782fb551
commit
ddc839400a
@ -19,18 +19,22 @@ pub fn scan_networks(router: &Router) -> Result<Vec<ScannedNetwork>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn find_wireless_iface(router: &Router) -> Result<String> {
|
fn find_wireless_iface(router: &Router) -> Result<String> {
|
||||||
let (_, code) = router.run("test -d /sys/class/net/wlan0/wireless")?;
|
// `iw dev` works on any mac80211 system and handles new-style interface names
|
||||||
if code == 0 {
|
// (phy0-ap0, phy0-sta0, etc.) used by OpenWrt 25.x mt76 drivers.
|
||||||
return Ok("wlan0".to_string());
|
let (out, _) = router.run("iw dev 2>/dev/null | awk '/Interface/{print $2}' | head -1")?;
|
||||||
}
|
|
||||||
let out = router.run_ok(
|
|
||||||
"ls /sys/class/net/ | while read i; do [ -d /sys/class/net/$i/wireless ] && echo $i && break; done",
|
|
||||||
)?;
|
|
||||||
let iface = out.trim().to_string();
|
let iface = out.trim().to_string();
|
||||||
if iface.is_empty() {
|
if !iface.is_empty() {
|
||||||
anyhow::bail!("No wireless interface found on this router");
|
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<Vec<ScannedNetwork>> {
|
fn parse_iwinfo_scan(output: &str) -> Result<Vec<ScannedNetwork>> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user