1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-21 05:18:02 +01:00

- Replace some tabs that snuck in with spaces.

- Try to validate successful association with static IPs by pinging the gateway specified.
This commit is contained in:
Dan O'Reilly
2009-03-21 16:28:40 -04:00
parent 518e0ec358
commit 34832775c8
6 changed files with 132 additions and 92 deletions

View File

@@ -228,7 +228,7 @@ class WiredInterface(Interface, wnettools.BaseWiredInterface):
self.Up()
time.sleep(2.5)
buff = struct.pack('16shhhh', (self.iface + '\0' * 16)[:16], 0, 1,
0x0004, 0)
0x0004, 0)
try:
result = fcntl.ioctl(self.sock.fileno(), SIOCGMIIPHY, buff)
except IOError, e:
@@ -360,7 +360,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
"""
error= "Unable to find ctrl_interface for wpa_supplicant. " + \
"Could not validate authentication."
"Could not validate authentication."
# Right now there's no way to do this for ralink drivers
if self.wpa_driver == RALINK_DRIVER:
@@ -433,7 +433,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
info[4] == 'WEP'):
print 'Setting up WEP'
cmd = ''.join(['iwconfig ', self.iface, ' key ',
network.get('key')])
network.get('key')])
if self.verbose: print cmd
misc.Run(cmd)
else:
@@ -451,7 +451,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
key_name = 'WPAPSK'
else:
print 'Unknown AuthMode, can\'t complete ' + \
'connection process!'
'connection process!'
return
cmd_list = []
@@ -495,7 +495,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
print "SIOCGIWRATE failed: " + str(e)
return ""
f, e, x, x = struct.unpack(fmt, result[:size])
return "%s %s" % ((f / 1000000), 'Mb/s')
return "%s %s" % ((f / 1000000), 'Mb/s')
#def GetOperationalMode(self, iwconfig=None):
# """ Get the operational mode for the interface. """
@@ -572,4 +572,3 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
return None
return buff.strip('\x00')

View File

@@ -69,7 +69,8 @@ class WicdError(Exception):
__LANG = None
def Run(cmd, include_stderr=False, return_pipe=False, return_obj=False):
def Run(cmd, include_stderr=False, return_pipe=False,
return_obj=False, return_retcode=True):
""" Run a command.
Runs the given command, returning either the output
@@ -81,8 +82,10 @@ def Run(cmd, include_stderr=False, return_pipe=False, return_obj=False):
be included in the pipe to the cmd.
return_pipe - Boolean specifying if a pipe to the
command should be returned. If it is
false, all that will be returned is
False, all that will be returned is
one output string from the command.
return_obj - If True, Run will return the Popen object
for the command that was run.
"""
global __LANG
@@ -136,8 +139,14 @@ def LaunchAndWait(cmd):
cmd : A list contained the program name and its arguments.
returns: The exit code of the process.
"""
call(cmd, shell=False)
if not isinstance(cmd, list):
cmd = to_unicode(str(cmd))
cmd = cmd.split()
p = Popen(cmd, shell=False, stdout=PIPE, stderr=STDOUT, stdin=None)
return p.wait()
def IsValidIP(ip):
""" Make sure an entered IP is valid. """

View File

@@ -183,15 +183,13 @@ class ConnectionStatus(object):
if daemon.GetSuspend():
print "Suspended."
state = misc.SUSPENDED
self.update_state(state)
return True
return self.update_state(state)
# Determine what our current state is.
# Are we currently connecting?
if daemon.CheckIfConnecting():
state = misc.CONNECTING
self.update_state(state)
return True
return self.update_state(state)
daemon.SendConnectResultsIfAvail()
@@ -199,8 +197,7 @@ class ConnectionStatus(object):
wired_ip = wired.GetWiredIP("")
wired_found = self.check_for_wired_connection(wired_ip)
if wired_found:
self.update_state(misc.WIRED, wired_ip=wired_ip)
return True
return self.update_state(misc.WIRED, wired_ip=wired_ip)
# Check for wireless
wifi_ip = wireless.GetWirelessIP("")
@@ -219,12 +216,10 @@ class ConnectionStatus(object):
if not daemon.GetGUIOpen():
print 'Killing wireless connection to switch to wired...'
wireless.DisconnectWireless()
daemon.AutoConnect(False, reply_handler=lambda:None,
error_handler=lambda:None)
self.update_state(misc.NOT_CONNECTED)
return True
self.update_state(misc.WIRELESS, wifi_ip=wifi_ip)
return True
daemon.AutoConnect(False, reply_handler=lambda *a:None,
error_handler=lambda *a:None)
return self.update_state(misc.NOT_CONNECTED)
return self.update_state(misc.WIRELESS, wifi_ip=wifi_ip)
state = misc.NOT_CONNECTED
if self.last_state == misc.WIRELESS:
@@ -232,8 +227,7 @@ class ConnectionStatus(object):
else:
from_wireless = False
self.auto_reconnect(from_wireless)
self.update_state(state)
return True
return self.update_state(state)
def _force_update_connection_status(self):
""" Run a connection status update on demand.
@@ -272,6 +266,7 @@ class ConnectionStatus(object):
else:
print 'ERROR: Invalid state!'
return True
daemon.SetConnectionStatus(state, info)
# Send a D-Bus signal announcing status has changed if necessary.
@@ -306,7 +301,7 @@ class ConnectionStatus(object):
# Some checks to keep reconnect retries from going crazy.
if (self.reconnect_tries > 3 and
(time.time() - self.last_reconnect_time) < 200):
(time.time() - self.last_reconnect_time) < 200):
print "Throttling autoreconnect"
return
@@ -323,7 +318,7 @@ class ConnectionStatus(object):
cur_net_id = wireless.GetCurrentNetworkID(self.iwconfig)
if from_wireless and cur_net_id > -1:
print 'Trying to reconnect to last used wireless ' + \
'network'
'network'
wireless.ConnectWireless(cur_net_id)
else:
daemon.AutoConnect(True, reply_handler=reply_handle,

View File

@@ -426,6 +426,29 @@ class ConnectThread(threading.Thread):
self.abort_connection(dhcp_status)
return
@abortable
def verify_association(self, iface):
""" Verify that our association the AP is valid.
Try to ping the gateway we have set to see if we're
really associated with it. This is only done if
we're using a static IP.
"""
if self.network.get('gateway'):
self.SetStatus('verifying_association')
print "Verifying AP association"
retcode = self.iface.VerifyAPAssociation(self.network['gateway'])
#TODO this should be in wnettools.py
if retcode:
print "Connection Failed: Failed to ping the access point!"
# Clean up before aborting.
iface.SetAddress('0.0.0.0')
iface.FlushRoutes()
if hasattr(iface, "StopWPA"):
iface.StopWPA()
self.abort_connection("association_failed")
@abortable
def set_dns_addresses(self, iface):
""" Set the DNS address(es).
@@ -838,6 +861,7 @@ class WirelessConnectThread(ConnectThread):
self.set_broadcast_address(wiface)
self.set_ip_address(wiface)
self.set_dns_addresses(wiface)
self.verify_association(wiface)
# Run post-connection script.
self.run_global_scripts_if_needed(wpath.postconnectscripts)

View File

@@ -153,6 +153,8 @@ language['dhcp_failed'] = _('Connection Failed: Unable to Get IP Address')
language['no_dhcp_offers'] = _('Connection Failed: No DHCP offers received.')
language['aborted'] = _('Connection Cancelled')
language['bad_pass'] = _('Connection Failed: Could not authenticate (bad password?)')
language['verifying_association'] = _("Verifying access point association...")
language['association_failed'] = _("Connection Failed: Could not contact the wireless access point.")
language['done'] = _('Done connecting...')
language['scanning'] = _('Scanning')
language['scanning_stand_by'] = _('Scanning networks... stand by...')

View File

@@ -585,6 +585,17 @@ class BaseInterface(object):
output = ifconfig
return misc.RunRegex(ip_pattern, output)
def VerifyAPAssociation(self, gateway):
""" Verify assocation with an access point.
Verifies that an access point can be contacted by
trying to ping it.
"""
cmd = "ping -q -w 3 -c 1 %s" % gateway
if self.verbose: print cmd
return misc.LaunchAndWait(cmd)
def IsUp(self, ifconfig=None):
""" Determines if the interface is up.