(iface string, channel int)
| 33 | } |
| 34 | |
| 35 | func SetInterfaceChannel(iface string, channel int) error { |
| 36 | curr := GetInterfaceChannel(iface) |
| 37 | // the interface is already on this channel |
| 38 | if curr == channel { |
| 39 | return nil |
| 40 | } |
| 41 | |
| 42 | if core.HasBinary("iw") { |
| 43 | // Debug("SetInterfaceChannel(%s, %d) iw based", iface, channel) |
| 44 | // out, err := core.Exec("iw", []string{"dev", iface, "set", "channel", fmt.Sprintf("%d", channel)}) |
| 45 | out, err := core.Exec("iw", []string{"dev", iface, "set", "freq", fmt.Sprintf("%d", Dot11Chan2Freq(channel))}) |
| 46 | |
| 47 | if err != nil { |
| 48 | return fmt.Errorf("iw: out=%s err=%s", out, err) |
| 49 | } else if out != "" { |
| 50 | return fmt.Errorf("Unexpected output while setting interface %s to channel %d: %s", iface, channel, out) |
| 51 | } |
| 52 | } else if core.HasBinary("iwconfig") { |
| 53 | // Debug("SetInterfaceChannel(%s, %d) iwconfig based") |
| 54 | out, err := core.Exec("iwconfig", []string{iface, "channel", fmt.Sprintf("%d", channel)}) |
| 55 | if err != nil { |
| 56 | return fmt.Errorf("iwconfig: out=%s err=%s", out, err) |
| 57 | } else if out != "" { |
| 58 | return fmt.Errorf("Unexpected output while setting interface %s to channel %d: %s", iface, channel, out) |
| 59 | } |
| 60 | } else { |
| 61 | return fmt.Errorf("no iw or iwconfig binaries found in $PATH") |
| 62 | } |
| 63 | |
| 64 | SetInterfaceCurrentChannel(iface, channel) |
| 65 | return nil |
| 66 | } |
| 67 | |
| 68 | var iwlistFreqParser = regexp.MustCompile(`^\s+Channel.([0-9]+)\s+:\s+([0-9\.]+)\s+GHz.*$`) |
| 69 |
no test coverage detected