| 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 bus_loop = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) | 10 bus_loop = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 11 bus = dbus.SystemBus(mainloop=bus_loop) | 11 bus = dbus.SystemBus(mainloop=bus_loop) |
| 12 manager = dbus.Interface(bus.get_object("org.chromium.flimflam", "/"), | 12 manager = dbus.Interface(bus.get_object("org.chromium.flimflam", "/"), |
| 13 "org.chromium.flimflam.Manager") | 13 "org.chromium.flimflam.Manager") |
| 14 | 14 connect_quirks = {} |
| 15 | 15 |
| 16 def DbusSetup(): | 16 def DbusSetup(): |
| 17 try: | 17 try: |
| 18 path = manager.GetService(({ | 18 path = manager.GetService(({ |
| 19 "Type": "wifi", | 19 "Type": "wifi", |
| 20 "Mode": "managed", | 20 "Mode": "managed", |
| 21 "SSID": ssid, | 21 "SSID": ssid, |
| 22 "Security": security, | 22 "Security": security, |
| 23 "Passphrase": psk })) | 23 "Passphrase": psk })) |
| 24 service = dbus.Interface( | 24 service = dbus.Interface( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 | 40 |
| 41 def ResetService(init_state): | 41 def ResetService(init_state): |
| 42 wait_time = 0 | 42 wait_time = 0 |
| 43 | 43 |
| 44 if init_state == 'idle': | 44 if init_state == 'idle': |
| 45 # If we are already idle, we have nothing to do | 45 # If we are already idle, we have nothing to do |
| 46 return | 46 return |
| 47 if init_state == 'ready': | 47 if init_state == 'ready': |
| 48 # flimflam is already connected. Disconnect. | 48 # flimflam is already connected. Disconnect. |
| 49 connect_quirks['already_connected'] = 1 |
| 49 service.Disconnect() | 50 service.Disconnect() |
| 50 else: | 51 else: |
| 51 # Workaround to force flimflam out of error state and back to 'idle' | 52 # Workaround to force flimflam out of error state and back to 'idle' |
| 53 connect_quirks['clear_error'] = 1 |
| 52 service.ClearProperty('Error') | 54 service.ClearProperty('Error') |
| 53 | 55 |
| 54 while wait_time < reset_timeout: | 56 while wait_time < reset_timeout: |
| 55 if service.GetProperties().get("State", None) == "idle": | 57 if service.GetProperties().get("State", None) == "idle": |
| 56 break | 58 break |
| 57 time.sleep(2) | 59 time.sleep(2) |
| 58 wait_time += 2 | 60 wait_time += 2 |
| 59 | 61 |
| 60 print>>sys.stderr, "cleared ourselves out of '%s' after %3.1f secs" % \ | 62 print>>sys.stderr, "cleared ourselves out of '%s' after %3.1f secs" % \ |
| 61 (init_state, wait_time) | 63 (init_state, wait_time) |
| 62 time.sleep(4) | 64 time.sleep(4) |
| 63 | 65 |
| 64 | 66 |
| 65 def TryConnect(assoc_time): | 67 def TryConnect(assoc_time): |
| 66 init_assoc_time = assoc_time | 68 init_assoc_time = assoc_time |
| 67 try: | 69 try: |
| 68 init_state = service.GetProperties().get("State", None) | 70 init_props = service.GetProperties() |
| 71 init_state = init_props.get("State", None) |
| 72 if init_state == "configuration" or init_state == "ready": |
| 73 if assoc_time > 0: |
| 74 # We connected in the time between the last failure and now |
| 75 print>>sys.stderr, "Associated while we weren't looking!" |
| 76 return (init_props, None) |
| 69 except dbus.exceptions.DBusException, e: | 77 except dbus.exceptions.DBusException, e: |
| 78 connect_quirks['lost_dbus'] = 1 |
| 70 print>>sys.stderr, "We just lost the service handle!" | 79 print>>sys.stderr, "We just lost the service handle!" |
| 71 return (None, 'DBUSFAIL') | 80 return (None, 'DBUSFAIL') |
| 72 | 81 |
| 73 ResetService(init_state) | 82 ResetService(init_state) |
| 74 | 83 |
| 75 # print "INIT_STATUS1: %s" % service.GetProperties().get("State", None) | 84 # print "INIT_STATUS1: %s" % service.GetProperties().get("State", None) |
| 76 | 85 |
| 77 try: | 86 try: |
| 78 service.Connect() | 87 service.Connect() |
| 88 except org.chromium.flimflam.Error.InProgress, e: |
| 89 # We can hope that a ResetService in the next call will solve this |
| 90 connect_quirks['in_progress'] = 1 |
| 91 print>>sys.stderr, "Previous connect is still in progress!" |
| 92 time.sleep(.5) |
| 93 return (None, 'FAIL') |
| 79 except Exception, e: | 94 except Exception, e: |
| 80 print "FAIL(Connect): ssid %s exception %s" %(ssid, e) | 95 print "FAIL(Connect): ssid %s exception %s" %(ssid, e) |
| 81 sys.exit(2) | 96 sys.exit(2) |
| 82 | 97 |
| 83 properties = None | 98 properties = None |
| 84 # wait up to assoc_timeout seconds to associate | 99 # wait up to assoc_timeout seconds to associate |
| 85 while assoc_time < assoc_timeout: | 100 while assoc_time < assoc_timeout: |
| 86 properties = service.GetProperties() | 101 properties = service.GetProperties() |
| 87 status = properties.get("State", None) | 102 status = properties.get("State", None) |
| 88 # print>>sys.stderr, "time %3.1f state %s" % (assoc_time, status) | 103 # print>>sys.stderr, "time %3.1f state %s" % (assoc_time, status) |
| 89 if status == "failure": | 104 if status == "failure": |
| 90 if assoc_time == init_assoc_time: | 105 if assoc_time == init_assoc_time: |
| 106 connect_quirks['fast_fail'] = 1 |
| 91 print>>sys.stderr, "failure on first try! Sleep 5 seconds" | 107 print>>sys.stderr, "failure on first try! Sleep 5 seconds" |
| 92 time.sleep(5) | 108 time.sleep(5) |
| 93 return (properties, 'FAIL') | 109 return (properties, 'FAIL') |
| 94 if status == "configuration" or status == "ready": | 110 if status == "configuration" or status == "ready": |
| 95 return (properties, None) | 111 return (properties, None) |
| 96 time.sleep(.5) | 112 time.sleep(.5) |
| 97 assoc_time += .5 | 113 assoc_time += .5 |
| 98 if assoc_time >= assoc_timeout: | 114 if assoc_time >= assoc_timeout: |
| 99 if properties is None: | 115 if properties is None: |
| 100 properties = service.GetProperties() | 116 properties = service.GetProperties() |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 assoc_time = time.time() - assoc_start | 152 assoc_time = time.time() - assoc_start |
| 137 print>>sys.stderr, "connect attempt #%d %3.1f secs" % (attempt, assoc_time) | 153 print>>sys.stderr, "connect attempt #%d %3.1f secs" % (attempt, assoc_time) |
| 138 (properties, failure_type) = TryConnect(assoc_time) | 154 (properties, failure_type) = TryConnect(assoc_time) |
| 139 if failure_type is None or failure_type == 'TIMEOUT': | 155 if failure_type is None or failure_type == 'TIMEOUT': |
| 140 break | 156 break |
| 141 if failure_type == 'DBUSFAIL': | 157 if failure_type == 'DBUSFAIL': |
| 142 (path, service) = DbusSetup() | 158 (path, service) = DbusSetup() |
| 143 | 159 |
| 144 assoc_time = time.time() - assoc_start | 160 assoc_time = time.time() - assoc_start |
| 145 | 161 |
| 162 if attempt > 0: |
| 163 connect_quirks['multiple_attempts'] = 1 |
| 164 |
| 146 if failure_type is not None: | 165 if failure_type is not None: |
| 147 print "%s(assoc): ssid %s assoc %3.1f secs props %s" \ | 166 print "%s(assoc): ssid %s assoc %3.1f secs props %s" \ |
| 148 %(failure_type, ssid, assoc_time, ParseProps(properties)) | 167 %(failure_type, ssid, assoc_time, ParseProps(properties)) |
| 149 DumpLogs() | 168 DumpLogs(logs) |
| 150 sys.exit(3) | 169 sys.exit(3) |
| 151 | 170 |
| 152 # wait another config_timeout seconds to get an ip address | 171 # wait another config_timeout seconds to get an ip address |
| 153 config_time = 0 | 172 config_time = 0 |
| 154 status = properties.get("State", None) | 173 status = properties.get("State", None) |
| 155 if status != "ready": | 174 if status != "ready": |
| 156 while config_time < config_timeout: | 175 while config_time < config_timeout: |
| 157 properties = service.GetProperties() | 176 properties = service.GetProperties() |
| 158 status = properties.get("State", None) | 177 status = properties.get("State", None) |
| 159 # print>>sys.stderr, "time %3.1f state %s" % (config_time, status) | 178 # print>>sys.stderr, "time %3.1f state %s" % (config_time, status) |
| 160 if status == "failure": | 179 if status == "failure": |
| 161 print "FAIL(config): ssid %s assoc %3.1f config %3.1f secs" \ | 180 print "FAIL(config): ssid %s assoc %3.1f config %3.1f secs" \ |
| 162 %(ssid, assoc_time, config_time) | 181 %(ssid, assoc_time, config_time) |
| 163 sys.exit(5) | 182 sys.exit(5) |
| 164 if status == "ready": | 183 if status == "ready": |
| 165 break | 184 break |
| 166 if status != "configuration": | 185 if status != "configuration": |
| 167 print "FAIL(config): ssid %s assoc %3.1f config %3.1f secs *%s*" \ | 186 print "FAIL(config): ssid %s assoc %3.1f config %3.1f secs *%s*" \ |
| 168 %(ssid, assoc_time, config_time, status) | 187 %(ssid, assoc_time, config_time, status) |
| 169 break | 188 break |
| 170 time.sleep(.5) | 189 time.sleep(.5) |
| 171 config_time += .5 | 190 config_time += .5 |
| 172 if config_time >= config_timeout: | 191 if config_time >= config_timeout: |
| 173 print "TIMEOUT(config): ssid %s assoc %3.1f config %3.1f secs" \ | 192 print "TIMEOUT(config): ssid %s assoc %3.1f config %3.1f secs" \ |
| 174 %(ssid, assoc_time, config_time) | 193 %(ssid, assoc_time, config_time) |
| 175 DumpLogs() | 194 DumpLogs(logs) |
| 176 sys.exit(6) | 195 sys.exit(6) |
| 177 | 196 |
| 178 print "OK %3.1f %3.1f (assoc and config times in sec)" \ | 197 print "OK %3.1f %3.1f %s (assoc and config times in sec, quirks)" \ |
| 179 %(assoc_time, config_time) | 198 %(assoc_time, config_time, str(connect_quirks.keys())) |
| 180 sys.exit(0) | 199 sys.exit(0) |
| 181 | 200 |
| OLD | NEW |