Last active
May 16, 2019 00:29
-
-
Save gdamjan/fba15c54c9b4dd4ffc32ffc0f38e8e1f to your computer and use it in GitHub Desktop.
configure a wifi interface to 4add/wds mode via iwd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from gi.repository import GLib | |
import dbus | |
import dbus.mainloop.glib | |
import sys | |
if len(sys.argv) != 2: | |
print('Usage: {} <mac-address>'.format(sys.argv[0])) | |
sys.exit(1) | |
interface_address = sys.argv[1] | |
def interfaces_added_cb(object_path, interfaces): | |
device_properties = interfaces.get("net.connman.iwd.Device") | |
if device_properties is None: | |
# not a device | |
return False | |
if device_properties.get('Address') != interface_address: | |
# not the device | |
return False | |
if device_properties.get('WDS') == 1: | |
print('wds already enabled on interface: {}'.format(name)) | |
mainloop.quit() | |
return True | |
name = device_properties.get('Name', 'n/a') | |
device = dbus.Interface(bus.get_object("net.connman.iwd", object_path), | |
"org.freedesktop.DBus.Properties") | |
device.Set("net.connman.iwd.Device", "WDS", dbus.Boolean(True)) | |
print('enabled wds on interface: {}'.format(name)) | |
mainloop.quit() | |
return True | |
if __name__ == '__main__': | |
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) | |
mainloop = GLib.MainLoop() | |
bus = dbus.SystemBus() | |
# add a signal handler to configure interfaces to appear later | |
bus.add_signal_receiver(interfaces_added_cb, bus_name="net.connman.iwd", | |
dbus_interface="org.freedesktop.DBus.ObjectManager", | |
signal_name="InterfacesAdded") | |
# enumerate already present interfaces | |
manager = dbus.Interface(bus.get_object("net.connman.iwd", "/"), | |
"org.freedesktop.DBus.ObjectManager") | |
objects = manager.GetManagedObjects() | |
for path, interfaces in objects.items(): | |
if interfaces_added_cb(path, interfaces): | |
sys.exit(0) | |
mainloop.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment