From 2c7e6be27269a864ed99964a0fc1867750ac0a69 Mon Sep 17 00:00:00 2001 From: jkirkwood Date: Wed, 10 Jul 2019 15:37:19 -0400 Subject: [PATCH 1/4] Add GetSecrets method to connection --- Connection.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Connection.go b/Connection.go index 6ff802a..fc03603 100644 --- a/Connection.go +++ b/Connection.go @@ -46,6 +46,12 @@ type Connection interface { // separately using the GetSecrets() method. GetSettings() (ConnectionSettings, error) + // Get the secrets belonging to this network configuration. Only secrets from + // persistent storage or a Secret Agent running in the requestor's session + // will be returned. The user will never be prompted for secrets as a result + // of this request. + GetSecrets(settingName string) (ConnectionSettings, error) + // Clear the secrets belonging to this network connection profile. ClearSecrets() error @@ -110,6 +116,27 @@ func (c *connection) GetSettings() (ConnectionSettings, error) { return rv, nil } +func (c *connection) GetSecrets(settingName string) (ConnectionSettings, error) { + var settings map[string]map[string]dbus.Variant + err := c.callWithReturn(&settings, ConnectionGetSecrets, settingName) + + if err != nil { + return nil, err + } + + rv := make(ConnectionSettings) + + for k1, v1 := range settings { + rv[k1] = make(map[string]interface{}) + + for k2, v2 := range v1 { + rv[k1][k2] = v2.Value() + } + } + + return rv, nil +} + func (c *connection) ClearSecrets() error { return c.call(ConnectionClearSecrets) } From 337d0bb01ef7a6f7f22ce858a0448c72c5e0a5ab Mon Sep 17 00:00:00 2001 From: jkirkwood Date: Wed, 10 Jul 2019 22:57:00 -0400 Subject: [PATCH 2/4] Add more wireless device properties --- DeviceWireless.go | 135 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 129 insertions(+), 6 deletions(-) diff --git a/DeviceWireless.go b/DeviceWireless.go index 530ec74..fc424f6 100644 --- a/DeviceWireless.go +++ b/DeviceWireless.go @@ -10,8 +10,19 @@ const ( DeviceWirelessInterface = DeviceInterface + ".Wireless" // Methods - DeviceWirelessGetAccessPoints = DeviceWirelessInterface + ".GetAccessPoints" - DeviceWirelessRequestScan = DeviceWirelessInterface + ".RequestScan" + DeviceWirelessGetAccessPoints = DeviceWirelessInterface + ".GetAccessPoints" + DeviceWirelessGetAllAccessPoints = DeviceWirelessInterface + ".GetAllAccessPoints" + DeviceWirelessRequestScan = DeviceWirelessInterface + ".RequestScan" + + // Properties + DeviceWirelessPropertyHwAddress = DeviceWirelessInterface + ".HwAddress" // readable s + DeviceWirelessPropertyPermHwAddress = DeviceWirelessInterface + ".PermHwAddress" // readable s + DeviceWirelessPropertyMode = DeviceWirelessInterface + ".Mode" // readable u + DeviceWirelessPropertyBitrate = DeviceWirelessInterface + ".Bitrate" // readable u + DeviceWirelessPropertyAccessPoints = DeviceWirelessInterface + ".AccessPoints" // readable ao + DeviceWirelessPropertyActiveAccessPoint = DeviceWirelessInterface + ".ActiveAccessPoint" // readable o + DeviceWirelessPropertyWirelessCapabilities = DeviceWirelessInterface + ".WirelessCapabilities" // readable u + DeviceWirelessPropertyLastScan = DeviceWirelessInterface + ".LastScan" // readable x ) type DeviceWireless interface { @@ -23,7 +34,40 @@ type DeviceWireless interface { // GetAllAccessPoints() method. GetAccessPoints() ([]AccessPoint, error) - RequestScan() + // GetAllAccessPoints gets the list of all access points visible to this + // device, including hidden ones for which the SSID is not yet known. + GetAllAccessPoints() ([]AccessPoint, error) + + // Request the device to scan. To know when the scan is finished, use the + // "PropertiesChanged" signal from "org.freedesktop.DBus.Properties" to listen + // to changes to the "LastScan" property. + RequestScan() error + + // The active hardware address of the device. + GetPropertyHwAddress() (string, error) + + // The permanent hardware address of the device. + GetPropertyPermHwAddress() (string, error) + + // The operating mode of the wireless device. + GetPropertyMode() (Nm80211Mode, error) + + // The bit rate currently used by the wireless device, in kilobits/second (Kb/s). + GetPropertyBitrate() (uint32, error) + + // List of object paths of access point visible to this wireless device. + GetPropertyAccessPoints() ([]AccessPoint, error) + + // Object path of the access point currently used by the wireless device. + GetPropertyActiveAccessPoint() (AccessPoint, error) + + // The capabilities of the wireless device. + GetPropertyWirelessCapabilities() (uint32, error) + + // The timestamp (in CLOCK_BOOTTIME milliseconds) for the last finished + // network scan. A value of -1 means the device never scanned for access + // points. + GetPropertyLastScan() (int64, error) } func NewDeviceWireless(objectPath dbus.ObjectPath) (DeviceWireless, error) { @@ -55,13 +99,92 @@ func (d *deviceWireless) GetAccessPoints() ([]AccessPoint, error) { return aps, nil } -func (d *deviceWireless) RequestScan() { +func (d *deviceWireless) GetAllAccessPoints() ([]AccessPoint, error) { + var apPaths []dbus.ObjectPath + err := d.callWithReturn(&apPaths, DeviceWirelessGetAllAccessPoints) + + 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 aps, err + } + } + + return aps, nil +} + +func (d *deviceWireless) RequestScan() error { var options map[string]interface{} - d.obj.Call(DeviceWirelessRequestScan, 0, options).Store() + return d.obj.Call(DeviceWirelessRequestScan, 0, options).Store() +} + +func (d *deviceWireless) GetPropertyHwAddress() (string, error) { + return d.getStringProperty(DeviceWirelessPropertyHwAddress) +} + +func (d *deviceWireless) GetPropertyPermHwAddress() (string, error) { + return d.getStringProperty(DeviceWirelessPropertyPermHwAddress) +} + +func (d *deviceWireless) GetPropertyMode() (Nm80211Mode, error) { + v, err := d.getUint32Property(DeviceWirelessPropertyMode) + return Nm80211Mode(v), err +} + +func (d *deviceWireless) GetPropertyBitrate() (uint32, error) { + return d.getUint32Property(DeviceWirelessPropertyBitrate) +} + +func (d *deviceWireless) GetPropertyAccessPoints() ([]AccessPoint, error) { + apPaths, err := d.getSliceObjectProperty(DeviceWirelessPropertyAccessPoints) + if err != nil { + return nil, err + } + + ap := make([]AccessPoint, len(apPaths)) + for i, path := range apPaths { + ap[i], err = NewAccessPoint(path) + if err != nil { + return ap, err + } + } + + return ap, nil +} + +func (d *deviceWireless) GetPropertyActiveAccessPoint() (AccessPoint, error) { + path, err := d.getObjectProperty(DeviceWirelessPropertyActiveAccessPoint) + if err != nil || path == "/" { + return nil, err + } + + return NewAccessPoint(path) +} + +func (d *deviceWireless) GetPropertyWirelessCapabilities() (uint32, error) { + return d.getUint32Property(DeviceWirelessPropertyWirelessCapabilities) +} + +func (d *deviceWireless) GetPropertyLastScan() (int64, error) { + return d.getInt64Property(DeviceWirelessPropertyLastScan) } func (d *deviceWireless) MarshalJSON() ([]byte, error) { m := d.device.marshalMap() - m["AccessPoints"], _ = d.GetAccessPoints() + m["AccessPoints"], _ = d.GetPropertyAccessPoints() + m["HwAddress"], _ = d.GetPropertyHwAddress() + 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() return json.Marshal(m) } From e5941e8300ee131e6ca8eb174ebb035a68634ed6 Mon Sep 17 00:00:00 2001 From: Josef Filzmaier Date: Wed, 14 Aug 2019 18:54:51 +0200 Subject: [PATCH 3/4] Change connection parameter name The developer.gnome.org spec specifies that the function call DeactivateConnection() requires an ActiveConnection as its parameter. --- NetworkManager.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/NetworkManager.go b/NetworkManager.go index 9c5e20f..383f8af 100644 --- a/NetworkManager.go +++ b/NetworkManager.go @@ -98,7 +98,7 @@ type NetworkManager interface { AddAndActivateWirelessConnection(connection map[string]map[string]interface{}, device Device, accessPoint AccessPoint) (ActiveConnection, error) // Deactivate an active connection. - DeactivateConnection(connection Connection) error + DeactivateConnection(connection ActiveConnection) error // Control the NetworkManager daemon's sleep state. When asleep, all interfaces that it manages are deactivated. When awake, devices are available to be activated. This command should not be called directly by users or clients; it is intended for system suspend/resume tracking. // sleepnWake: Indicates whether the NetworkManager daemon should sleep or wake. @@ -203,6 +203,9 @@ type NetworkManager interface { // Indicates whether connectivity checking is enabled. This property can also be written to to disable connectivity checking (as a privacy control panel might want to do). GetPropertyConnectivityCheckEnabled() (bool, error) + // NetworkManager Settings + GetPropertySettings() (Settings, error) + // Dictionary of global DNS settings where the key is one of "searches", "options" and "domains". The values for the "searches" and "options" keys are string arrays describing the list of search domains and resolver options, respectively. The value of the "domains" key is a second-level dictionary, where each key is a domain name, and each key's value is a third-level dictionary with the keys "servers" and "options". "servers" is a string array of DNS servers, "options" is a string array of domain-specific options. //GetPropertyGlobalDnsConfiguration() []interface{} @@ -345,7 +348,7 @@ func (nm *networkManager) AddAndActivateWirelessConnection(connection map[string return } -func (nm *networkManager) DeactivateConnection(c Connection) error { +func (nm *networkManager) DeactivateConnection(c ActiveConnection) error { return nm.call(NetworkManagerDeactivateConnection, c.GetPath()) } From 6730bdafade5603f16937688137b78cc5c7d1c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCller?= Date: Thu, 29 Aug 2019 17:21:09 +0200 Subject: [PATCH 4/4] Update NetworkManager.go Fix the interface removing unimplemnted methods --- NetworkManager.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/NetworkManager.go b/NetworkManager.go index 383f8af..98b65fb 100644 --- a/NetworkManager.go +++ b/NetworkManager.go @@ -203,9 +203,6 @@ type NetworkManager interface { // Indicates whether connectivity checking is enabled. This property can also be written to to disable connectivity checking (as a privacy control panel might want to do). GetPropertyConnectivityCheckEnabled() (bool, error) - // NetworkManager Settings - GetPropertySettings() (Settings, error) - // Dictionary of global DNS settings where the key is one of "searches", "options" and "domains". The values for the "searches" and "options" keys are string arrays describing the list of search domains and resolver options, respectively. The value of the "domains" key is a second-level dictionary, where each key is a domain name, and each key's value is a third-level dictionary with the keys "servers" and "options". "servers" is a string array of DNS servers, "options" is a string array of domain-specific options. //GetPropertyGlobalDnsConfiguration() []interface{}