summaryrefslogtreecommitdiff
path: root/test/test-connman
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2009-01-21 18:54:41 +0100
committerMarcel Holtmann <marcel@holtmann.org>2009-01-21 18:54:41 +0100
commit7054e93685c8c18838cc78500566ba4277a5cb26 (patch)
treec6991c56183dc02f9295985c0533a9f185412b2a /test/test-connman
parent9f02a110ab06991b9bcce6ff1ff651c2069eb3ad (diff)
downloadconnman-7054e93685c8c18838cc78500566ba4277a5cb26.tar.gz
connman-7054e93685c8c18838cc78500566ba4277a5cb26.tar.bz2
connman-7054e93685c8c18838cc78500566ba4277a5cb26.zip
Add more advanced test script for device handling
Diffstat (limited to 'test/test-connman')
-rwxr-xr-xtest/test-connman265
1 files changed, 265 insertions, 0 deletions
diff --git a/test/test-connman b/test/test-connman
new file mode 100755
index 00000000..c59a064c
--- /dev/null
+++ b/test/test-connman
@@ -0,0 +1,265 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("org.moblin.connman", "/"),
+ "org.moblin.connman.Manager")
+
+if len(sys.argv) < 2:
+ print "Usage: %s <command>" % (sys.argv[0])
+ print ""
+ print " state"
+ print " scan [ <interface> ]"
+ print " dev <interface>"
+ print " dev <interface> scan"
+ print " dev <interface> networks"
+ print " dev <interface> connect <network>"
+ print " dev <interface> remember <network>"
+ print " dev <interface> disconnect [network]"
+ print " dev <interface> policy [ignore|off|auto|manual]"
+ print " dev <interface> powered [on|off]"
+ print " dev <interface> priority [0-255]"
+ sys.exit(1)
+
+def print_properties(path, properties):
+ print "[ %s ]" % (path)
+ for key in properties.keys():
+ if key == "Networks":
+ continue
+
+ if key in ["Powered", "Scanning", "Connected",
+ "Available", "Remember", "Default"]:
+ if properties[key] == dbus.Boolean(1):
+ val = "true"
+ else:
+ val = "false"
+ elif key in ["Strength", "Priority"]:
+ val = int(properties[key])
+ else:
+ val = str(properties[key])
+
+ print " %s = %s" % (key, val)
+
+ if "Networks" in properties.keys():
+ list = ""
+ for path in properties["Networks"]:
+ val = str(path)
+ list = list + val[val.rfind("/") + 1:] + " "
+ print " Networks = [ %s]" % (list)
+
+def print_networks(networks):
+ for path in networks:
+ network = dbus.Interface(bus.get_object("org.moblin.connman", path),
+ "org.moblin.connman.Network")
+
+ properties = network.GetProperties()
+
+ if properties["Connected"] == dbus.Boolean(1):
+ connected = "*"
+ else:
+ connected = " "
+
+ name = properties["Name"]
+ strength = int(properties["Strength"])
+
+ details = ""
+ try:
+ details += "{" + properties["WiFi.Mode"] + "} "
+ except:
+ pass
+ try:
+ details += "{" + properties["WiFi.Security"] + "} "
+ except:
+ pass
+ if "WiFi.Passphrase" in properties.keys():
+ if properties["WiFi.Passphrase"] != "":
+ details += "{passphrase present}"
+
+ print "%s %-20s %3d%% %s" % (connected,
+ name, strength, details)
+
+def select_network(networks, name):
+ for path in networks:
+ network = dbus.Interface(bus.get_object("org.moblin.connman", path),
+ "org.moblin.connman.Network")
+
+ properties = network.GetProperties()
+
+ if properties["Name"] != name:
+ continue
+
+ if properties["Connected"] == dbus.Boolean(1):
+ print "Already connected to network %s" % (name)
+ break
+
+ print "Selecting network %s" % (name)
+
+ network.Connect()
+
+def remember_network(networks, name):
+ for path in networks:
+ network = dbus.Interface(bus.get_object("org.moblin.connman", path),
+ "org.moblin.connman.Network")
+
+ properties = network.GetProperties()
+
+ if properties["Name"] != name:
+ continue
+
+ if properties["Remember"] == dbus.Boolean(1):
+ print "Already a known network %s" % (name)
+ break
+
+ print "Remembering network %s" % (name)
+
+ network.SetProperty("Remember", dbus.Boolean(1))
+
+def disconnect_network(networks, name):
+ for path in networks:
+ network = dbus.Interface(bus.get_object("org.moblin.connman", path),
+ "org.moblin.connman.Network")
+
+ properties = network.GetProperties()
+
+ if name != "" and properties["Name"] != name:
+ continue
+
+ if properties["Connected"] == dbus.Boolean(1):
+ name = properties["Name"]
+ print "Disconnecting from network %s" % (name)
+ network.Disconnect()
+
+if sys.argv[1] == "state":
+ properties = manager.GetProperties()
+
+ print "System is %s" % (properties["State"])
+
+elif sys.argv[1] == "scan":
+ properties = manager.GetProperties()
+
+ interface = ""
+ found = 0
+
+ if len(sys.argv) > 2:
+ interface = sys.argv[2]
+
+ for path in properties["Devices"]:
+ device = dbus.Interface(bus.get_object("org.moblin.connman", path),
+ "org.moblin.connman.Device")
+
+ properties = device.GetProperties()
+
+ if interface != "" and properties["Interface"] != interface:
+ continue
+
+ if properties["Type"] in ["wifi", "wimax"]:
+ interface = properties["Interface"]
+ print "Propose scanning for device %s" % (interface)
+ device.ProposeScan()
+ found = 1
+ elif interface != "":
+ print "No scanning support for device %s" % (interface)
+ found = 1
+
+ if found == 0:
+ print "No such device"
+
+elif sys.argv[1] == "dev":
+ properties = manager.GetProperties()
+
+ interface = ""
+ command = ""
+ value = ""
+ found = 0
+
+ if len(sys.argv) > 2:
+ interface = sys.argv[2]
+ if len(sys.argv) > 3:
+ command = sys.argv[3]
+ if len(sys.argv) > 4:
+ value = sys.argv[4]
+
+ for path in properties["Devices"]:
+ device = dbus.Interface(bus.get_object("org.moblin.connman", path),
+ "org.moblin.connman.Device")
+
+ properties = device.GetProperties()
+
+ if interface != "" and properties["Interface"] != interface:
+ continue
+
+ if command == "scan":
+ if properties["Type"] in ["wifi", "wimax"]:
+ interface = properties["Interface"]
+ print "Scan for device %s" % (interface)
+ device.ProposeScan()
+ else:
+ print "No scanning for device %s" % (interface)
+ elif command in ["networks", "net"]:
+ if "Networks" in properties.keys():
+ print_networks(properties["Networks"])
+ else:
+ print "Device has no networks"
+ elif command in ["connect", "conn"] and value != "":
+ if "Networks" in properties.keys():
+ select_network(properties["Networks"], value)
+ else:
+ print "Device can't connect networks"
+ elif command in ["connect", "conn"]:
+ print "Need to specify network"
+ elif command in ["remember", "known"] and value != "":
+ if "Networks" in properties.keys():
+ remember_network(properties["Networks"], value)
+ else:
+ print "Device has no networks"
+ elif command in ["remember", "known"]:
+ print "Need to specify network"
+ elif command in ["disconnect", "disc"] and value != "":
+ if "Networks" in properties.keys():
+ disconnect_network(properties["Networks"], value)
+ else:
+ print "Device has no networks"
+ elif command in ["discconnect", "disc"]:
+ if "Networks" in properties.keys():
+ disconnect_network(properties["Networks"], "")
+ else:
+ print "Device has no networks"
+ elif command == "policy" and value != "":
+ policy = value
+ device.SetProperty("Policy", policy)
+ elif command == "policy":
+ interface = properties["Interface"]
+ policy = properties["Policy"]
+ print "Policy of device %s is %s" % (interface, policy)
+ elif command == "powered" and value != "":
+ if value == "on":
+ powered = dbus.Boolean(1)
+ elif value == "off":
+ powered = dbus.Boolean(0)
+ else:
+ powered = dbus.Boolean(value)
+ device.SetProperty("Powered", powered)
+ elif command == "powered":
+ interface = properties["Interface"]
+ if properties["Powered"] == dbus.Boolean(1):
+ powered = "on"
+ else:
+ powered = "off"
+ print "Device %s is powered %s" % (interface, powered)
+ elif command == "priority" and value != "":
+ priority = int(value)
+ device.SetProperty("Priority", priority)
+ elif command == "priority":
+ interface = properties["Interface"]
+ priority = properties["Priority"]
+ print "Device %s has priority of %d" % (interface, priority)
+ elif command == "list" or command == "":
+ print_properties(path, properties)
+ else:
+ print "Unknown command"
+
+else:
+ print "Unknown command"