Fixing wireless configuration creation

This commit is contained in:
Philippe Caseiro 2018-10-29 15:10:32 +01:00
parent 077ec7bd7a
commit 5912ec7202
3 changed files with 7 additions and 18 deletions

5
uci.go
View File

@ -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
}

View File

@ -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" {

View File

@ -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)