This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
WirelessDevice.go
72 lines (57 loc) · 1.61 KB
/
WirelessDevice.go
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
72
package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus"
)
const (
WirelessDeviceInterface = DeviceInterface + ".Wireless"
WirelessDeviceGetAccessPoints = WirelessDeviceInterface + ".GetAccessPoints"
WirelessDeviceRequestScan = WirelessDeviceInterface + ".RequestScan"
)
type WirelessDevice interface {
Device
// GetAccessPoints gets the list of access points visible to this device.
// Note that this list does not include access points which hide their SSID.
// To retrieve a list of all access points (including hidden ones) use the
// GetAllAccessPoints() method.
GetAccessPoints() ([]AccessPoint, error)
RequestScan() error
}
func NewWirelessDevice(objectPath dbus.ObjectPath) (WirelessDevice, error) {
var d wirelessDevice
return &d, d.init(NetworkManagerInterface, objectPath)
}
type wirelessDevice struct {
device
}
func (d *wirelessDevice) GetAccessPoints() ([]AccessPoint, error) {
var apPaths []dbus.ObjectPath
err := d.call(&apPaths, WirelessDeviceGetAccessPoints)
if err != nil {
return nil, err
}
aps := make([]AccessPoint, len(apPaths))
for i, path := range apPaths {
aps[i], err = NewAccessPoint(path)
if err != nil {
return nil, err
}
}
return aps, nil
}
func (d *wirelessDevice) RequestScan() error {
var options map[string]interface{}
return d.obj.Call(WirelessDeviceRequestScan, 0, options).Store()
}
func (d *wirelessDevice) MarshalJSON() ([]byte, error) {
m, err := d.device.marshalMap()
if err != nil {
return nil, err
}
aps, err := d.GetAccessPoints()
if err != nil {
return nil, err
}
m["AccessPoints"] = aps
return json.Marshal(m)
}