diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3a8bd00..32595f1 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -23,4 +23,4 @@ jobs: uses: actions/checkout@v2 - name: Build - run: go build -v examples/devices.go + run: go build -v examples/devices/devices.go diff --git a/AccessPoint.go b/AccessPoint.go index bad167e..849009b 100644 --- a/AccessPoint.go +++ b/AccessPoint.go @@ -57,6 +57,11 @@ type AccessPoint interface { // 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) } @@ -117,6 +122,10 @@ 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 { @@ -154,6 +163,10 @@ func (a *accessPoint) MarshalJSON() ([]byte, error) { if err != nil { return nil, err } + LastSeen, err := a.GetPropertyLastSeen() + if err != nil { + return nil, err + } return json.Marshal(map[string]interface{}{ "Flags": Flags, @@ -165,5 +178,6 @@ func (a *accessPoint) MarshalJSON() ([]byte, error) { "Mode": Mode.String(), "MaxBitrate": MaxBitrate, "Strength": Strength, + "LastSeen": LastSeen, }) } diff --git a/ActiveConnection.go b/ActiveConnection.go index 3f6e3dc..b06cc9b 100644 --- a/ActiveConnection.go +++ b/ActiveConnection.go @@ -2,6 +2,7 @@ package gonetworkmanager import ( "fmt" + "github.com/godbus/dbus/v5" ) @@ -220,6 +221,7 @@ func (a *activeConnection) GetPropertyMaster() (Device, error) { } type StateChange struct { + Path dbus.ObjectPath State NmActiveConnectionState Reason NmActiveConnectionStateReason } @@ -243,17 +245,17 @@ func (a *activeConnection) SubscribeState(receiver chan StateChange, exit chan s for { select { case signal, ok := <-channel: - if !ok { err = fmt.Errorf("connection closed for %s", ActiveConnectionSignalStateChanged) return } - if signal.Path != a.GetPath() || signal.Name != ActiveConnectionInterface+"."+ActiveConnectionSignalStateChanged { + if signal.Name != ActiveConnectionInterface+"."+ActiveConnectionSignalStateChanged { continue } stateChange := StateChange{ + Path: signal.Path, State: NmActiveConnectionState(signal.Body[0].(uint32)), Reason: NmActiveConnectionStateReason(signal.Body[1].(uint32)), } diff --git a/DeviceWireless.go b/DeviceWireless.go index 187406d..3d3e405 100644 --- a/DeviceWireless.go +++ b/DeviceWireless.go @@ -186,7 +186,6 @@ func (d *deviceWireless) MarshalJSON() ([]byte, error) { m["PermHwAddress"], _ = d.GetPropertyPermHwAddress() m["Mode"], _ = d.GetPropertyMode() m["Bitrate"], _ = d.GetPropertyBitrate() - m["AccessPoints"], _ = d.GetPropertyAccessPoints() m["ActiveAccessPoint"], _ = d.GetPropertyActiveAccessPoint() m["WirelessCapabilities"], _ = d.GetPropertyWirelessCapabilities() m["LastScan"], _ = d.GetPropertyLastScan() diff --git a/NetworkManager.go b/NetworkManager.go index 190004c..053c1a3 100644 --- a/NetworkManager.go +++ b/NetworkManager.go @@ -172,7 +172,7 @@ type NetworkManager interface { GetPropertyActiveConnections() ([]ActiveConnection, error) // The object path of the "primary" active connection being used to access the network. In particular, if there is no VPN active, or the VPN does not have the default route, then this indicates the connection that has the default route. If there is a VPN active with the default route, then this indicates the connection that contains the route to the VPN endpoint. - GetPropertyPrimaryConnection() (Connection, error) + GetPropertyPrimaryConnection() (ActiveConnection, error) // The connection type of the "primary" active connection being used to access the network. This is the same as the Type property on the object indicated by PrimaryConnection. GetPropertyPrimaryConnectionType() (string, error) @@ -543,14 +543,14 @@ func (nm *networkManager) GetPropertyActiveConnections() ([]ActiveConnection, er return ac, nil } -func (nm *networkManager) GetPropertyPrimaryConnection() (Connection, error) { - connectionPath, err := nm.getObjectProperty(NetworkManagerPropertyPrimaryConnection) +func (nm *networkManager) GetPropertyPrimaryConnection() (ActiveConnection, error) { + activeConnectionPath, err := nm.getObjectProperty(NetworkManagerPropertyPrimaryConnection) if err != nil { return nil, err } - return NewConnection(connectionPath) + return NewActiveConnection(activeConnectionPath) } func (nm *networkManager) GetPropertyPrimaryConnectionType() (string, error) { diff --git a/examples/devices.go b/examples/devices/devices.go similarity index 100% rename from examples/devices.go rename to examples/devices/devices.go diff --git a/examples/static_connect.go b/examples/static_connect/static_connect.go similarity index 100% rename from examples/static_connect.go rename to examples/static_connect/static_connect.go diff --git a/utils.go b/utils.go index 1a2d3dc..4e1f01b 100644 --- a/utils.go +++ b/utils.go @@ -58,7 +58,7 @@ func (d *dbusBase) getProperty(iface string) (interface{}, error) { return variant.Value(), err } -func (d *dbusBase) setProperty(iface string, value interface{}) (error) { +func (d *dbusBase) setProperty(iface string, value interface{}) error { err := d.obj.SetProperty(iface, dbus.MakeVariant(value)) return err } @@ -180,6 +180,19 @@ func (d *dbusBase) getUint32Property(iface string) (value uint32, err error) { return } +func (d *dbusBase) getInt32Property(iface string) (value int32, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.(int32) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + func (d *dbusBase) getInt64Property(iface string) (value int64, err error) { prop, err := d.getProperty(iface) if err != nil {