OLD | NEW |
1 import dbus, dbus.mainloop.glib, gobject, logging, re, sys, time, subprocess | 1 import dbus, dbus.mainloop.glib, gobject, logging, re, sys, time, subprocess |
2 | 2 |
3 ssid = sys.argv[1] | 3 ssid = sys.argv[1] |
4 security = sys.argv[2] | 4 security = sys.argv[2] |
5 psk = sys.argv[3] | 5 psk = sys.argv[3] |
6 assoc_timeout = float(sys.argv[4]) | 6 assoc_timeout = float(sys.argv[4]) |
7 config_timeout = float(sys.argv[5]) | 7 config_timeout = float(sys.argv[5]) |
8 reset_timeout = float(sys.argv[6]) if len(sys.argv) > 6 else assoc_timeout | 8 reset_timeout = float(sys.argv[6]) if len(sys.argv) > 6 else assoc_timeout |
9 | 9 |
| 10 FLIMFLAM = "org.chromium.flimflam" |
| 11 |
10 bus_loop = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) | 12 bus_loop = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
11 bus = dbus.SystemBus(mainloop=bus_loop) | 13 bus = dbus.SystemBus(mainloop=bus_loop) |
12 manager = dbus.Interface(bus.get_object("org.chromium.flimflam", "/"), | 14 manager = dbus.Interface(bus.get_object(FLIMFLAM, "/"), FLIMFLAM + ".Manager") |
13 "org.chromium.flimflam.Manager") | |
14 connect_quirks = {} | 15 connect_quirks = {} |
15 | 16 |
16 connection_settings = { | 17 connection_settings = { |
17 "Type": "wifi", | 18 "Type": "wifi", |
18 "Mode": "managed", | 19 "Mode": "managed", |
19 "SSID": ssid, | 20 "SSID": ssid, |
20 "Security": security | 21 "Security": security |
21 } | 22 } |
22 | 23 |
23 if security == '802_1x': | 24 if security == '802_1x': |
24 (connection_settings["Identity"], | 25 (connection_settings["Identity"], |
25 connection_settings["CertPath"]) = psk.split(':') | 26 connection_settings["CertPath"]) = psk.split(':') |
26 else: | 27 else: |
27 connection_settings["Passphrase"] = psk | 28 connection_settings["Passphrase"] = psk |
28 | 29 |
| 30 |
29 def DbusSetup(): | 31 def DbusSetup(): |
30 try: | 32 try: |
31 path = manager.GetService((connection_settings)) | 33 path = manager.GetService((connection_settings)) |
32 service = dbus.Interface( | 34 service = dbus.Interface( |
33 bus.get_object("org.chromium.flimflam", path), | 35 bus.get_object(FLIMFLAM, path), FLIMFLAM + ".Service") |
34 "org.chromium.flimflam.Service") | |
35 except Exception, e: | 36 except Exception, e: |
36 print "FAIL(GetService): ssid %s exception %s" %(ssid, e) | 37 print "FAIL(GetService): ssid %s exception %s" % (ssid, e) |
37 ErrExit(1) | 38 ErrExit(1) |
38 | 39 |
39 return (path, service) | 40 return (path, service) |
40 | 41 |
41 | 42 |
42 def ParseProps(props): | 43 def ParseProps(props): |
43 proplist = [] | 44 proplist = [] |
44 if props is not None: | 45 if props is not None: |
45 for p in props: | 46 for p in props: |
46 proplist.append("'%s': '%s'" % (str(p), str(props[p]))) | 47 proplist.append("'%s': '%s'" % (str(p), str(props[p]))) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 print "FAIL(Connect): ssid %s exception %s" %(ssid, e) | 117 print "FAIL(Connect): ssid %s exception %s" %(ssid, e) |
117 ErrExit(2) | 118 ErrExit(2) |
118 | 119 |
119 properties = None | 120 properties = None |
120 # wait up to assoc_timeout seconds to associate | 121 # wait up to assoc_timeout seconds to associate |
121 while assoc_time < assoc_timeout: | 122 while assoc_time < assoc_timeout: |
122 try: | 123 try: |
123 properties = service.GetProperties() | 124 properties = service.GetProperties() |
124 except dbus.exceptions.DBusException, e: | 125 except dbus.exceptions.DBusException, e: |
125 connect_quirks['get_prop'] = 1 | 126 connect_quirks['get_prop'] = 1 |
126 print>>sys.stderr, "Got exception trying GetProperties()!" | 127 print>>sys.stderr, "Got exception trying GetProperties(): %s" % e |
127 return (None, 'DBUSFAIL') | 128 return (None, 'DBUSFAIL') |
128 status = properties.get("State", None) | 129 status = properties.get("State", None) |
129 # print>>sys.stderr, "time %3.1f state %s" % (assoc_time, status) | 130 # print>>sys.stderr, "time %3.1f state %s" % (assoc_time, status) |
130 if status == "failure": | 131 if status == "failure": |
131 if assoc_time == init_assoc_time: | 132 if assoc_time == init_assoc_time: |
132 connect_quirks['fast_fail'] = 1 | 133 connect_quirks['fast_fail'] = 1 |
133 print>>sys.stderr, "failure on first try! Sleep 5 seconds" | 134 print>>sys.stderr, "failure on first try! Sleep 5 seconds" |
134 time.sleep(5) | 135 time.sleep(5) |
135 return (properties, 'FAIL') | 136 return (properties, 'FAIL') |
136 if status == "configuration" or status == "ready": | 137 if status == "configuration" or status == "ready": |
137 return (properties, None) | 138 return (properties, None) |
138 time.sleep(.5) | 139 time.sleep(.5) |
139 assoc_time += .5 | 140 assoc_time += .5 |
140 if assoc_time >= assoc_timeout: | 141 if assoc_time >= assoc_timeout: |
141 if properties is None: | 142 if properties is None: |
142 properties = service.GetProperties() | 143 properties = service.GetProperties() |
143 return (properties, 'TIMEOUT') | 144 return (properties, 'TIMEOUT') |
144 ErrExit(4) | |
145 | 145 |
146 | 146 |
147 # Open /var/log/messages and seek to the current end | 147 # Open /var/log/messages and seek to the current end |
148 def OpenLogs(*logfiles): | 148 def OpenLogs(*logfiles): |
149 logs = [] | 149 logs = [] |
150 for logfile in logfiles: | 150 for logfile in logfiles: |
151 try: | 151 try: |
152 msgs = open(logfile) | 152 msgs = open(logfile) |
153 msgs.seek(0, 2) | 153 msgs.seek(0, 2) |
154 logs.append({ 'name': logfile, 'file': msgs }) | 154 logs.append({ 'name': logfile, 'file': msgs }) |
155 except Exception, e: | 155 except Exception, e: |
156 # If we cannot open the file, this is not necessarily an error | 156 # If we cannot open the file, this is not necessarily an error |
157 pass | 157 pass |
158 | 158 |
159 return logs | 159 return logs |
160 | 160 |
161 | 161 |
| 162 def DumpObjectList(kind): |
| 163 print>>sys.stderr, "%s list:" % kind |
| 164 for item in [dbus.Interface(bus.get_object(FLIMFLAM, path), |
| 165 FLIMFLAM + "." + kind) |
| 166 for path in manager.GetProperties().get(kind + 's', [])]: |
| 167 print>>sys.stderr, "[ %s ]" % (item.object_path) |
| 168 for key, val in item.GetProperties().items(): |
| 169 print>>sys.stderr, " %s = %s" % (key, str(val)) |
| 170 |
162 # Returns the list of the wifi interfaces (e.g. "wlan0") known to flimflam | 171 # Returns the list of the wifi interfaces (e.g. "wlan0") known to flimflam |
163 def GetWifiInterfaces(): | 172 def GetWifiInterfaces(): |
164 interfaces = [] | 173 interfaces = [] |
165 device_paths = manager.GetProperties().get("Devices", None) | 174 device_paths = manager.GetProperties().get("Devices", None) |
166 for device_path in device_paths: | 175 for device_path in device_paths: |
167 device = dbus.Interface( | 176 device = dbus.Interface( |
168 bus.get_object("org.chromium.flimflam", device_path), | 177 bus.get_object("org.chromium.flimflam", device_path), |
169 "org.chromium.flimflam.Device") | 178 "org.chromium.flimflam.Device") |
170 props = device.GetProperties() | 179 props = device.GetProperties() |
171 type = props.get("Type", None) | 180 type = props.get("Type", None) |
172 interface = props.get("Interface", None) | 181 interface = props.get("Interface", None) |
173 if type == "wifi": | 182 if type == "wifi": |
174 interfaces.append(interface) | 183 interfaces.append(interface) |
175 return interfaces | 184 return interfaces |
176 | 185 |
177 def DumpLogs(logs): | 186 def DumpLogs(logs): |
178 for log in logs: | 187 for log in logs: |
179 print>>sys.stderr, "Content of %s during our run:" % log['name'] | 188 print>>sys.stderr, "Content of %s during our run:" % log['name'] |
180 print>>sys.stderr, " ))) ".join(log['file'].readlines()) | 189 print>>sys.stderr, " ))) ".join(log['file'].readlines()) |
181 | 190 |
182 for interface in GetWifiInterfaces(): | 191 for interface in GetWifiInterfaces(): |
183 print>>sys.stderr, "iw dev %s scan output: %s" % \ | 192 print>>sys.stderr, "iw dev %s scan output: %s" % \ |
184 ( interface, | 193 ( interface, |
185 subprocess.Popen(["iw", "dev", interface, "scan"], | 194 subprocess.Popen(["iw", "dev", interface, "scan"], |
186 stdout=subprocess.PIPE).communicate()[0]) | 195 stdout=subprocess.PIPE).communicate()[0]) |
187 | 196 |
| 197 DumpObjectList("Service") |
| 198 |
188 def ErrExit(code): | 199 def ErrExit(code): |
189 try: | 200 try: |
190 service.Disconnect() | 201 service.Disconnect() |
191 except: | 202 except: |
192 pass | 203 pass |
193 DumpLogs(logs) | 204 DumpLogs(logs) |
194 sys.exit(code) | 205 sys.exit(code) |
195 | 206 |
196 logs = OpenLogs('/var/log/messages', '/var/log/hostap.log') | 207 logs = OpenLogs('/var/log/messages', '/var/log/hostap.log') |
197 | 208 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 print "TIMEOUT(config): ssid %s assoc %3.1f config %3.1f secs" \ | 252 print "TIMEOUT(config): ssid %s assoc %3.1f config %3.1f secs" \ |
242 %(ssid, assoc_time, config_time) | 253 %(ssid, assoc_time, config_time) |
243 ErrExit(6) | 254 ErrExit(6) |
244 | 255 |
245 print "OK %3.1f %3.1f %s (assoc and config times in sec, quirks)" \ | 256 print "OK %3.1f %3.1f %s (assoc and config times in sec, quirks)" \ |
246 %(assoc_time, config_time, str(connect_quirks.keys())) | 257 %(assoc_time, config_time, str(connect_quirks.keys())) |
247 | 258 |
248 if connect_quirks: | 259 if connect_quirks: |
249 DumpLogs(logs) | 260 DumpLogs(logs) |
250 sys.exit(0) | 261 sys.exit(0) |
OLD | NEW |