From 9224fc9401a70f9012eae7002d2fca7ecf6f230a Mon Sep 17 00:00:00 2001 From: Peter Hommel Date: Mon, 13 May 2019 15:51:12 +0200 Subject: [PATCH] I have added AddAndActivateConnection to NetworkManager (#8) Add `AddAndActivateConnection` method to NetworkManager. This adds a network profile, and activates the connection in one operation. --- NetworkManager.go | 29 +++++++++++++++++++++++++++++ utils.go | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/NetworkManager.go b/NetworkManager.go index 6457671..68843fa 100644 --- a/NetworkManager.go +++ b/NetworkManager.go @@ -12,6 +12,7 @@ const ( NetworkManagerGetDevices = NetworkManagerInterface + ".GetDevices" NetworkManagerActivateConnection = NetworkManagerInterface + ".ActivateConnection" + NetworkManagerAddAndActivateConnection = NetworkManagerInterface + ".AddAndActivateConnection" NetworkManagerPropertyState = NetworkManagerInterface + ".State" NetworkManagerPropertyActiveConnection = NetworkManagerInterface + ".ActiveConnections" ) @@ -32,6 +33,18 @@ type NetworkManager interface { // ActivateWirelessConnection requests activating access point to network device ActivateWirelessConnection(connection Connection, device Device, accessPoint AccessPoint) ActiveConnection + // AddAndActivateWirelessConnection adds a new connection profile to the network device it has been + // passed. It then activates the connection to the passed access point. The first paramter contains + // additional information for the connection (most propably the credentials). + // Example contents for connection are: + // connection := make(map[string]map[string]interface{}) + // connection["802-11-wireless"] = make(map[string]interface{}) + // connection["802-11-wireless"]["security"] = "802-11-wireless-security" + // connection["802-11-wireless-security"] = make(map[string]interface{}) + // connection["802-11-wireless-security"]["key-mgmt"] = "wpa-psk" + // connection["802-11-wireless-security"]["psk"] = password + AddAndActivateWirelessConnection(connection map[string]map[string]interface{}, device Device, accessPoint AccessPoint) (ac ActiveConnection, err error) + Subscribe() <-chan *dbus.Signal Unsubscribe() @@ -91,6 +104,22 @@ func (n *networkManager) ActivateWirelessConnection(c Connection, d Device, ap A return nil } +func (n *networkManager) AddAndActivateWirelessConnection(connection map[string]map[string]interface{}, d Device, ap AccessPoint) (ac ActiveConnection, err error) { + var opath1 dbus.ObjectPath + var opath2 dbus.ObjectPath + + err = n.callError2(&opath1, &opath2, NetworkManagerAddAndActivateConnection, connection, d.GetPath(), ap.GetPath()) + if err != nil { + return + } + + ac, err = NewActiveConnection(opath2) + if err != nil { + return + } + return +} + func (n *networkManager) Subscribe() <-chan *dbus.Signal { if n.sigChan != nil { return n.sigChan diff --git a/utils.go b/utils.go index 785a86a..b6f73da 100644 --- a/utils.go +++ b/utils.go @@ -41,6 +41,10 @@ func (d *dbusBase) callError(value interface{}, method string, args ...interface return d.obj.Call(method, 0, args...).Store(value) } +func (d *dbusBase) callError2(value1 interface{}, value2 interface{}, method string, args ...interface{}) error { + return d.obj.Call(method, 0, args...).Store(value1, value2) +} + func (d *dbusBase) subscribe(iface, member string) { rule := fmt.Sprintf("type='signal',interface='%s',path='%s',member='%s'", iface, d.obj.Path(), NetworkManagerInterface)