8 manager = dbus.Interface(bus.get_object("org.moblin.connman", "/"),
9 "org.moblin.connman.Manager")
12 print "Usage: %s <command>" % (sys.argv[0])
15 print " scan [ <interface> ]"
16 print " dev <interface>"
17 print " dev <interface> scan"
18 print " dev <interface> networks"
19 print " dev <interface> connect <network>"
20 print " dev <interface> remember <network>"
21 print " dev <interface> disconnect [network]"
22 print " dev <interface> policy [ignore|off|auto|manual]"
23 print " dev <interface> powered [on|off]"
24 print " dev <interface> priority [0-255]"
27 def print_properties(path, properties):
28 print "[ %s ]" % (path)
29 for key in properties.keys():
33 if key in ["Powered", "Scanning", "Connected",
34 "Available", "Remember", "Default"]:
35 if properties[key] == dbus.Boolean(1):
39 elif key in ["Strength", "Priority"]:
40 val = int(properties[key])
42 val = str(properties[key])
44 print " %s = %s" % (key, val)
46 if "Networks" in properties.keys():
48 for path in properties["Networks"]:
50 list = list + val[val.rfind("/") + 1:] + " "
51 print " Networks = [ %s]" % (list)
53 def print_networks(networks):
55 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
56 "org.moblin.connman.Network")
58 properties = network.GetProperties()
60 if properties["Connected"] == dbus.Boolean(1):
65 name = properties["Name"]
66 strength = int(properties["Strength"])
70 details += "{" + properties["WiFi.Mode"] + "} "
74 details += "{" + properties["WiFi.Security"] + "} "
77 if "WiFi.Passphrase" in properties.keys():
78 if properties["WiFi.Passphrase"] != "":
79 details += "{passphrase present}"
81 print "%s %-20s %3d%% %s" % (connected,
82 name, strength, details)
84 def select_network(networks, name):
86 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
87 "org.moblin.connman.Network")
89 properties = network.GetProperties()
91 if properties["Name"] != name:
94 if properties["Connected"] == dbus.Boolean(1):
95 print "Already connected to network %s" % (name)
98 print "Selecting network %s" % (name)
102 def remember_network(networks, name):
103 for path in networks:
104 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
105 "org.moblin.connman.Network")
107 properties = network.GetProperties()
109 if properties["Name"] != name:
112 if properties["Remember"] == dbus.Boolean(1):
113 print "Already a known network %s" % (name)
116 print "Remembering network %s" % (name)
118 network.SetProperty("Remember", dbus.Boolean(1))
120 def disconnect_network(networks, name):
121 for path in networks:
122 network = dbus.Interface(bus.get_object("org.moblin.connman", path),
123 "org.moblin.connman.Network")
125 properties = network.GetProperties()
127 if name != "" and properties["Name"] != name:
130 if properties["Connected"] == dbus.Boolean(1):
131 name = properties["Name"]
132 print "Disconnecting from network %s" % (name)
135 if sys.argv[1] == "state":
136 properties = manager.GetProperties()
138 print "System is %s" % (properties["State"])
140 elif sys.argv[1] == "scan":
141 properties = manager.GetProperties()
146 if len(sys.argv) > 2:
147 interface = sys.argv[2]
149 for path in properties["Devices"]:
150 device = dbus.Interface(bus.get_object("org.moblin.connman", path),
151 "org.moblin.connman.Device")
153 properties = device.GetProperties()
155 if interface != "" and properties["Interface"] != interface:
158 if properties["Type"] in ["wifi", "wimax"]:
159 interface = properties["Interface"]
160 print "Propose scanning for device %s" % (interface)
163 elif interface != "":
164 print "No scanning support for device %s" % (interface)
168 print "No such device"
170 elif sys.argv[1] == "dev":
171 properties = manager.GetProperties()
178 if len(sys.argv) > 2:
179 interface = sys.argv[2]
180 if len(sys.argv) > 3:
181 command = sys.argv[3]
182 if len(sys.argv) > 4:
185 for path in properties["Devices"]:
186 device = dbus.Interface(bus.get_object("org.moblin.connman", path),
187 "org.moblin.connman.Device")
189 properties = device.GetProperties()
191 if interface != "" and properties["Interface"] != interface:
194 if command == "scan":
195 if properties["Type"] in ["wifi", "wimax"]:
196 interface = properties["Interface"]
197 print "Scan for device %s" % (interface)
200 print "No scanning for device %s" % (interface)
201 elif command in ["networks", "net"]:
202 if "Networks" in properties.keys():
203 print_networks(properties["Networks"])
205 print "Device has no networks"
206 elif command in ["connect", "conn"] and value != "":
207 if "Networks" in properties.keys():
208 select_network(properties["Networks"], value)
210 print "Device can't connect networks"
211 elif command in ["connect", "conn"]:
212 print "Need to specify network"
213 elif command in ["remember", "known"] and value != "":
214 if "Networks" in properties.keys():
215 remember_network(properties["Networks"], value)
217 print "Device has no networks"
218 elif command in ["remember", "known"]:
219 print "Need to specify network"
220 elif command in ["disconnect", "disc"] and value != "":
221 if "Networks" in properties.keys():
222 disconnect_network(properties["Networks"], value)
224 print "Device has no networks"
225 elif command in ["discconnect", "disc"]:
226 if "Networks" in properties.keys():
227 disconnect_network(properties["Networks"], "")
229 print "Device has no networks"
230 elif command == "policy" and value != "":
232 device.SetProperty("Policy", policy)
233 elif command == "policy":
234 interface = properties["Interface"]
235 policy = properties["Policy"]
236 print "Policy of device %s is %s" % (interface, policy)
237 elif command == "powered" and value != "":
239 powered = dbus.Boolean(1)
241 powered = dbus.Boolean(0)
243 powered = dbus.Boolean(value)
244 device.SetProperty("Powered", powered)
245 elif command == "powered":
246 interface = properties["Interface"]
247 if properties["Powered"] == dbus.Boolean(1):
251 print "Device %s is powered %s" % (interface, powered)
252 elif command == "priority" and value != "":
253 priority = int(value)
254 device.SetProperty("Priority", priority)
255 elif command == "priority":
256 interface = properties["Interface"]
257 priority = properties["Priority"]
258 print "Device %s has priority of %d" % (interface, priority)
259 elif command == "list" or command == "":
260 print_properties(path, properties)
262 print "Unknown command"
265 print "Unknown command"