print ""
print " state"
print " services"
+ print " apn <service> [apn]"
print " passphrase <service> [passphrase]"
+ print " autoconnect <service> [autoconnect]"
print " connect <service>"
print " disconnect <service>"
print " remove <service>"
print ""
print " dev <interface>"
print " dev <interface> scan"
+ print " dev <interface> scan_interval <period>"
print " dev <interface> networks"
print " dev <interface> connect <network>"
print " dev <interface> disconnect [network]"
print "%s %-26s { %s }" % (favorite, name, identifier)
+def device_handle(devices, interface):
+ for path in devices:
+ device = dbus.Interface(bus.get_object("org.moblin.connman", path),
+ "org.moblin.connman.Device")
+
+ properties = device.GetProperties()
+
+ if "Interface" not in properties.keys():
+ continue
+
+ 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 == "scan_interval" and value != "":
+ device.SetProperty("ScanInterval", dbus.UInt16(value))
+ 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 ["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 == "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 == "list" or command == "":
+ print_properties(path, properties)
+ else:
+ print "Unknown command"
+
+
+
if sys.argv[1] == "state":
properties = manager.GetProperties()
print_services(properties["Services"])
+elif sys.argv[1] in ["apn"]:
+ if (len(sys.argv) < 3):
+ print "Need at least service parameter"
+ sys.exit(1)
+
+ path = "/profile/default/" + sys.argv[2]
+
+ service = dbus.Interface(bus.get_object("org.moblin.connman", path),
+ "org.moblin.connman.Service")
+
+ if (len(sys.argv) > 3):
+ apn = sys.argv[3]
+
+ service.SetProperty("APN", apn);
+
+ print "APN %s set for %s" % (apn, sys.argv[2])
+ else:
+ properties = service.GetProperties()
+
+ if "Name" in properties.keys():
+ name = properties["Name"]
+ else:
+ name = "{" + properties["Type"] + "}"
+
+ if "APN" in properties.keys():
+ apn = properties["APN"]
+ else:
+ apn = "not set"
+
+ print "APN for %s is %s" % (name, apn)
+
elif sys.argv[1] in ["passphrase", "pass"]:
if (len(sys.argv) < 3):
print "Need at least service parameter"
print "Passphrase for %s is %s" % (name, passphrase)
+elif sys.argv[1] in ["autoconnect", "autoconn"]:
+ if (len(sys.argv) < 3):
+ print "Need at least service parameter"
+ sys.exit(1)
+
+ path = "/profile/default/" + sys.argv[2]
+
+ service = dbus.Interface(bus.get_object("org.moblin.connman", path),
+ "org.moblin.connman.Service")
+
+ if (len(sys.argv) > 3):
+ flag = sys.argv[3].strip().lower()
+ autoconnect = dbus.Boolean(flag not in ['false', 'f', 'n', '0'])
+
+ service.SetProperty("AutoConnect", autoconnect);
+
+ print "Auto connect %s for %s" % (autoconnect, sys.argv[2])
+ else:
+ properties = service.GetProperties()
+
+ if "Name" in properties.keys():
+ name = properties["Name"]
+ else:
+ name = "{" + properties["Type"] + "}"
+
+ if "AutoConnect" in properties.keys():
+ autoconnect = properties["AutoConnect"]
+ else:
+ autoconnect = dbus.Boolean(0)
+
+ print "Auto connect %s for %s" % (autoconnect, name)
+
elif sys.argv[1] in ["connect", "conn"]:
if (len(sys.argv) < 3):
print "Need at least service parameter"
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()
+ for path in properties["Technologies"]:
+ technology = dbus.Interface(bus.get_object("org.moblin.connman", path),
+ "org.moblin.connman.Technology")
- if interface != "" and properties["Interface"] != interface:
- continue
+ properties = technology.GetProperties()
- 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 ["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 == "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 == "list" or command == "":
- print_properties(path, properties)
- else:
- print "Unknown command"
+ device_handle(properties["Devices"], interface)
else:
print "Unknown command"