mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 04:48:00 +01:00
Improved the authentication validation code. Instead of sleeping for an abitrary amount of time, then checking if authentication succeeded, it now repeatedly checks for a longer set amount of time. This way it is less likely to fail because it didn't wait long enough, but will usually finish faster.
This commit is contained in:
@@ -483,7 +483,6 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
self.SetStatus('generating_wpa_config')
|
self.SetStatus('generating_wpa_config')
|
||||||
print 'Attempting to authenticate...'
|
print 'Attempting to authenticate...'
|
||||||
wiface.Authenticate(self.network)
|
wiface.Authenticate(self.network)
|
||||||
auth_time = time.time()
|
|
||||||
|
|
||||||
if self.should_die:
|
if self.should_die:
|
||||||
wiface.Up()
|
wiface.Up()
|
||||||
@@ -512,19 +511,9 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
self.network['bssid'])
|
self.network['bssid'])
|
||||||
|
|
||||||
if self.network.get('enctype') is not None:
|
if self.network.get('enctype') is not None:
|
||||||
# Allow some time for wpa_supplicant to associate.
|
|
||||||
# Hopefully 3 sec is enough. If it proves to be inconsistent,
|
|
||||||
# we might have to try to monitor wpa_supplicant more closely,
|
|
||||||
# so we can tell exactly when it fails/succeeds.
|
|
||||||
self.SetStatus('validating_authentication')
|
self.SetStatus('validating_authentication')
|
||||||
elapsed = time.time() - auth_time
|
|
||||||
if elapsed < 3 and elapsed >= 0:
|
|
||||||
if self.debug:
|
|
||||||
print 'sleeping for ' + str(3 - elapsed)
|
|
||||||
time.sleep(3 - elapsed)
|
|
||||||
|
|
||||||
# Make sure wpa_supplicant was able to associate.
|
# Make sure wpa_supplicant was able to associate.
|
||||||
if not wiface.ValidateAuthentication():
|
if not wiface.ValidateAuthentication(time.time()):
|
||||||
self.connect_aborted('bad_pass')
|
self.connect_aborted('bad_pass')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
29
wnettools.py
29
wnettools.py
@@ -791,7 +791,7 @@ class WirelessInterface(Interface):
|
|||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
def ValidateAuthentication(self):
|
def ValidateAuthentication(self, auth_time):
|
||||||
""" Validate WPA authentication.
|
""" Validate WPA authentication.
|
||||||
|
|
||||||
Validate that the wpa_supplicant authentication
|
Validate that the wpa_supplicant authentication
|
||||||
@@ -806,37 +806,44 @@ class WirelessInterface(Interface):
|
|||||||
if self.wpa_driver == RALINK_DRIVER:
|
if self.wpa_driver == RALINK_DRIVER:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
MAX_TIME = 5
|
||||||
|
MAX_DISCONNECTED_TIME = 3
|
||||||
|
while (time.time() - auth_time) < MAX_TIME:
|
||||||
cmd = 'wpa_cli -i ' + self.iface + ' status'
|
cmd = 'wpa_cli -i ' + self.iface + ' status'
|
||||||
if self.verbose: print cmd
|
|
||||||
output = misc.Run(cmd)
|
output = misc.Run(cmd)
|
||||||
result = misc.RunRegex(auth_pattern, output)
|
result = misc.RunRegex(auth_pattern, output)
|
||||||
|
if self.verbose:
|
||||||
|
print 'WPA_CLI RESULT IS', result
|
||||||
|
|
||||||
|
if not result:
|
||||||
|
return False
|
||||||
if result == "COMPLETED":
|
if result == "COMPLETED":
|
||||||
return True
|
return True
|
||||||
elif result == "DISCONNECTED":
|
elif result == "DISCONNECTED" and \
|
||||||
|
(time.time() - auth_time) > MAX_DISCONNECTED_TIME:
|
||||||
# Force a rescan to get wpa_supplicant moving again.
|
# Force a rescan to get wpa_supplicant moving again.
|
||||||
self._ForceSupplicantScan()
|
self._ForceSupplicantScan()
|
||||||
return self.ValidateAuthentication()
|
MAX_TIME += 5
|
||||||
else:
|
time.sleep(1)
|
||||||
|
|
||||||
print 'wpa_supplicant authentication may have failed.'
|
print 'wpa_supplicant authentication may have failed.'
|
||||||
return False
|
return False
|
||||||
pass
|
|
||||||
|
|
||||||
def _ForceSupplicantScan(self):
|
def _ForceSupplicantScan(self):
|
||||||
""" Force wpa_supplicant to rescan available networks.
|
""" Force wpa_supplicant to rescan available networks.
|
||||||
|
|
||||||
This function forces wpa_supplicant to rescan, then sleeps
|
This function forces wpa_supplicant to rescan.
|
||||||
to allow the scan to finish and reassociation to take place.
|
|
||||||
This works around authentication validation sometimes failing for
|
This works around authentication validation sometimes failing for
|
||||||
wpa_supplicant because it remains in a DISCONNECTED state for
|
wpa_supplicant because it remains in a DISCONNECTED state for
|
||||||
quite a while, after which a rescan is required, and then
|
quite a while, after which a rescan is required, and then
|
||||||
attempting to authenticate.
|
attempting to authenticate. This whole process takes a long
|
||||||
|
time, so we manually speed it up if we see it happening.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
print 'wpa_supplicant rescan forced...'
|
print 'wpa_supplicant rescan forced...'
|
||||||
cmd = 'wpa_cli -i' + self.iface + ' scan'
|
cmd = 'wpa_cli -i' + self.iface + ' scan'
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
time.sleep(5)
|
|
||||||
print 'Trying to validate authentication again'
|
|
||||||
|
|
||||||
def _AuthenticateRalinkLegacy(self, network):
|
def _AuthenticateRalinkLegacy(self, network):
|
||||||
""" Authenticate with the specified wireless network.
|
""" Authenticate with the specified wireless network.
|
||||||
|
|||||||
Reference in New Issue
Block a user