From 5912ec72023342e9e9801b4b4db28c44625b59d2 Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Mon, 29 Oct 2018 15:10:32 +0100 Subject: [PATCH] Fixing wireless configuration creation --- uci.go | 5 ++--- uci_wireless_conf.go | 13 +++---------- uci_wireless_interface.go | 7 ++----- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/uci.go b/uci.go index b2ff144..f85d0d7 100644 --- a/uci.go +++ b/uci.go @@ -65,7 +65,7 @@ func (u *UCI) Commit() *Action { func (u *UCI) Reload() *Action { cmdResult := u.exec.Run("reload_config") - time.Sleep(5 * time.Second) + time.Sleep(1 * time.Second) return &Action{cmdResult, "reload_config"} } @@ -124,7 +124,6 @@ func (u *UCI) GetWifiIfaceByName(name string) *UCIWirelessInterface { // 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") @@ -140,7 +139,7 @@ func (u *UCI) GetWifiIfaceBySSID(ssid string) *UCIWirelessInterface { } // GetWifiIfaces wifi interfaces in configuration -func (u *UCI) GetWifiIfaces() []*UCIWirelessInterface { +func (u *UCI) GetWifiIfaces() map[int]*UCIWirelessInterface { return u.Wireless.Interfaces } diff --git a/uci_wireless_conf.go b/uci_wireless_conf.go index 8dd043c..4eff24d 100644 --- a/uci_wireless_conf.go +++ b/uci_wireless_conf.go @@ -12,7 +12,7 @@ type UCIWirelessConf struct { uciClient *UCI Devices []map[string]string DefaultInterface map[string]string - Interfaces []*UCIWirelessInterface + Interfaces map[int]*UCIWirelessInterface } // NewUCIWirelessConf builds a new UCIWirelessConf instance @@ -21,7 +21,7 @@ func NewUCIWirelessConf(uci *UCI) *UCIWirelessConf { uciClient: uci, Devices: []map[string]string{}, //, 10), DefaultInterface: map[string]string{}, - Interfaces: []*UCIWirelessInterface{}, //, 10), + Interfaces: map[int]*UCIWirelessInterface{}, } } @@ -65,13 +65,7 @@ func (wc *UCIWirelessConf) parseInterfaces(lines []string) int { idx = int(s) } - if idx >= len(wc.Interfaces) { - for i := 0; i <= idx; i++ { - wc.Interfaces = append(wc.Interfaces, NewUCIWirelessInterface()) - } - } - - if wc.Interfaces[idx] == nil { + if _, exists := wc.Interfaces[idx]; !exists { wc.Interfaces[idx] = NewUCIWirelessInterface() wc.Interfaces[idx].Index = idx } @@ -94,7 +88,6 @@ 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" { diff --git a/uci_wireless_interface.go b/uci_wireless_interface.go index 244f052..c4289ff 100644 --- a/uci_wireless_interface.go +++ b/uci_wireless_interface.go @@ -70,11 +70,8 @@ func (wi *UCIWirelessInterface) Create(uci *UCI) *Action { if addRes.ReturnCode != 0 { return addRes } - if wi.Index <= 0 { - confPrefix = fmt.Sprintf("wireless.@wifi-iface[%d]", len(uci.Wireless.Interfaces)) - } else { - confPrefix = fmt.Sprintf("wireless.@wifi-iface[%d]", wi.Index) - } + confPrefix = fmt.Sprintf("wireless.@wifi-iface[%d]", wi.Index) + conf := make(map[string][]string) conf["network"] = append(conf["network"], fmt.Sprintf("%s.network", confPrefix), wi.Network)