From 2f3390cf363d3f2542e87359710b694ec3d386c8 Mon Sep 17 00:00:00 2001 From: Simone Margaritelli Date: Mon, 25 Nov 2019 11:59:04 +0100 Subject: [PATCH] fix: using iw instead of iwconfig whenever possible (fixes #657) --- network/net.go | 9 ++++++++- network/net_linux.go | 21 ++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/network/net.go b/network/net.go index 47be68d8..35d2510a 100644 --- a/network/net.go +++ b/network/net.go @@ -285,7 +285,14 @@ func ActivateInterface(name string) error { } func SetInterfaceTxPower(name string, txpower int) error { - if core.HasBinary("iwconfig") { + if core.HasBinary("iw") { + Debug("SetInterfaceTxPower(%s, %d) iw based", name, txpower) + if _, err := core.Exec("iw", []string{"dev", name, "set", "txpower", fmt.Sprintf("%dmBm", + txpower)}); err != nil { + return err + } + } else if core.HasBinary("iwconfig") { + Debug("SetInterfaceTxPower(%s, %d) iwconfig based", name, txpower) if out, err := core.Exec("iwconfig", []string{name, "txpower", fmt.Sprintf("%d", txpower)}); err != nil { return err } else if out != "" { diff --git a/network/net_linux.go b/network/net_linux.go index a93fb40f..b56788b0 100644 --- a/network/net_linux.go +++ b/network/net_linux.go @@ -41,11 +41,22 @@ func SetInterfaceChannel(iface string, channel int) error { return nil } - out, err := core.Exec("iwconfig", []string{iface, "channel", fmt.Sprintf("%d", channel)}) - if err != nil { - return err - } else if out != "" { - return fmt.Errorf("Unexpected output while setting interface %s to channel %d: %s", iface, channel, out) + if core.HasBinary("iw") { + Debug("SetInterfaceChannel(%s, %d) iw based", iface, channel) + out, err := core.Exec("iw", []string{"dev", iface, "set", "channel", fmt.Sprintf("%d", channel)}) + if err != nil { + return err + } else if out != "" { + return fmt.Errorf("Unexpected output while setting interface %s to channel %d: %s", iface, channel, out) + } + } else if core.HasBinary("iwconfig") { + Debug("SetInterfaceChannel(%s, %d) iwconfig based") + out, err := core.Exec("iwconfig", []string{iface, "channel", fmt.Sprintf("%d", channel)}) + if err != nil { + return err + } else if out != "" { + return fmt.Errorf("Unexpected output while setting interface %s to channel %d: %s", iface, channel, out) + } } SetInterfaceCurrentChannel(iface, channel)