forked from Wifx/gonetworkmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AccessPoint.go
183 lines (152 loc) · 5.2 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus/v5"
)
const (
AccessPointInterface = NetworkManagerInterface + ".AccessPoint"
/* Properties */
AccessPointPropertyFlags = AccessPointInterface + ".Flags" // readable u
AccessPointPropertyWpaFlags = AccessPointInterface + ".WpaFlags" // readable u
AccessPointPropertyRsnFlags = AccessPointInterface + ".RsnFlags" // readable u
AccessPointPropertySsid = AccessPointInterface + ".Ssid" // readable ay
AccessPointPropertyFrequency = AccessPointInterface + ".Frequency" // readable u
AccessPointPropertyHwAddress = AccessPointInterface + ".HwAddress" // readable s
AccessPointPropertyMode = AccessPointInterface + ".Mode" // readable u
AccessPointPropertyMaxBitrate = AccessPointInterface + ".MaxBitrate" // readable u
AccessPointPropertyStrength = AccessPointInterface + ".Strength" // readable y
AccessPointPropertyLastSeen = AccessPointInterface + ".LastSeen" // readable i
)
type AccessPoint interface {
GetPath() dbus.ObjectPath
// GetFlags gets flags describing the capabilities of the access point.
GetPropertyFlags() (uint32, error)
// GetWPAFlags gets flags describing the access point's capabilities
// according to WPA (Wifi Protected Access).
GetPropertyWPAFlags() (uint32, error)
// GetRSNFlags gets flags describing the access point's capabilities
// according to the RSN (Robust Secure Network) protocol.
GetPropertyRSNFlags() (uint32, error)
// GetSSID returns the Service Set Identifier identifying the access point.
GetPropertySSID() (string, error)
// GetFrequency gets the radio channel frequency in use by the access point,
// in MHz.
GetPropertyFrequency() (uint32, error)
// GetHWAddress gets the hardware address (BSSID) of the access point.
GetPropertyHWAddress() (string, error)
// GetMode describes the operating mode of the access point.
GetPropertyMode() (Nm80211Mode, error)
// GetMaxBitrate gets the maximum bitrate this access point is capable of, in
// kilobits/second (Kb/s).
GetPropertyMaxBitrate() (uint32, error)
// GetStrength gets the current signal quality of the access point, in
// percent.
GetPropertyStrength() (uint8, error)
// GetPropertyLastSeen
// The timestamp (in CLOCK_BOOTTIME seconds) for the last time the access point was found in scan results.
// A value of -1 means the access point has never been found in scan results.
GetPropertyLastSeen() (int32, error)
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) GetPropertyFlags() (uint32, error) {
return a.getUint32Property(AccessPointPropertyFlags)
}
func (a *accessPoint) GetPropertyWPAFlags() (uint32, error) {
return a.getUint32Property(AccessPointPropertyWpaFlags)
}
func (a *accessPoint) GetPropertyRSNFlags() (uint32, error) {
return a.getUint32Property(AccessPointPropertyRsnFlags)
}
func (a *accessPoint) GetPropertySSID() (string, error) {
r, err := a.getSliceByteProperty(AccessPointPropertySsid)
if err != nil {
return "", err
}
return string(r), nil
}
func (a *accessPoint) GetPropertyFrequency() (uint32, error) {
return a.getUint32Property(AccessPointPropertyFrequency)
}
func (a *accessPoint) GetPropertyHWAddress() (string, error) {
return a.getStringProperty(AccessPointPropertyHwAddress)
}
func (a *accessPoint) GetPropertyMode() (Nm80211Mode, error) {
r, err := a.getUint32Property(AccessPointPropertyMode)
if err != nil {
return Nm80211ModeUnknown, err
}
return Nm80211Mode(r), nil
}
func (a *accessPoint) GetPropertyMaxBitrate() (uint32, error) {
return a.getUint32Property(AccessPointPropertyMaxBitrate)
}
func (a *accessPoint) GetPropertyStrength() (uint8, error) {
return a.getUint8Property(AccessPointPropertyStrength)
}
func (a *accessPoint) GetPropertyLastSeen() (int32, error) {
return a.getInt32Property(AccessPointPropertyLastSeen)
}
func (a *accessPoint) MarshalJSON() ([]byte, error) {
Flags, err := a.GetPropertyFlags()
if err != nil {
return nil, err
}
WPAFlags, err := a.GetPropertyWPAFlags()
if err != nil {
return nil, err
}
RSNFlags, err := a.GetPropertyRSNFlags()
if err != nil {
return nil, err
}
SSID, err := a.GetPropertySSID()
if err != nil {
return nil, err
}
Frequency, err := a.GetPropertyFrequency()
if err != nil {
return nil, err
}
HWAddress, err := a.GetPropertyHWAddress()
if err != nil {
return nil, err
}
Mode, err := a.GetPropertyMode()
if err != nil {
return nil, err
}
MaxBitrate, err := a.GetPropertyMaxBitrate()
if err != nil {
return nil, err
}
Strength, err := a.GetPropertyStrength()
if err != nil {
return nil, err
}
LastSeen, err := a.GetPropertyLastSeen()
if err != nil {
return nil, err
}
return json.Marshal(map[string]interface{}{
"Flags": Flags,
"WPAFlags": WPAFlags,
"RSNFlags": RSNFlags,
"SSID": SSID,
"Frequency": Frequency,
"HWAddress": HWAddress,
"Mode": Mode.String(),
"MaxBitrate": MaxBitrate,
"Strength": Strength,
"LastSeen": LastSeen,
})
}