Lint Clean !
This commit is contained in:
parent
aed2271bf7
commit
cadd3482a2
|
@ -67,9 +67,11 @@ type CreateIfaceResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// OwrtCreateWifiInterface Create a WifiInterface in openwrt
|
// OwrtCreateWifiInterface Create a WifiInterface in openwrt
|
||||||
func (o *OrionService) OwrtCreateWifiInterface(r *http.Request, args *CreateIfaceArgs, reply *CreateIfaceResponse) error {
|
func (o *OrionService) OwrtCreateWifiInterface(r *http.Request,
|
||||||
|
args *CreateIfaceArgs,
|
||||||
|
reply *CreateIfaceResponse) error {
|
||||||
reply.Iface = nil
|
reply.Iface = nil
|
||||||
if args.Cleanup == true {
|
if args.Cleanup {
|
||||||
o.UCI.LoadWirelessConf()
|
o.UCI.LoadWirelessConf()
|
||||||
w := o.UCI.GetWifiIfaces()
|
w := o.UCI.GetWifiIfaces()
|
||||||
for _, iface := range w {
|
for _, iface := range w {
|
||||||
|
@ -127,7 +129,9 @@ type ConnectIfaceResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// OwrtConnectWifiInterface connects a given Wifi Interface to a given SSID
|
// OwrtConnectWifiInterface connects a given Wifi Interface to a given SSID
|
||||||
func (o *OrionService) OwrtConnectWifiInterface(r *http.Request, args *ConnectIfaceArgs, reply *ConnectIfaceResponse) error {
|
func (o *OrionService) OwrtConnectWifiInterface(r *http.Request,
|
||||||
|
args *ConnectIfaceArgs,
|
||||||
|
reply *ConnectIfaceResponse) error {
|
||||||
o.UCI.LoadWirelessConf()
|
o.UCI.LoadWirelessConf()
|
||||||
iface := o.UCI.GetWifiIface(args.Iface.Index)
|
iface := o.UCI.GetWifiIface(args.Iface.Index)
|
||||||
cells := iface.Scan()
|
cells := iface.Scan()
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (wi *UCIWirelessInterface) GetSysDevName(sysDir string) string {
|
||||||
return "ERROR123-FILE-DONES-NOT-EXIST"
|
return "ERROR123-FILE-DONES-NOT-EXIST"
|
||||||
}
|
}
|
||||||
|
|
||||||
filepath.Walk(sysDir, func(path string, f os.FileInfo, _ error) error {
|
err := filepath.Walk(sysDir, func(path string, f os.FileInfo, _ error) error {
|
||||||
patt := fmt.Sprintf("%s/%s/.*/address", wi.DevicePath, "net")
|
patt := fmt.Sprintf("%s/%s/.*/address", wi.DevicePath, "net")
|
||||||
r, err := regexp.MatchString(patt, path)
|
r, err := regexp.MatchString(patt, path)
|
||||||
if err == nil && r {
|
if err == nil && r {
|
||||||
|
@ -56,6 +56,9 @@ func (wi *UCIWirelessInterface) GetSysDevName(sysDir string) string {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err.Error()
|
||||||
|
}
|
||||||
fmt.Println(found)
|
fmt.Println(found)
|
||||||
wi.SysDevName = found
|
wi.SysDevName = found
|
||||||
return found
|
return found
|
||||||
|
@ -184,8 +187,7 @@ func (wi *UCIWirelessInterface) Update(uci *UCI) *Action {
|
||||||
|
|
||||||
// Scan starts a scan for wifi networks with this device
|
// Scan starts a scan for wifi networks with this device
|
||||||
func (wi *UCIWirelessInterface) Scan() []*WifiCell {
|
func (wi *UCIWirelessInterface) Scan() []*WifiCell {
|
||||||
var devName string
|
devName := wi.GetSysDevName("")
|
||||||
devName = wi.GetSysDevName("")
|
|
||||||
|
|
||||||
wifi := NewWifiScanner(devName)
|
wifi := NewWifiScanner(devName)
|
||||||
return wifi.Scan()
|
return wifi.Scan()
|
||||||
|
|
|
@ -4,18 +4,30 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ifaceName = "Test"
|
||||||
|
ifaceNetwork = "Pyxis"
|
||||||
|
ifaceSysDevName = "wlanX"
|
||||||
|
ifaceEnc = "psk"
|
||||||
|
ifaceSSID = "PyxisWifi"
|
||||||
|
ifaceKey = "qsmdflkjqslmdfkjqslmfkdj"
|
||||||
|
ifaceDevice = "radioX"
|
||||||
|
ifaceMode = "ap"
|
||||||
|
ifaceBssid = "00:00:00:00:00"
|
||||||
|
)
|
||||||
|
|
||||||
func TestGetSysDevName(t *testing.T) {
|
func TestGetSysDevName(t *testing.T) {
|
||||||
iface := NewUCIWirelessInterface()
|
iface := NewUCIWirelessInterface()
|
||||||
iface.Name = "Test"
|
iface.Name = ifaceName
|
||||||
iface.Index = 1
|
iface.Index = 1
|
||||||
iface.Device = "radioX"
|
iface.Device = ifaceDevice
|
||||||
iface.DevicePath = "soc/soc:pcie/pci0000:00/0000:00:02.0/0000:02:00.0"
|
iface.DevicePath = "soc/soc:pcie/pci0000:00/0000:00:02.0/0000:02:00.0"
|
||||||
iface.Mode = "ap"
|
iface.Mode = ifaceMode
|
||||||
iface.Ssid = "PyxisWifi"
|
iface.Ssid = ifaceSSID
|
||||||
iface.Bssid = "00:00:00:00:00"
|
iface.Bssid = ifaceBssid
|
||||||
iface.Network = "Pyxis"
|
iface.Network = ifaceNetwork
|
||||||
iface.Encryption = "psk"
|
iface.Encryption = ifaceEnc
|
||||||
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
|
iface.Key = ifaceKey
|
||||||
|
|
||||||
if g, e := iface.GetSysDevName("testdata/sys/"), "wlan1"; g != e {
|
if g, e := iface.GetSysDevName("testdata/sys/"), "wlan1"; g != e {
|
||||||
t.Fatalf("UCIWirelessInterface.GetDeviceSysName() failed ! Got: %s Expect: %s", g, e)
|
t.Fatalf("UCIWirelessInterface.GetDeviceSysName() failed ! Got: %s Expect: %s", g, e)
|
||||||
|
@ -32,14 +44,14 @@ func TestCreate(t *testing.T) {
|
||||||
uci := NewUCIWithExecutor(exec)
|
uci := NewUCIWithExecutor(exec)
|
||||||
|
|
||||||
iface := NewUCIWirelessInterface()
|
iface := NewUCIWirelessInterface()
|
||||||
iface.Name = "Test"
|
iface.Name = ifaceName
|
||||||
iface.Device = "radioX"
|
iface.Device = ifaceDevice
|
||||||
iface.Mode = "ap"
|
iface.Mode = ifaceMode
|
||||||
iface.Ssid = "PyxisWifi"
|
iface.Ssid = ifaceSSID
|
||||||
iface.Bssid = "00:00:00:00:00"
|
iface.Bssid = ifaceBssid
|
||||||
iface.Network = "Pyxis"
|
iface.Network = ifaceNetwork
|
||||||
iface.Encryption = "psk"
|
iface.Encryption = ifaceEnc
|
||||||
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
|
iface.Key = ifaceKey
|
||||||
|
|
||||||
if iface.Create(uci).ReturnCode != 0 {
|
if iface.Create(uci).ReturnCode != 0 {
|
||||||
t.Fatalf("UCIWirelessInterface.Create() failed !")
|
t.Fatalf("UCIWirelessInterface.Create() failed !")
|
||||||
|
@ -51,16 +63,16 @@ func TestUpdate(t *testing.T) {
|
||||||
uci := NewUCIWithExecutor(exec)
|
uci := NewUCIWithExecutor(exec)
|
||||||
|
|
||||||
iface := NewUCIWirelessInterface()
|
iface := NewUCIWirelessInterface()
|
||||||
iface.Name = "Test"
|
iface.Name = ifaceName
|
||||||
iface.Index = 1
|
iface.Index = 1
|
||||||
iface.Device = "radioX"
|
iface.Device = ifaceDevice
|
||||||
iface.SysDevName = "wlanX"
|
iface.SysDevName = ifaceSysDevName
|
||||||
iface.Mode = "ap"
|
iface.Mode = ifaceMode
|
||||||
iface.Ssid = "PyxisWifi"
|
iface.Ssid = ifaceSSID
|
||||||
iface.Bssid = "00:00:00:00:00"
|
iface.Bssid = ifaceBssid
|
||||||
iface.Network = "Pyxis"
|
iface.Network = ifaceNetwork
|
||||||
iface.Encryption = "psk"
|
iface.Encryption = ifaceEnc
|
||||||
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
|
iface.Key = ifaceKey
|
||||||
|
|
||||||
if iface.Create(uci).ReturnCode != 0 {
|
if iface.Create(uci).ReturnCode != 0 {
|
||||||
t.Fatalf("UCIWirelessInterface.Create() failed !")
|
t.Fatalf("UCIWirelessInterface.Create() failed !")
|
||||||
|
@ -78,16 +90,16 @@ func TestDelete(t *testing.T) {
|
||||||
uci := NewUCIWithExecutor(exec)
|
uci := NewUCIWithExecutor(exec)
|
||||||
|
|
||||||
iface := NewUCIWirelessInterface()
|
iface := NewUCIWirelessInterface()
|
||||||
iface.Name = "Test"
|
iface.Name = ifaceName
|
||||||
iface.Index = 1
|
iface.Index = 1
|
||||||
iface.Device = "radioX"
|
iface.Device = ifaceDevice
|
||||||
iface.SysDevName = "wlanX"
|
iface.SysDevName = ifaceSysDevName
|
||||||
iface.Mode = "ap"
|
iface.Mode = ifaceMode
|
||||||
iface.Ssid = "PyxisWifi"
|
iface.Ssid = ifaceSSID
|
||||||
iface.Bssid = "00:00:00:00:00"
|
iface.Bssid = ifaceBssid
|
||||||
iface.Network = "Pyxis"
|
iface.Network = ifaceNetwork
|
||||||
iface.Encryption = "psk"
|
iface.Encryption = ifaceEnc
|
||||||
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
|
iface.Key = ifaceKey
|
||||||
|
|
||||||
if iface.Delete(uci).ReturnCode != 0 {
|
if iface.Delete(uci).ReturnCode != 0 {
|
||||||
t.Fatalf("UCIWirelessInterface.Delete() failed !")
|
t.Fatalf("UCIWirelessInterface.Delete() failed !")
|
||||||
|
@ -100,16 +112,16 @@ func TestConnect(t *testing.T) {
|
||||||
uci := NewUCIWithExecutor(exec)
|
uci := NewUCIWithExecutor(exec)
|
||||||
|
|
||||||
iface := NewUCIWirelessInterface()
|
iface := NewUCIWirelessInterface()
|
||||||
iface.Name = "Test"
|
iface.Name = ifaceName
|
||||||
iface.Index = 1
|
iface.Index = 1
|
||||||
iface.Device = "radioX"
|
iface.Device = ifaceDevice
|
||||||
iface.SysDevName = "wlanX"
|
iface.SysDevName = ifaceSysDevName
|
||||||
iface.Mode = "ap"
|
iface.Mode = ifaceMode
|
||||||
iface.Ssid = "PyxisWifi"
|
iface.Ssid = ifaceSSID
|
||||||
iface.Bssid = "00:00:00:00:00"
|
iface.Bssid = ifaceBssid
|
||||||
iface.Network = "Pyxis"
|
iface.Network = ifaceNetwork
|
||||||
iface.Encryption = "psk"
|
iface.Encryption = ifaceEnc
|
||||||
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
|
iface.Key = ifaceKey
|
||||||
|
|
||||||
wifiCell := NewWifiCell("PyxisWifi", "01:01:01:01:01", "psk")
|
wifiCell := NewWifiCell("PyxisWifi", "01:01:01:01:01", "psk")
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ func (w *WifiScanner) parseWifiCells(stdout string) int {
|
||||||
enc = NONE
|
enc = NONE
|
||||||
cell := NewWifiCell(ssid, mac, enc)
|
cell := NewWifiCell(ssid, mac, enc)
|
||||||
w.Cells = append(w.Cells, cell)
|
w.Cells = append(w.Cells, cell)
|
||||||
ssid, mac, enc = "", "", ""
|
ssid, enc = "", ""
|
||||||
}
|
}
|
||||||
macRegexp := regexp.MustCompile(macExpr)
|
macRegexp := regexp.MustCompile(macExpr)
|
||||||
mac = macRegexp.FindString(line)
|
mac = macRegexp.FindString(line)
|
||||||
|
|
Reference in New Issue