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 " passphrase <service> [passphrase]"
17 print " connect <service>"
18 print " disconnect <service>"
19 print " remove <service>"
22 print " enable <type>"
23 print " disable <type>"
24 print " offlinemode [on|off]"
26 print " dev <interface>"
27 print " dev <interface> scan"
28 print " dev <interface> networks"
29 print " dev <interface> connect <network>"
30 print " dev <interface> disconnect [network]"
31 print " dev <interface> powered [on|off]"
34 def print_properties(path, properties):
35 print "[ %s ]" % (path)
36 for key in properties.keys():
40 if key in ["Powered", "Scanning", "Connected",
41 "Available", "Remember", "Default"]:
42 if properties[key] == dbus.Boolean(1):
46 elif key in ["Strength", "Priority"]:
47 val = int(properties[key])
49 val = str(properties[key])
51 print " %s = %s" % (key, val)
53 if "Networks" in properties.keys():
55 for path in properties["Networks"]:
57 list = list + val[val.rfind("/") + 1:] + " "
58 print " Networks = [ %s]" % (list)
60 def print_networks(networks):
62 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
63 "org.moblin.connman.Network")
65 properties = network.GetProperties()
67 if properties["Connected"] == dbus.Boolean(1):
72 if "Name" in properties.keys():
73 name = properties["Name"]
77 strength = int(properties["Strength"])
81 details += "{" + properties["WiFi.Mode"] + "} "
85 details += "{" + properties["WiFi.Security"] + "} "
88 if "WiFi.Passphrase" in properties.keys():
89 if properties["WiFi.Passphrase"] != "":
90 details += "{passphrase present}"
92 print "%s %-26s %3d%% %s" % (connected,
93 name, strength, details)
95 def select_network(networks, name):
97 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
98 "org.moblin.connman.Network")
100 properties = network.GetProperties()
102 if properties["Name"] != name:
105 if properties["Connected"] == dbus.Boolean(1):
106 print "Already connected to network %s" % (name)
109 print "Selecting network %s" % (name)
113 def disconnect_network(networks, name):
114 for path in networks:
115 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
116 "org.moblin.connman.Network")
118 properties = network.GetProperties()
120 if name != "" and properties["Name"] != name:
123 if properties["Connected"] == dbus.Boolean(1):
124 name = properties["Name"]
125 print "Disconnecting from network %s" % (name)
128 def print_services(services):
129 for path in services:
130 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
131 "org.moblin.connman.Service")
133 properties = service.GetProperties()
135 identifier = path[path.rfind("/") + 1:]
137 if properties["Favorite"] == dbus.Boolean(1):
142 if "Name" in properties.keys():
143 name = properties["Name"]
145 name = "{" + properties["Type"] + "}"
147 print "%s %-26s { %s }" % (favorite, name, identifier)
149 if sys.argv[1] == "state":
150 properties = manager.GetProperties()
152 print "System is %s" % (properties["State"])
154 elif sys.argv[1] in ["services", "list", "show"]:
155 properties = manager.GetProperties()
157 print_services(properties["Services"])
159 elif sys.argv[1] in ["passphrase", "pass"]:
160 if (len(sys.argv) < 3):
161 print "Need at least service parameter"
164 path = "/profile/default/" + sys.argv[2]
166 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
167 "org.moblin.connman.Service")
169 if (len(sys.argv) > 3):
170 passphrase = sys.argv[3]
172 service.SetProperty("Passphrase", passphrase);
174 print "Passphrase %s set for %s" % (passphrase, sys.argv[2])
176 properties = service.GetProperties()
178 if "Name" in properties.keys():
179 name = properties["Name"]
181 name = "{" + properties["Type"] + "}"
183 if "Passphrase" in properties.keys():
184 passphrase = properties["Passphrase"]
186 passphrase = "not set"
188 print "Passphrase for %s is %s" % (name, passphrase)
190 elif sys.argv[1] in ["connect", "conn"]:
191 if (len(sys.argv) < 3):
192 print "Need at least service parameter"
195 path = "/profile/default/" + sys.argv[2]
197 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
198 "org.moblin.connman.Service")
201 service.Connect(timeout=60000)
202 except dbus.DBusException, error:
203 print "%s: %s" % (error._dbus_error_name, error.message)
205 elif sys.argv[1] in ["disconnect", "disc"]:
206 if (len(sys.argv) < 3):
207 print "Need at least service parameter"
210 path = "/profile/default/" + sys.argv[2]
212 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
213 "org.moblin.connman.Service")
217 except dbus.DBusException, error:
218 print "%s: %s" % (error._dbus_error_name, error.message)
220 elif sys.argv[1] in ["remove"]:
221 if (len(sys.argv) < 3):
222 print "Need at least service parameter"
225 path = "/profile/default/" + sys.argv[2]
227 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
228 "org.moblin.connman.Service")
230 properties = service.GetProperties()
232 if properties["Favorite"] == dbus.Boolean(0):
233 print "Only favorite services can be removed"
238 except dbus.DBusException, error:
239 print "%s: %s" % (error._dbus_error_name, error.message)
241 elif sys.argv[1] == "scan":
242 if len(sys.argv) > 2:
243 manager.RequestScan(sys.argv[2])
245 manager.RequestScan("")
247 elif sys.argv[1] == "enable":
248 if len(sys.argv) > 2:
249 manager.EnableTechnology(sys.argv[2])
251 manager.EnableTechnology("")
253 elif sys.argv[1] == "disable":
254 if len(sys.argv) > 2:
255 manager.DisableTechnology(sys.argv[2])
257 manager.DisableTechnology("")
259 elif sys.argv[1] in ["offlinemode", "flightmode"]:
260 if len(sys.argv) > 2:
261 if sys.argv[2] == "on":
262 active = dbus.Boolean(1)
263 elif sys.argv[2] == "off":
264 active = dbus.Boolean(0)
266 active = dbus.Boolean(sys.argv[2])
267 manager.SetProperty("OfflineMode", active)
269 properties = manager.GetProperties()
270 print "Offline mode is %s" % (properties["OfflineMode"])
272 elif sys.argv[1] == "dev":
273 properties = manager.GetProperties()
280 if len(sys.argv) > 2:
281 interface = sys.argv[2]
282 if len(sys.argv) > 3:
283 command = sys.argv[3]
284 if len(sys.argv) > 4:
287 for path in properties["Devices"]:
288 device = dbus.Interface(bus.get_object("org.moblin.connman", path),
289 "org.moblin.connman.Device")
291 properties = device.GetProperties()
293 if interface != "" and properties["Interface"] != interface:
296 if command == "scan":
297 if properties["Type"] in ["wifi", "wimax"]:
298 interface = properties["Interface"]
299 print "Scan for device %s" % (interface)
302 print "No scanning for device %s" % (interface)
303 elif command in ["networks", "net"]:
304 if "Networks" in properties.keys():
305 print_networks(properties["Networks"])
307 print "Device has no networks"
308 elif command in ["connect", "conn"] and value != "":
309 if "Networks" in properties.keys():
310 select_network(properties["Networks"], value)
312 print "Device can't connect networks"
313 elif command in ["connect", "conn"]:
314 print "Need to specify network"
315 elif command in ["disconnect", "disc"] and value != "":
316 if "Networks" in properties.keys():
317 disconnect_network(properties["Networks"], value)
319 print "Device has no networks"
320 elif command in ["discconnect", "disc"]:
321 if "Networks" in properties.keys():
322 disconnect_network(properties["Networks"], "")
324 print "Device has no networks"
325 elif command == "powered" and value != "":
327 powered = dbus.Boolean(1)
329 powered = dbus.Boolean(0)
331 powered = dbus.Boolean(value)
332 device.SetProperty("Powered", powered)
333 elif command == "powered":
334 interface = properties["Interface"]
335 if properties["Powered"] == dbus.Boolean(1):
339 print "Device %s is powered %s" % (interface, powered)
340 elif command == "list" or command == "":
341 print_properties(path, properties)
343 print "Unknown command"
346 print "Unknown command"