Adding GetWifiIfaceBySSID and cleaning tests

This commit is contained in:
Philippe Caseiro 2018-10-29 11:19:40 +01:00
parent 6e84372169
commit 077ec7bd7a
4 changed files with 42 additions and 0 deletions

View File

@ -22,6 +22,13 @@ wireless.radio1.path='soc/soc:pcie/pci0000:00/0000:00:02.0/0000:02:00.0'
wireless.radio1.channel='1'
wireless.radio1.legacy_rates='1'
wireless.radio1.disabled='0'
wireless.@wifi-iface[0]=wifi-iface
wireless.@wifi-iface[0].ssid='Quid'
wireless.@wifi-iface[0].encryption='psk2'
wireless.@wifi-iface[0].device='radio1'
wireless.@wifi-iface[0].mode='ap'
wireless.@wifi-iface[0].disabled='0'
wireless.@wifi-iface[0].network='efs'
wireless.@wifi-iface[1]=wifi-iface
wireless.@wifi-iface[1].device='radio1'
wireless.@wifi-iface[1].mode='ap'

17
uci.go
View File

@ -122,6 +122,23 @@ func (u *UCI) GetWifiIfaceByName(name string) *UCIWirelessInterface {
return nil
}
// GetWifiIfaceBySSID returns the wifi Interface by Index
func (u *UCI) GetWifiIfaceBySSID(ssid string) *UCIWirelessInterface {
u.LoadWirelessConf()
ifaces := u.Wireless.Interfaces
if len(ifaces) <= 0 {
fmt.Println("ifaces are empty !!! fuck")
return nil
}
for _, ifa := range ifaces {
if ifa.Ssid == ssid {
return ifa
}
}
fmt.Println("iface not found !")
return nil
}
// GetWifiIfaces wifi interfaces in configuration
func (u *UCI) GetWifiIfaces() []*UCIWirelessInterface {
return u.Wireless.Interfaces

View File

@ -2,6 +2,7 @@ package owrt
import (
"fmt"
"io/ioutil"
"testing"
)
@ -98,3 +99,18 @@ func TestUCIReload(t *testing.T) {
t.Error("Stderr is not empty ...")
}
}
func TestGetWifiIfaceBySSID(t *testing.T) {
config, err := ioutil.ReadFile("./testdata/uci_show_wireless_2_cards.txt")
if err != nil {
t.Fatal(err)
}
exec := createMockExecutor(string(config), "", 0)
uci := NewUCIWithExecutor(exec)
uci.LoadWirelessConf()
wifi := uci.GetWifiIfaceBySSID("Pyxis2")
fmt.Printf("%s\n", wifi.Ssid)
if g, e := wifi.Ssid, "Pyxis2"; g != e {
t.Fatalf("Wifi SSID have to be [%s] and we have [%s]", e, g)
}
}

View File

@ -79,6 +79,7 @@ func (wc *UCIWirelessConf) parseInterfaces(lines []string) int {
for key, expr := range matches {
if expr.MatchString(li) {
value := strings.Split(li, "=")[1]
value = strings.Trim(value, "'")
if key == "Name" {
wc.Interfaces[idx].Name = value
}
@ -93,6 +94,7 @@ func (wc *UCIWirelessConf) parseInterfaces(lines []string) int {
wc.Interfaces[idx].Mode = value
}
if key == "Ssid" {
fmt.Printf("Fixing SSID FOR %s\n", value)
wc.Interfaces[idx].Ssid = value
}
if key == "Encryption" {