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 " scan [ <interface> ]"
+ print " scan [type]"
+ print " enable <type>"
+ print " disable <type>"
+ print " offlinemode [on|off]"
+ 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> 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):
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),
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"
service = dbus.Interface(bus.get_object("org.moblin.connman", path),
"org.moblin.connman.Service")
- service.Connect()
+ try:
+ service.Connect(timeout=60000)
+ except dbus.DBusException, error:
+ print "%s: %s" % (error._dbus_error_name, error.message)
elif sys.argv[1] in ["disconnect", "disc"]:
if (len(sys.argv) < 3):
service = dbus.Interface(bus.get_object("org.moblin.connman", path),
"org.moblin.connman.Service")
- service.Disconnect()
+ try:
+ service.Disconnect()
+ except dbus.DBusException, error:
+ print "%s: %s" % (error._dbus_error_name, error.message)
elif sys.argv[1] in ["remove"]:
if (len(sys.argv) < 3):
print "Only favorite services can be removed"
sys.exit(1)
- service.Remove()
+ try:
+ service.Remove()
+ except dbus.DBusException, error:
+ print "%s: %s" % (error._dbus_error_name, error.message)
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()
+ manager.RequestScan(sys.argv[2])
+ else:
+ manager.RequestScan("")
- if interface != "" and properties["Interface"] != interface:
- continue
+elif sys.argv[1] == "enable":
+ if len(sys.argv) > 2:
+ manager.EnableTechnology(sys.argv[2])
+ else:
+ manager.EnableTechnology("")
- 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
+elif sys.argv[1] == "disable":
+ if len(sys.argv) > 2:
+ manager.DisableTechnology(sys.argv[2])
+ else:
+ manager.DisableTechnology("")
- if found == 0:
- print "No such device"
+elif sys.argv[1] in ["offlinemode", "flightmode"]:
+ if len(sys.argv) > 2:
+ if sys.argv[2] == "on":
+ active = dbus.Boolean(1)
+ elif sys.argv[2] == "off":
+ active = dbus.Boolean(0)
+ else:
+ active = dbus.Boolean(sys.argv[2])
+ manager.SetProperty("OfflineMode", active)
+ else:
+ properties = manager.GetProperties()
+ print "Offline mode is %s" % (properties["OfflineMode"])
elif sys.argv[1] == "dev":
properties = manager.GetProperties()
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 ["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"
+ device_handle(properties["Devices"], interface)
else:
print "Unknown command"