8 manager = dbus.Interface(bus.get_object("org.moblin.connman", "/"),
9 "org.moblin.connman.Manager")
12 print "Usage: %s <command>" % (sys.argv[0])
16 print " apn <service> [apn]"
17 print " passphrase <service> [passphrase]"
18 print " autoconnect <service> [autoconnect]"
19 print " connect <service>"
20 print " disconnect <service>"
21 print " remove <service>"
24 print " enable <type>"
25 print " disable <type>"
26 print " offlinemode [on|off]"
28 print " dev <interface>"
29 print " dev <interface> scan"
30 print " dev <interface> scan_interval <period>"
31 print " dev <interface> networks"
32 print " dev <interface> connect <network>"
33 print " dev <interface> disconnect [network]"
34 print " dev <interface> powered [on|off]"
37 def print_properties(path, properties):
38 print "[ %s ]" % (path)
39 for key in properties.keys():
43 if key in ["Powered", "Scanning", "Connected",
44 "Available", "Remember", "Default"]:
45 if properties[key] == dbus.Boolean(1):
49 elif key in ["Strength", "Priority"]:
50 val = int(properties[key])
52 val = str(properties[key])
54 print " %s = %s" % (key, val)
56 if "Networks" in properties.keys():
58 for path in properties["Networks"]:
60 list = list + val[val.rfind("/") + 1:] + " "
61 print " Networks = [ %s]" % (list)
63 def print_networks(networks):
65 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
66 "org.moblin.connman.Network")
68 properties = network.GetProperties()
70 if properties["Connected"] == dbus.Boolean(1):
75 if "Name" in properties.keys():
76 name = properties["Name"]
80 strength = int(properties["Strength"])
84 details += "{" + properties["WiFi.Mode"] + "} "
88 details += "{" + properties["WiFi.Security"] + "} "
91 if "WiFi.Passphrase" in properties.keys():
92 if properties["WiFi.Passphrase"] != "":
93 details += "{passphrase present}"
95 print "%s %-26s %3d%% %s" % (connected,
96 name, strength, details)
98 def select_network(networks, name):
100 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
101 "org.moblin.connman.Network")
103 properties = network.GetProperties()
105 if properties["Name"] != name:
108 if properties["Connected"] == dbus.Boolean(1):
109 print "Already connected to network %s" % (name)
112 print "Selecting network %s" % (name)
116 def disconnect_network(networks, name):
117 for path in networks:
118 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
119 "org.moblin.connman.Network")
121 properties = network.GetProperties()
123 if name != "" and properties["Name"] != name:
126 if properties["Connected"] == dbus.Boolean(1):
127 name = properties["Name"]
128 print "Disconnecting from network %s" % (name)
131 def print_services(services):
132 for path in services:
133 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
134 "org.moblin.connman.Service")
136 properties = service.GetProperties()
138 identifier = path[path.rfind("/") + 1:]
140 if properties["Favorite"] == dbus.Boolean(1):
145 if "Name" in properties.keys():
146 name = properties["Name"]
148 name = "{" + properties["Type"] + "}"
150 print "%s %-26s { %s }" % (favorite, name, identifier)
152 def device_handle(devices, interface):
154 device = dbus.Interface(bus.get_object("org.moblin.connman", path),
155 "org.moblin.connman.Device")
157 properties = device.GetProperties()
159 if "Interface" not in properties.keys():
162 if interface != "" and properties["Interface"] != interface:
165 if command == "scan":
166 if properties["Type"] in ["wifi", "wimax"]:
167 interface = properties["Interface"]
168 print "Scan for device %s" % (interface)
171 print "No scanning for device %s" % (interface)
172 elif command == "scan_interval" and value != "":
173 device.SetProperty("ScanInterval", dbus.UInt16(value))
174 elif command in ["networks", "net"]:
175 if "Networks" in properties.keys():
176 print_networks(properties["Networks"])
178 print "Device has no networks"
179 elif command in ["connect", "conn"] and value != "":
180 if "Networks" in properties.keys():
181 select_network(properties["Networks"], value)
183 print "Device can't connect networks"
184 elif command in ["connect", "conn"]:
185 print "Need to specify network"
186 elif command in ["disconnect", "disc"] and value != "":
187 if "Networks" in properties.keys():
188 disconnect_network(properties["Networks"], value)
190 print "Device has no networks"
191 elif command in ["discconnect", "disc"]:
192 if "Networks" in properties.keys():
193 disconnect_network(properties["Networks"], "")
195 print "Device has no networks"
196 elif command == "powered" and value != "":
198 powered = dbus.Boolean(1)
200 powered = dbus.Boolean(0)
202 powered = dbus.Boolean(value)
203 device.SetProperty("Powered", powered)
204 elif command == "powered":
205 interface = properties["Interface"]
206 if properties["Powered"] == dbus.Boolean(1):
210 print "Device %s is powered %s" % (interface, powered)
211 elif command == "list" or command == "":
212 print_properties(path, properties)
214 print "Unknown command"
218 if sys.argv[1] == "state":
219 properties = manager.GetProperties()
221 print "System is %s" % (properties["State"])
223 elif sys.argv[1] in ["services", "list", "show"]:
224 properties = manager.GetProperties()
226 print_services(properties["Services"])
228 elif sys.argv[1] in ["apn"]:
229 if (len(sys.argv) < 3):
230 print "Need at least service parameter"
233 path = "/profile/default/" + sys.argv[2]
235 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
236 "org.moblin.connman.Service")
238 if (len(sys.argv) > 3):
241 service.SetProperty("APN", apn);
243 print "APN %s set for %s" % (apn, sys.argv[2])
245 properties = service.GetProperties()
247 if "Name" in properties.keys():
248 name = properties["Name"]
250 name = "{" + properties["Type"] + "}"
252 if "APN" in properties.keys():
253 apn = properties["APN"]
257 print "APN for %s is %s" % (name, apn)
259 elif sys.argv[1] in ["passphrase", "pass"]:
260 if (len(sys.argv) < 3):
261 print "Need at least service parameter"
264 path = "/profile/default/" + sys.argv[2]
266 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
267 "org.moblin.connman.Service")
269 if (len(sys.argv) > 3):
270 passphrase = sys.argv[3]
272 service.SetProperty("Passphrase", passphrase);
274 print "Passphrase %s set for %s" % (passphrase, sys.argv[2])
276 properties = service.GetProperties()
278 if "Name" in properties.keys():
279 name = properties["Name"]
281 name = "{" + properties["Type"] + "}"
283 if "Passphrase" in properties.keys():
284 passphrase = properties["Passphrase"]
286 passphrase = "not set"
288 print "Passphrase for %s is %s" % (name, passphrase)
290 elif sys.argv[1] in ["autoconnect", "autoconn"]:
291 if (len(sys.argv) < 3):
292 print "Need at least service parameter"
295 path = "/profile/default/" + sys.argv[2]
297 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
298 "org.moblin.connman.Service")
300 if (len(sys.argv) > 3):
301 flag = sys.argv[3].strip().lower()
302 autoconnect = dbus.Boolean(flag not in ['false', 'f', 'n', '0'])
304 service.SetProperty("AutoConnect", autoconnect);
306 print "Auto connect %s for %s" % (autoconnect, sys.argv[2])
308 properties = service.GetProperties()
310 if "Name" in properties.keys():
311 name = properties["Name"]
313 name = "{" + properties["Type"] + "}"
315 if "AutoConnect" in properties.keys():
316 autoconnect = properties["AutoConnect"]
318 autoconnect = dbus.Boolean(0)
320 print "Auto connect %s for %s" % (autoconnect, name)
322 elif sys.argv[1] in ["connect", "conn"]:
323 if (len(sys.argv) < 3):
324 print "Need at least service parameter"
327 path = "/profile/default/" + sys.argv[2]
329 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
330 "org.moblin.connman.Service")
333 service.Connect(timeout=60000)
334 except dbus.DBusException, error:
335 print "%s: %s" % (error._dbus_error_name, error.message)
337 elif sys.argv[1] in ["disconnect", "disc"]:
338 if (len(sys.argv) < 3):
339 print "Need at least service parameter"
342 path = "/profile/default/" + sys.argv[2]
344 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
345 "org.moblin.connman.Service")
349 except dbus.DBusException, error:
350 print "%s: %s" % (error._dbus_error_name, error.message)
352 elif sys.argv[1] in ["remove"]:
353 if (len(sys.argv) < 3):
354 print "Need at least service parameter"
357 path = "/profile/default/" + sys.argv[2]
359 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
360 "org.moblin.connman.Service")
362 properties = service.GetProperties()
364 if properties["Favorite"] == dbus.Boolean(0):
365 print "Only favorite services can be removed"
370 except dbus.DBusException, error:
371 print "%s: %s" % (error._dbus_error_name, error.message)
373 elif sys.argv[1] == "scan":
374 if len(sys.argv) > 2:
375 manager.RequestScan(sys.argv[2])
377 manager.RequestScan("")
379 elif sys.argv[1] == "enable":
380 if len(sys.argv) > 2:
381 manager.EnableTechnology(sys.argv[2])
383 manager.EnableTechnology("")
385 elif sys.argv[1] == "disable":
386 if len(sys.argv) > 2:
387 manager.DisableTechnology(sys.argv[2])
389 manager.DisableTechnology("")
391 elif sys.argv[1] in ["offlinemode", "flightmode"]:
392 if len(sys.argv) > 2:
393 if sys.argv[2] == "on":
394 active = dbus.Boolean(1)
395 elif sys.argv[2] == "off":
396 active = dbus.Boolean(0)
398 active = dbus.Boolean(sys.argv[2])
399 manager.SetProperty("OfflineMode", active)
401 properties = manager.GetProperties()
402 print "Offline mode is %s" % (properties["OfflineMode"])
404 elif sys.argv[1] == "dev":
405 properties = manager.GetProperties()
412 if len(sys.argv) > 2:
413 interface = sys.argv[2]
414 if len(sys.argv) > 3:
415 command = sys.argv[3]
416 if len(sys.argv) > 4:
419 for path in properties["Technologies"]:
420 technology = dbus.Interface(bus.get_object("org.moblin.connman", path),
421 "org.moblin.connman.Technology")
423 properties = technology.GetProperties()
425 device_handle(properties["Devices"], interface)
428 print "Unknown command"