Lint Clean !
This commit is contained in:
parent
aed2271bf7
commit
cadd3482a2
|
@ -67,9 +67,11 @@ type CreateIfaceResponse struct {
|
|||
}
|
||||
|
||||
// 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
|
||||
if args.Cleanup == true {
|
||||
if args.Cleanup {
|
||||
o.UCI.LoadWirelessConf()
|
||||
w := o.UCI.GetWifiIfaces()
|
||||
for _, iface := range w {
|
||||
|
@ -127,7 +129,9 @@ type ConnectIfaceResponse struct {
|
|||
}
|
||||
|
||||
// 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()
|
||||
iface := o.UCI.GetWifiIface(args.Iface.Index)
|
||||
cells := iface.Scan()
|
||||
|
|
|
@ -45,7 +45,7 @@ func (wi *UCIWirelessInterface) GetSysDevName(sysDir string) string {
|
|||
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")
|
||||
r, err := regexp.MatchString(patt, path)
|
||||
if err == nil && r {
|
||||
|
@ -56,6 +56,9 @@ func (wi *UCIWirelessInterface) GetSysDevName(sysDir string) string {
|
|||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
fmt.Println(found)
|
||||
wi.SysDevName = found
|
||||
return found
|
||||
|
@ -184,8 +187,7 @@ func (wi *UCIWirelessInterface) Update(uci *UCI) *Action {
|
|||
|
||||
// Scan starts a scan for wifi networks with this device
|
||||
func (wi *UCIWirelessInterface) Scan() []*WifiCell {
|
||||
var devName string
|
||||
devName = wi.GetSysDevName("")
|
||||
devName := wi.GetSysDevName("")
|
||||
|
||||
wifi := NewWifiScanner(devName)
|
||||
return wifi.Scan()
|
||||
|
|
|
@ -4,18 +4,30 @@ import (
|
|||
"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) {
|
||||
iface := NewUCIWirelessInterface()
|
||||
iface.Name = "Test"
|
||||
iface.Name = ifaceName
|
||||
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.Mode = "ap"
|
||||
iface.Ssid = "PyxisWifi"
|
||||
iface.Bssid = "00:00:00:00:00"
|
||||
iface.Network = "Pyxis"
|
||||
iface.Encryption = "psk"
|
||||
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
|
||||
iface.Mode = ifaceMode
|
||||
iface.Ssid = ifaceSSID
|
||||
iface.Bssid = ifaceBssid
|
||||
iface.Network = ifaceNetwork
|
||||
iface.Encryption = ifaceEnc
|
||||
iface.Key = ifaceKey
|
||||
|
||||
if g, e := iface.GetSysDevName("testdata/sys/"), "wlan1"; 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)
|
||||
|
||||
iface := NewUCIWirelessInterface()
|
||||
iface.Name = "Test"
|
||||
iface.Device = "radioX"
|
||||
iface.Mode = "ap"
|
||||
iface.Ssid = "PyxisWifi"
|
||||
iface.Bssid = "00:00:00:00:00"
|
||||
iface.Network = "Pyxis"
|
||||
iface.Encryption = "psk"
|
||||
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
|
||||
iface.Name = ifaceName
|
||||
iface.Device = ifaceDevice
|
||||
iface.Mode = ifaceMode
|
||||
iface.Ssid = ifaceSSID
|
||||
iface.Bssid = ifaceBssid
|
||||
iface.Network = ifaceNetwork
|
||||
iface.Encryption = ifaceEnc
|
||||
iface.Key = ifaceKey
|
||||
|
||||
if iface.Create(uci).ReturnCode != 0 {
|
||||
t.Fatalf("UCIWirelessInterface.Create() failed !")
|
||||
|
@ -51,16 +63,16 @@ func TestUpdate(t *testing.T) {
|
|||
uci := NewUCIWithExecutor(exec)
|
||||
|
||||
iface := NewUCIWirelessInterface()
|
||||
iface.Name = "Test"
|
||||
iface.Name = ifaceName
|
||||
iface.Index = 1
|
||||
iface.Device = "radioX"
|
||||
iface.SysDevName = "wlanX"
|
||||
iface.Mode = "ap"
|
||||
iface.Ssid = "PyxisWifi"
|
||||
iface.Bssid = "00:00:00:00:00"
|
||||
iface.Network = "Pyxis"
|
||||
iface.Encryption = "psk"
|
||||
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
|
||||
iface.Device = ifaceDevice
|
||||
iface.SysDevName = ifaceSysDevName
|
||||
iface.Mode = ifaceMode
|
||||
iface.Ssid = ifaceSSID
|
||||
iface.Bssid = ifaceBssid
|
||||
iface.Network = ifaceNetwork
|
||||
iface.Encryption = ifaceEnc
|
||||
iface.Key = ifaceKey
|
||||
|
||||
if iface.Create(uci).ReturnCode != 0 {
|
||||
t.Fatalf("UCIWirelessInterface.Create() failed !")
|
||||
|
@ -78,16 +90,16 @@ func TestDelete(t *testing.T) {
|
|||
uci := NewUCIWithExecutor(exec)
|
||||
|
||||
iface := NewUCIWirelessInterface()
|
||||
iface.Name = "Test"
|
||||
iface.Name = ifaceName
|
||||
iface.Index = 1
|
||||
iface.Device = "radioX"
|
||||
iface.SysDevName = "wlanX"
|
||||
iface.Mode = "ap"
|
||||
iface.Ssid = "PyxisWifi"
|
||||
iface.Bssid = "00:00:00:00:00"
|
||||
iface.Network = "Pyxis"
|
||||
iface.Encryption = "psk"
|
||||
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
|
||||
iface.Device = ifaceDevice
|
||||
iface.SysDevName = ifaceSysDevName
|
||||
iface.Mode = ifaceMode
|
||||
iface.Ssid = ifaceSSID
|
||||
iface.Bssid = ifaceBssid
|
||||
iface.Network = ifaceNetwork
|
||||
iface.Encryption = ifaceEnc
|
||||
iface.Key = ifaceKey
|
||||
|
||||
if iface.Delete(uci).ReturnCode != 0 {
|
||||
t.Fatalf("UCIWirelessInterface.Delete() failed !")
|
||||
|
@ -100,16 +112,16 @@ func TestConnect(t *testing.T) {
|
|||
uci := NewUCIWithExecutor(exec)
|
||||
|
||||
iface := NewUCIWirelessInterface()
|
||||
iface.Name = "Test"
|
||||
iface.Name = ifaceName
|
||||
iface.Index = 1
|
||||
iface.Device = "radioX"
|
||||
iface.SysDevName = "wlanX"
|
||||
iface.Mode = "ap"
|
||||
iface.Ssid = "PyxisWifi"
|
||||
iface.Bssid = "00:00:00:00:00"
|
||||
iface.Network = "Pyxis"
|
||||
iface.Encryption = "psk"
|
||||
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
|
||||
iface.Device = ifaceDevice
|
||||
iface.SysDevName = ifaceSysDevName
|
||||
iface.Mode = ifaceMode
|
||||
iface.Ssid = ifaceSSID
|
||||
iface.Bssid = ifaceBssid
|
||||
iface.Network = ifaceNetwork
|
||||
iface.Encryption = ifaceEnc
|
||||
iface.Key = ifaceKey
|
||||
|
||||
wifiCell := NewWifiCell("PyxisWifi", "01:01:01:01:01", "psk")
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ func (w *WifiScanner) parseWifiCells(stdout string) int {
|
|||
enc = NONE
|
||||
cell := NewWifiCell(ssid, mac, enc)
|
||||
w.Cells = append(w.Cells, cell)
|
||||
ssid, mac, enc = "", "", ""
|
||||
ssid, enc = "", ""
|
||||
}
|
||||
macRegexp := regexp.MustCompile(macExpr)
|
||||
mac = macRegexp.FindString(line)
|
||||
|
|
Reference in New Issue