forked from BellerophonMobile/gonetworkmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AccessPoint.go
122 lines (94 loc) · 3.41 KB
/
AccessPoint.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus"
)
const (
AccessPointInterface = NetworkManagerInterface + ".AccessPoint"
AccessPointPropertyFlags = AccessPointInterface + ".Flags"
AccessPointPropertyWPAFlags = AccessPointInterface + ".WpaFlags"
AccessPointPropertyRSNFlags = AccessPointInterface + ".RsnFlags"
AccessPointPropertySSID = AccessPointInterface + ".Ssid"
AccessPointPropertyFrequency = AccessPointInterface + ".Frequency"
AccessPointPropertyHWAddress = AccessPointInterface + ".HwAddress"
AccessPointPropertyMode = AccessPointInterface + ".Mode"
AccessPointPropertyMaxBitrate = AccessPointInterface + ".MaxBitrate"
AccessPointPropertyStrength = AccessPointInterface + ".Strength"
)
type AccessPoint interface {
GetPath() dbus.ObjectPath
// GetFlags gets flags describing the capabilities of the access point.
GetFlags() uint32
// GetWPAFlags gets flags describing the access point's capabilities
// according to WPA (Wifi Protected Access).
GetWPAFlags() uint32
// GetRSNFlags gets flags describing the access point's capabilities
// according to the RSN (Robust Secure Network) protocol.
GetRSNFlags() uint32
// GetSSID returns the Service Set Identifier identifying the access point.
GetSSID() string
// GetFrequency gets the radio channel frequency in use by the access point,
// in MHz.
GetFrequency() uint32
// GetHWAddress gets the hardware address (BSSID) of the access point.
GetHWAddress() string
// GetMode describes the operating mode of the access point.
GetMode() Nm80211Mode
// GetMaxBitrate gets the maximum bitrate this access point is capable of, in
// kilobits/second (Kb/s).
GetMaxBitrate() uint32
// GetStrength gets the current signal quality of the access point, in
// percent.
GetStrength() uint8
MarshalJSON() ([]byte, error)
}
func NewAccessPoint(objectPath dbus.ObjectPath) (AccessPoint, error) {
var a accessPoint
return &a, a.init(NetworkManagerInterface, objectPath)
}
type accessPoint struct {
dbusBase
}
func (a *accessPoint) GetPath() dbus.ObjectPath {
return a.obj.Path()
}
func (a *accessPoint) GetFlags() uint32 {
return a.getUint32Property(AccessPointPropertyFlags)
}
func (a *accessPoint) GetWPAFlags() uint32 {
return a.getUint32Property(AccessPointPropertyWPAFlags)
}
func (a *accessPoint) GetRSNFlags() uint32 {
return a.getUint32Property(AccessPointPropertyRSNFlags)
}
func (a *accessPoint) GetSSID() string {
return string(a.getSliceByteProperty(AccessPointPropertySSID))
}
func (a *accessPoint) GetFrequency() uint32 {
return a.getUint32Property(AccessPointPropertyFrequency)
}
func (a *accessPoint) GetHWAddress() string {
return a.getStringProperty(AccessPointPropertyHWAddress)
}
func (a *accessPoint) GetMode() Nm80211Mode {
return Nm80211Mode(a.getUint32Property(AccessPointPropertyMode))
}
func (a *accessPoint) GetMaxBitrate() uint32 {
return a.getUint32Property(AccessPointPropertyMaxBitrate)
}
func (a *accessPoint) GetStrength() uint8 {
return a.getUint8Property(AccessPointPropertyStrength)
}
func (a *accessPoint) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"Flags": a.GetFlags(),
"WPAFlags": a.GetWPAFlags(),
"RSNFlags": a.GetRSNFlags(),
"SSID": a.GetSSID(),
"Frequency": a.GetFrequency(),
"HWAddress": a.GetHWAddress(),
"Mode": a.GetMode().String(),
"MaxBitrate": a.GetMaxBitrate(),
"Strength": a.GetStrength(),
})
}