forked from shibumi/iwd
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstation.go
More file actions
71 lines (62 loc) · 1.7 KB
/
station.go
File metadata and controls
71 lines (62 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package iwd
import (
"github.com/godbus/dbus/v5"
)
const (
objectStation = "net.connman.iwd.Station"
callStationScan = "net.connman.iwd.Station.Scan"
callStationGetOrderedNetworks = "net.connman.iwd.Station.GetOrderedNetworks"
callStationDisconnect = "net.connman.iwd.Station.Disconnect"
)
// Station refers to net.connman.iwd.Station
type Station struct {
iwd *Iwd
Path dbus.ObjectPath
ConnectedNetwork *dbus.ObjectPath
Scanning bool
State string
}
type OrderedNetwork struct {
Network
SignalStrength int16
}
// Scan scans for wireless networks
func (s *Station) Scan(conn *dbus.Conn) error {
obj := conn.Object(objectIwd, s.Path)
call := obj.Call(callStationScan, 0)
if call.Err != nil {
return call.Err
}
return nil
}
func (s *Station) GetOrderedNetworks(conn *dbus.Conn) ([]*OrderedNetwork, error) {
obj := conn.Object(objectIwd, s.Path)
var objects [][]dbus.Variant
err := obj.Call(callStationGetOrderedNetworks, 0).Store(&objects)
if err != nil {
return nil, err
}
orderedNetworks := make([]*OrderedNetwork, 0, len(objects))
for _, obj := range objects {
networkObject := obj[0].Value().(dbus.ObjectPath)
signalStrength := obj[1].Value().(int16)
for _, network := range s.iwd.Networks {
if network.Path == networkObject {
orderedNetworks = append(orderedNetworks, &OrderedNetwork{
Network: network,
SignalStrength: signalStrength,
})
break
}
}
}
return orderedNetworks, nil
}
func (s *Station) Disconnect(conn *dbus.Conn) error {
obj := conn.Object(objectIwd, s.Path)
call := obj.Call(callStationDisconnect, 0)
if call.Err != nil {
return call.Err
}
return nil
}