This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
orion/openwrt/wifi_cell.go

78 lines
1.6 KiB
Go
Raw Normal View History

package openwrt
2018-09-20 10:59:11 +02:00
import "time"
// WifiCell reprensents wifi network Cell
type WifiCell struct {
2018-09-20 10:59:11 +02:00
Ssid string
MacAdress string
Encryption string
}
// NewWifiCell returns a new WifiCell object
2018-09-20 10:59:11 +02:00
func NewWifiCell(ssid string, mac string, encrypt string) *WifiCell {
return &WifiCell{
2018-09-20 10:59:11 +02:00
Ssid: ssid,
MacAdress: mac,
Encryption: encrypt,
}
}
2018-09-20 10:59:11 +02:00
// Connect to wifi Cell
func (cell *WifiCell) Connect(uci *UCI, secret string) *Action {
delRes := uci.Delete("wireless.@wifi-iface[1]")
if delRes.ReturnCode != 0 {
return delRes
}
addRes := uci.AddWireless("wifi-iface")
if addRes.ReturnCode != 0 {
return addRes
}
setRes := uci.Set("wireless.@wifi-iface[1].network", "PyxisNetwork")
if setRes.ReturnCode != 0 {
return setRes
}
2018-09-20 10:59:11 +02:00
setRes = uci.Set("wireless.@wifi-iface[1].ssid", cell.Ssid)
if setRes.ReturnCode != 0 {
return setRes
}
2018-09-20 17:09:11 +02:00
setRes = uci.Set("wireless.@wifi-iface[1].encryption", cell.Encryption)
2018-09-20 10:59:11 +02:00
if setRes.ReturnCode != 0 {
return setRes
}
setRes = uci.Set("wireless.@wifi-iface[1].device", "radio1")
if setRes.ReturnCode != 0 {
return setRes
}
setRes = uci.Set("wireless.@wifi-iface[1].mode", "sta")
if setRes.ReturnCode != 0 {
return setRes
}
setRes = uci.Set("wireless.@wifi-iface[1].bssid", cell.MacAdress)
if setRes.ReturnCode != 0 {
return setRes
}
setRes = uci.Set("wireless.@wifi-iface[1].key", secret)
if setRes.ReturnCode != 0 {
return setRes
}
setRes = uci.Commit()
if setRes.ReturnCode != 0 {
return setRes
}
setRes = uci.Reload()
if setRes.ReturnCode != 0 {
return setRes
}
time.Sleep(20)
return &Action{
&CommandResult{
Stdout: "",
Stderr: "",
ReturnCode: 0,
},
}
}