Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
I have added AddAndActivateConnection to NetworkManager (#8)
Browse files Browse the repository at this point in the history
Add `AddAndActivateConnection` method to NetworkManager.

This adds a network profile, and activates the connection in one operation.
  • Loading branch information
phommel authored and tom5760 committed May 13, 2019
1 parent c04bde1 commit 9224fc9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
29 changes: 29 additions & 0 deletions NetworkManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (

NetworkManagerGetDevices = NetworkManagerInterface + ".GetDevices"
NetworkManagerActivateConnection = NetworkManagerInterface + ".ActivateConnection"
NetworkManagerAddAndActivateConnection = NetworkManagerInterface + ".AddAndActivateConnection"
NetworkManagerPropertyState = NetworkManagerInterface + ".State"
NetworkManagerPropertyActiveConnection = NetworkManagerInterface + ".ActiveConnections"
)
Expand All @@ -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()

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9224fc9

Please sign in to comment.