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>"
21 print " scan [ <interface> ]"
22 print " dev <interface>"
23 print " dev <interface> scan"
24 print " dev <interface> networks"
25 print " dev <interface> connect <network>"
26 print " dev <interface> remember <network>"
27 print " dev <interface> disconnect [network]"
28 print " dev <interface> policy [ignore|off|auto|manual]"
29 print " dev <interface> powered [on|off]"
30 print " dev <interface> priority [0-255]"
33 def print_properties(path, properties):
34 print "[ %s ]" % (path)
35 for key in properties.keys():
39 if key in ["Powered", "Scanning", "Connected",
40 "Available", "Remember", "Default"]:
41 if properties[key] == dbus.Boolean(1):
45 elif key in ["Strength", "Priority"]:
46 val = int(properties[key])
48 val = str(properties[key])
50 print " %s = %s" % (key, val)
52 if "Networks" in properties.keys():
54 for path in properties["Networks"]:
56 list = list + val[val.rfind("/") + 1:] + " "
57 print " Networks = [ %s]" % (list)
59 def print_networks(networks):
61 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
62 "org.moblin.connman.Network")
64 properties = network.GetProperties()
66 if properties["Connected"] == dbus.Boolean(1):
71 if "Name" in properties.keys():
72 name = properties["Name"]
76 strength = int(properties["Strength"])
80 details += "{" + properties["WiFi.Mode"] + "} "
84 details += "{" + properties["WiFi.Security"] + "} "
87 if "WiFi.Passphrase" in properties.keys():
88 if properties["WiFi.Passphrase"] != "":
89 details += "{passphrase present}"
91 print "%s %-26s %3d%% %s" % (connected,
92 name, strength, details)
94 def select_network(networks, name):
96 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
97 "org.moblin.connman.Network")
99 properties = network.GetProperties()
101 if properties["Name"] != name:
104 if properties["Connected"] == dbus.Boolean(1):
105 print "Already connected to network %s" % (name)
108 print "Selecting network %s" % (name)
112 def remember_network(networks, name):
113 for path in networks:
114 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
115 "org.moblin.connman.Network")
117 properties = network.GetProperties()
119 if properties["Name"] != name:
122 if properties["Remember"] == dbus.Boolean(1):
123 print "Already a known network %s" % (name)
126 print "Remembering network %s" % (name)
128 network.SetProperty("Remember", dbus.Boolean(1))
130 def disconnect_network(networks, name):
131 for path in networks:
132 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
133 "org.moblin.connman.Network")
135 properties = network.GetProperties()
137 if name != "" and properties["Name"] != name:
140 if properties["Connected"] == dbus.Boolean(1):
141 name = properties["Name"]
142 print "Disconnecting from network %s" % (name)
145 def print_services(services):
146 for path in services:
147 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
148 "org.moblin.connman.Service")
150 properties = service.GetProperties()
152 identifier = path[path.rfind("/") + 1:]
154 if properties["Favorite"] == dbus.Boolean(1):
159 if "Name" in properties.keys():
160 name = properties["Name"]
162 name = "{" + properties["Type"] + "}"
164 print "%s %-26s { %s }" % (favorite, name, identifier)
166 if sys.argv[1] == "state":
167 properties = manager.GetProperties()
169 print "System is %s" % (properties["State"])
171 elif sys.argv[1] in ["services", "list", "show"]:
172 properties = manager.GetProperties()
174 print_services(properties["Services"])
176 elif sys.argv[1] in ["passphrase", "pass"]:
177 if (len(sys.argv) < 3):
178 print "Need at least service parameter"
181 path = "/profile/default/" + sys.argv[2]
183 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
184 "org.moblin.connman.Service")
186 if (len(sys.argv) > 3):
187 passphrase = sys.argv[3]
189 service.SetProperty("Passphrase", passphrase);
191 print "Passphrase %s set for %s" % (passphrase, sys.argv[2])
193 properties = service.GetProperties()
195 if "Name" in properties.keys():
196 name = properties["Name"]
198 name = "{" + properties["Type"] + "}"
200 if "Passphrase" in properties.keys():
201 passphrase = properties["Passphrase"]
203 passphrase = "not set"
205 print "Passphrase for %s is %s" % (name, passphrase)
207 elif sys.argv[1] in ["connect", "conn"]:
208 if (len(sys.argv) < 3):
209 print "Need at least service parameter"
212 path = "/profile/default/" + sys.argv[2]
214 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
215 "org.moblin.connman.Service")
219 elif sys.argv[1] in ["disconnect", "disc"]:
220 if (len(sys.argv) < 3):
221 print "Need at least service parameter"
224 path = "/profile/default/" + sys.argv[2]
226 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
227 "org.moblin.connman.Service")
231 elif sys.argv[1] in ["remove"]:
232 if (len(sys.argv) < 3):
233 print "Need at least service parameter"
236 path = "/profile/default/" + sys.argv[2]
238 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
239 "org.moblin.connman.Service")
241 properties = service.GetProperties()
243 if properties["Favorite"] == dbus.Boolean(0):
244 print "Only favorite services can be removed"
249 elif sys.argv[1] == "scan":
250 properties = manager.GetProperties()
255 if len(sys.argv) > 2:
256 interface = sys.argv[2]
258 for path in properties["Devices"]:
259 device = dbus.Interface(bus.get_object("org.moblin.connman", path),
260 "org.moblin.connman.Device")
262 properties = device.GetProperties()
264 if interface != "" and properties["Interface"] != interface:
267 if properties["Type"] in ["wifi", "wimax"]:
268 interface = properties["Interface"]
269 print "Propose scanning for device %s" % (interface)
272 elif interface != "":
273 print "No scanning support for device %s" % (interface)
277 print "No such device"
279 elif sys.argv[1] == "dev":
280 properties = manager.GetProperties()
287 if len(sys.argv) > 2:
288 interface = sys.argv[2]
289 if len(sys.argv) > 3:
290 command = sys.argv[3]
291 if len(sys.argv) > 4:
294 for path in properties["Devices"]:
295 device = dbus.Interface(bus.get_object("org.moblin.connman", path),
296 "org.moblin.connman.Device")
298 properties = device.GetProperties()
300 if interface != "" and properties["Interface"] != interface:
303 if command == "scan":
304 if properties["Type"] in ["wifi", "wimax"]:
305 interface = properties["Interface"]
306 print "Scan for device %s" % (interface)
309 print "No scanning for device %s" % (interface)
310 elif command in ["networks", "net"]:
311 if "Networks" in properties.keys():
312 print_networks(properties["Networks"])
314 print "Device has no networks"
315 elif command in ["connect", "conn"] and value != "":
316 if "Networks" in properties.keys():
317 select_network(properties["Networks"], value)
319 print "Device can't connect networks"
320 elif command in ["connect", "conn"]:
321 print "Need to specify network"
322 elif command in ["remember", "known"] and value != "":
323 if "Networks" in properties.keys():
324 remember_network(properties["Networks"], value)
326 print "Device has no networks"
327 elif command in ["remember", "known"]:
328 print "Need to specify network"
329 elif command in ["disconnect", "disc"] and value != "":
330 if "Networks" in properties.keys():
331 disconnect_network(properties["Networks"], value)
333 print "Device has no networks"
334 elif command in ["discconnect", "disc"]:
335 if "Networks" in properties.keys():
336 disconnect_network(properties["Networks"], "")
338 print "Device has no networks"
339 elif command == "policy" and value != "":
341 device.SetProperty("Policy", policy)
342 elif command == "policy":
343 interface = properties["Interface"]
344 policy = properties["Policy"]
345 print "Policy of device %s is %s" % (interface, policy)
346 elif command == "powered" and value != "":
348 powered = dbus.Boolean(1)
350 powered = dbus.Boolean(0)
352 powered = dbus.Boolean(value)
353 device.SetProperty("Powered", powered)
354 elif command == "powered":
355 interface = properties["Interface"]
356 if properties["Powered"] == dbus.Boolean(1):
360 print "Device %s is powered %s" % (interface, powered)
361 elif command == "priority" and value != "":
362 priority = int(value)
363 device.SetProperty("Priority", priority)
364 elif command == "priority":
365 interface = properties["Interface"]
366 priority = properties["Priority"]
367 print "Device %s has priority of %d" % (interface, priority)
368 elif command == "list" or command == "":
369 print_properties(path, properties)
371 print "Unknown command"
374 print "Unknown command"