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 { func (u *UCI) Reload() *Action {
cmdResult := u.exec.Run("reload_config") cmdResult := u.exec.Run("reload_config")
time.Sleep(5 * time.Second) time.Sleep(1 * time.Second)
return &Action{cmdResult, "reload_config"} return &Action{cmdResult, "reload_config"}
} }
@ -124,7 +124,6 @@ func (u *UCI) GetWifiIfaceByName(name string) *UCIWirelessInterface {
// GetWifiIfaceBySSID returns the wifi Interface by Index // GetWifiIfaceBySSID returns the wifi Interface by Index
func (u *UCI) GetWifiIfaceBySSID(ssid string) *UCIWirelessInterface { func (u *UCI) GetWifiIfaceBySSID(ssid string) *UCIWirelessInterface {
u.LoadWirelessConf()
ifaces := u.Wireless.Interfaces ifaces := u.Wireless.Interfaces
if len(ifaces) <= 0 { if len(ifaces) <= 0 {
fmt.Println("ifaces are empty !!! fuck") fmt.Println("ifaces are empty !!! fuck")
@ -140,7 +139,7 @@ func (u *UCI) GetWifiIfaceBySSID(ssid string) *UCIWirelessInterface {
} }
// GetWifiIfaces wifi interfaces in configuration // GetWifiIfaces wifi interfaces in configuration
func (u *UCI) GetWifiIfaces() []*UCIWirelessInterface { func (u *UCI) GetWifiIfaces() map[int]*UCIWirelessInterface {
return u.Wireless.Interfaces return u.Wireless.Interfaces
} }

View File

@ -12,7 +12,7 @@ type UCIWirelessConf struct {
uciClient *UCI uciClient *UCI
Devices []map[string]string Devices []map[string]string
DefaultInterface map[string]string DefaultInterface map[string]string
Interfaces []*UCIWirelessInterface Interfaces map[int]*UCIWirelessInterface
} }
// NewUCIWirelessConf builds a new UCIWirelessConf instance // NewUCIWirelessConf builds a new UCIWirelessConf instance
@ -21,7 +21,7 @@ func NewUCIWirelessConf(uci *UCI) *UCIWirelessConf {
uciClient: uci, uciClient: uci,
Devices: []map[string]string{}, //, 10), Devices: []map[string]string{}, //, 10),
DefaultInterface: map[string]string{}, 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) idx = int(s)
} }
if idx >= len(wc.Interfaces) { if _, exists := wc.Interfaces[idx]; !exists {
for i := 0; i <= idx; i++ {
wc.Interfaces = append(wc.Interfaces, NewUCIWirelessInterface())
}
}
if wc.Interfaces[idx] == nil {
wc.Interfaces[idx] = NewUCIWirelessInterface() wc.Interfaces[idx] = NewUCIWirelessInterface()
wc.Interfaces[idx].Index = idx wc.Interfaces[idx].Index = idx
} }
@ -94,7 +88,6 @@ func (wc *UCIWirelessConf) parseInterfaces(lines []string) int {
wc.Interfaces[idx].Mode = value wc.Interfaces[idx].Mode = value
} }
if key == "Ssid" { if key == "Ssid" {
fmt.Printf("Fixing SSID FOR %s\n", value)
wc.Interfaces[idx].Ssid = value wc.Interfaces[idx].Ssid = value
} }
if key == "Encryption" { if key == "Encryption" {

View File

@ -70,11 +70,8 @@ func (wi *UCIWirelessInterface) Create(uci *UCI) *Action {
if addRes.ReturnCode != 0 { if addRes.ReturnCode != 0 {
return addRes 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 := make(map[string][]string)
conf["network"] = append(conf["network"], fmt.Sprintf("%s.network", confPrefix), wi.Network) conf["network"] = append(conf["network"], fmt.Sprintf("%s.network", confPrefix), wi.Network)