From 31075ab2ef57c87fe351281ca3e016d565f2fa05 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Thu, 23 Sep 2021 15:57:24 -0700 Subject: [PATCH] test: choose default device in force-roam This makes the usage much more convenient if the system has only a single device. --- test/force-roam | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/test/force-roam b/test/force-roam index b45ad2e6..a6df854a 100755 --- a/test/force-roam +++ b/test/force-roam @@ -3,14 +3,33 @@ import sys import dbus -if (len(sys.argv) != 3): - print("Usage: %s " % (sys.argv[0])) +if len(sys.argv) < 2 or len(sys.argv) > 3: + print("Usage: %s [device] " % (sys.argv[0])) sys.exit(1) bus = dbus.SystemBus() -device = dbus.Interface(bus.get_object("net.connman.iwd", sys.argv[1]), +device = None + +if len(sys.argv) == 2: + manager = dbus.Interface(bus.get_object("net.connman.iwd", "/"), + "org.freedesktop.DBus.ObjectManager") + objects = manager.GetManagedObjects() + for path in objects: + for interface in objects[path]: + if interface == "net.connman.iwd.StationDebug": + device = dbus.Interface(bus.get_object("net.connman.iwd", path), "net.connman.iwd.StationDebug") + break -mac = sys.argv[2].replace(':', '') + if not device: + print("StationDebug interface not found") + exit() + mac = sys.argv[1] +else: + device = dbus.Interface(bus.get_object("net.connman.iwd", sys.argv[1]), + "net.connman.iwd.StationDebug") + mac = sys.argv[2] + +mac = mac.replace(':', '') device.Roam(dbus.ByteArray.fromhex(mac))