Merge branch 'master' into DeviceActiveConnection

This commit is contained in:
Christian Müller 2019-09-11 11:57:34 +02:00
commit 2ee5cfeefc
3 changed files with 158 additions and 8 deletions

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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.
@ -345,7 +345,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())
}