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> disconnect [network]"
27 print " dev <interface> powered [on|off]"
30 def print_properties(path, properties):
31 print "[ %s ]" % (path)
32 for key in properties.keys():
36 if key in ["Powered", "Scanning", "Connected",
37 "Available", "Remember", "Default"]:
38 if properties[key] == dbus.Boolean(1):
42 elif key in ["Strength", "Priority"]:
43 val = int(properties[key])
45 val = str(properties[key])
47 print " %s = %s" % (key, val)
49 if "Networks" in properties.keys():
51 for path in properties["Networks"]:
53 list = list + val[val.rfind("/") + 1:] + " "
54 print " Networks = [ %s]" % (list)
56 def print_networks(networks):
58 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
59 "org.moblin.connman.Network")
61 properties = network.GetProperties()
63 if properties["Connected"] == dbus.Boolean(1):
68 if "Name" in properties.keys():
69 name = properties["Name"]
73 strength = int(properties["Strength"])
77 details += "{" + properties["WiFi.Mode"] + "} "
81 details += "{" + properties["WiFi.Security"] + "} "
84 if "WiFi.Passphrase" in properties.keys():
85 if properties["WiFi.Passphrase"] != "":
86 details += "{passphrase present}"
88 print "%s %-26s %3d%% %s" % (connected,
89 name, strength, details)
91 def select_network(networks, name):
93 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
94 "org.moblin.connman.Network")
96 properties = network.GetProperties()
98 if properties["Name"] != name:
101 if properties["Connected"] == dbus.Boolean(1):
102 print "Already connected to network %s" % (name)
105 print "Selecting network %s" % (name)
109 def disconnect_network(networks, name):
110 for path in networks:
111 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
112 "org.moblin.connman.Network")
114 properties = network.GetProperties()
116 if name != "" and properties["Name"] != name:
119 if properties["Connected"] == dbus.Boolean(1):
120 name = properties["Name"]
121 print "Disconnecting from network %s" % (name)
124 def print_services(services):
125 for path in services:
126 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
127 "org.moblin.connman.Service")
129 properties = service.GetProperties()
131 identifier = path[path.rfind("/") + 1:]
133 if properties["Favorite"] == dbus.Boolean(1):
138 if "Name" in properties.keys():
139 name = properties["Name"]
141 name = "{" + properties["Type"] + "}"
143 print "%s %-26s { %s }" % (favorite, name, identifier)
145 if sys.argv[1] == "state":
146 properties = manager.GetProperties()
148 print "System is %s" % (properties["State"])
150 elif sys.argv[1] in ["services", "list", "show"]:
151 properties = manager.GetProperties()
153 print_services(properties["Services"])
155 elif sys.argv[1] in ["passphrase", "pass"]:
156 if (len(sys.argv) < 3):
157 print "Need at least service parameter"
160 path = "/profile/default/" + sys.argv[2]
162 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
163 "org.moblin.connman.Service")
165 if (len(sys.argv) > 3):
166 passphrase = sys.argv[3]
168 service.SetProperty("Passphrase", passphrase);
170 print "Passphrase %s set for %s" % (passphrase, sys.argv[2])
172 properties = service.GetProperties()
174 if "Name" in properties.keys():
175 name = properties["Name"]
177 name = "{" + properties["Type"] + "}"
179 if "Passphrase" in properties.keys():
180 passphrase = properties["Passphrase"]
182 passphrase = "not set"
184 print "Passphrase for %s is %s" % (name, passphrase)
186 elif sys.argv[1] in ["connect", "conn"]:
187 if (len(sys.argv) < 3):
188 print "Need at least service parameter"
191 path = "/profile/default/" + sys.argv[2]
193 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
194 "org.moblin.connman.Service")
197 service.Connect(timeout=60000)
198 except dbus.DBusException, error:
199 print "%s: %s" % (error._dbus_error_name, error.message)
201 elif sys.argv[1] in ["disconnect", "disc"]:
202 if (len(sys.argv) < 3):
203 print "Need at least service parameter"
206 path = "/profile/default/" + sys.argv[2]
208 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
209 "org.moblin.connman.Service")
213 except dbus.DBusException, error:
214 print "%s: %s" % (error._dbus_error_name, error.message)
216 elif sys.argv[1] in ["remove"]:
217 if (len(sys.argv) < 3):
218 print "Need at least service parameter"
221 path = "/profile/default/" + sys.argv[2]
223 service = dbus.Interface(bus.get_object("org.moblin.connman", path),
224 "org.moblin.connman.Service")
226 properties = service.GetProperties()
228 if properties["Favorite"] == dbus.Boolean(0):
229 print "Only favorite services can be removed"
234 except dbus.DBusException, error:
235 print "%s: %s" % (error._dbus_error_name, error.message)
237 elif sys.argv[1] == "scan":
238 properties = manager.GetProperties()
243 if len(sys.argv) > 2:
244 interface = sys.argv[2]
246 for path in properties["Devices"]:
247 device = dbus.Interface(bus.get_object("org.moblin.connman", path),
248 "org.moblin.connman.Device")
250 properties = device.GetProperties()
252 if interface != "" and properties["Interface"] != interface:
255 if properties["Type"] in ["wifi", "wimax"]:
256 interface = properties["Interface"]
257 print "Propose scanning for device %s" % (interface)
260 elif interface != "":
261 print "No scanning support for device %s" % (interface)
265 print "No such device"
267 elif sys.argv[1] == "dev":
268 properties = manager.GetProperties()
275 if len(sys.argv) > 2:
276 interface = sys.argv[2]
277 if len(sys.argv) > 3:
278 command = sys.argv[3]
279 if len(sys.argv) > 4:
282 for path in properties["Devices"]:
283 device = dbus.Interface(bus.get_object("org.moblin.connman", path),
284 "org.moblin.connman.Device")
286 properties = device.GetProperties()
288 if interface != "" and properties["Interface"] != interface:
291 if command == "scan":
292 if properties["Type"] in ["wifi", "wimax"]:
293 interface = properties["Interface"]
294 print "Scan for device %s" % (interface)
297 print "No scanning for device %s" % (interface)
298 elif command in ["networks", "net"]:
299 if "Networks" in properties.keys():
300 print_networks(properties["Networks"])
302 print "Device has no networks"
303 elif command in ["connect", "conn"] and value != "":
304 if "Networks" in properties.keys():
305 select_network(properties["Networks"], value)
307 print "Device can't connect networks"
308 elif command in ["connect", "conn"]:
309 print "Need to specify network"
310 elif command in ["disconnect", "disc"] and value != "":
311 if "Networks" in properties.keys():
312 disconnect_network(properties["Networks"], value)
314 print "Device has no networks"
315 elif command in ["discconnect", "disc"]:
316 if "Networks" in properties.keys():
317 disconnect_network(properties["Networks"], "")
319 print "Device has no networks"
320 elif command == "powered" and value != "":
322 powered = dbus.Boolean(1)
324 powered = dbus.Boolean(0)
326 powered = dbus.Boolean(value)
327 device.SetProperty("Powered", powered)
328 elif command == "powered":
329 interface = properties["Interface"]
330 if properties["Powered"] == dbus.Boolean(1):
334 print "Device %s is powered %s" % (interface, powered)
335 elif command == "list" or command == "":
336 print_properties(path, properties)
338 print "Unknown command"
341 print "Unknown command"