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

package openwrt
import "time"
// WifiCell reprensents wifi network Cell
type WifiCell struct {
Ssid string
MacAdress string
Encryption string
}
// NewWifiCell returns a new WifiCell object
func NewWifiCell(ssid string, mac string, encrypt string) *WifiCell {
return &WifiCell{
Ssid: ssid,
MacAdress: mac,
Encryption: encrypt,
}
}
// 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
}
setRes = uci.Set("wireless.@wifi-iface[1].ssid", cell.Ssid)
if setRes.ReturnCode != 0 {
return setRes
}
setRes = uci.Set("wireless.@wifi-iface[1].encryption", cell.Encryption)
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,
},
}
}