1
0
mirror of https://github.com/gryf/wicd.git synced 2026-01-08 06:44:20 +01:00

Fixed bug in signal strength display for ralink cards

Altered the way ralink network info gets handled during the connection process
This commit is contained in:
imdano
2007-09-19 09:56:17 +00:00
parent 64e5c27ba2
commit 6f0faa1ac2

View File

@@ -39,10 +39,10 @@ import wpath
essid_pattern = re.compile('.*ESSID:"(.*?)"\n', re.DOTALL | re.I | re.M | re.S) essid_pattern = re.compile('.*ESSID:"(.*?)"\n', re.DOTALL | re.I | re.M | re.S)
ap_mac_pattern = re.compile('.*Address: (.*?)\n',re.DOTALL | re.I | re.M | re.S) ap_mac_pattern = re.compile('.*Address: (.*?)\n',re.DOTALL | re.I | re.M | re.S)
channel_pattern = re.compile('.*Channel:? ?(\d\d?)',re.DOTALL | re.I | re.M | re.S) channel_pattern = re.compile('.*Channel:? ?(\d\d?)',re.DOTALL | re.I | re.M | re.S)
# These next two look a lot a like, altstrength is for Signal level = xx/100,
# which is just an alternate way of displaying link quality,signaldbm is
# for displaying actualy signal strength (-xx dBm).
strength_pattern = re.compile('.*Quality:?=? ?(\d\d*)',re.DOTALL | re.I | re.M | re.S) strength_pattern = re.compile('.*Quality:?=? ?(\d\d*)',re.DOTALL | re.I | re.M | re.S)
# These next two look a lot a like, altstrength is for Signal level = xx/100,
# which is just an alternate way of displaying link quality, signaldbm is
# for displaying actualy signal strength (-xx dBm).
altstrength_pattern = re.compile('.*Signal level:?=? ?(\d\d*)',re.DOTALL | re.I | re.M | re.S) altstrength_pattern = re.compile('.*Signal level:?=? ?(\d\d*)',re.DOTALL | re.I | re.M | re.S)
signaldbm_pattern = re.compile('.*Signal level:?=? ?(-\d\d*)',re.DOTALL | re.I | re.M | re.S) signaldbm_pattern = re.compile('.*Signal level:?=? ?(-\d\d*)',re.DOTALL | re.I | re.M | re.S)
mode_pattern = re.compile('.*Mode:(.*?)\n',re.DOTALL | re.I | re.M | re.S) mode_pattern = re.compile('.*Mode:(.*?)\n',re.DOTALL | re.I | re.M | re.S)
@@ -263,13 +263,20 @@ class WirelessInterface(Interface):
# this way we can look at only one network at a time # this way we can look at only one network at a time
networks = results.split( ' Cell ' ) networks = results.split( ' Cell ' )
# Get available network info from iwpriv get_site_survey
# if we're using a ralink card (needed to get encryption info)
if self.wpa_driver == 'ralink legacy':
ralink_info = self._GetRalinkScanInfo()
else:
ralink_info = None
# An array for the access points # An array for the access points
access_points = [] access_points = []
for cell in networks: for cell in networks:
# Only use sections where there is an ESSID. # Only use sections where there is an ESSID.
if cell.count('ESSID:') > 0: if cell.count('ESSID:') > 0:
# Add this network to the list of networks # Add this network to the list of networks
access_points.append(self._ParseAccessPoint(cell)) access_points.append(self._ParseAccessPoint(cell, ralink_info))
return access_points return access_points
@@ -305,14 +312,29 @@ class WirelessInterface(Interface):
print 'Couldn\'t determine channel number for current network - ' + freq print 'Couldn\'t determine channel number for current network - ' + freq
return None return None
def _GetRalinkInfo(self):
""" Get a network info list used for ralink drivers
def _ParseAccessPoint(self, cell): Calls iwpriv <wireless interface> get_site_survey, which
on some ralink cards will return encryption and signal
strength info for wireless networks in the area.
"""
iwpriv = misc.Run('iwpriv ' + self.iface + ' get_site_survey')
lines = iwpriv.splitlines()
lines = lines[2:]
return lines
def _ParseAccessPoint(self, cell, ralink_info):
""" Parse a single cell from the output of iwlist. """ Parse a single cell from the output of iwlist.
Keyword arguments: Keyword arguments:
cell -- string containing the cell information cell -- string containing the cell information
ralink_info -- string contating network information needed
for ralink cards.
Returns: Returns:
A dictionary containing the cell networks properties. A dictionary containing the cell networks properties.
""" """
@@ -321,6 +343,7 @@ class WirelessInterface(Interface):
# ESSID - Switch '<hidden>' to 'Hidden' to remove # ESSID - Switch '<hidden>' to 'Hidden' to remove
# brackets that can mix up formatting. # brackets that can mix up formatting.
ap['essid'] = misc.RunRegex(essid_pattern, cell) ap['essid'] = misc.RunRegex(essid_pattern, cell)
ap['essid'] = ap['essid'].encode('utf-8')
if ap['essid'] == '<hidden>': if ap['essid'] == '<hidden>':
ap['essid'] = 'Hidden' ap['essid'] = 'Hidden'
ap['hidden'] = True ap['hidden'] = True
@@ -340,69 +363,83 @@ class WirelessInterface(Interface):
# Mode # Mode
ap['mode'] = misc.RunRegex(mode_pattern, cell) ap['mode'] = misc.RunRegex(mode_pattern, cell)
# Encryption - Default to WEP # Break off here if we're using a ralink card
if misc.RunRegex(wep_pattern, cell) == 'on': if self.wpa_driver == 'ralink legacy':
if self.wpa_driver != 'ralink legacy': ap = self._ParseRalinkAccessPoint(ap, ralink_info, cell)
ap['encryption'] = True elif misc.RunRegex(wep_pattern, cell) == 'on':
ap['encryption_method'] = 'WEP' # Encryption - Default to WEP
ap['encryption'] = True
ap['encryption_method'] = 'WEP'
if misc.RunRegex(wpa1_pattern,cell) == 'WPA Version 1': if misc.RunRegex(wpa1_pattern,cell) == 'WPA Version 1':
ap['encryption_method'] = 'WPA' ap['encryption_method'] = 'WPA'
if misc.RunRegex(altwpa_pattern,cell) == 'wpa_ie': if misc.RunRegex(altwpa_pattern,cell) == 'wpa_ie':
ap['encryption_method'] = 'WPA' ap['encryption_method'] = 'WPA'
if misc.RunRegex(wpa2_pattern,cell) == 'WPA2': if misc.RunRegex(wpa2_pattern,cell) == 'WPA2':
ap['encryption_method'] = 'WPA2' ap['encryption_method'] = 'WPA2'
# Support for ralink legacy drivers (maybe only serialmonkey enhanced),
# may not work w/ hidden networks
else:
iwpriv = misc.Run('iwpriv ' + self.iface + ' get_site_survey')
lines = iwpriv.splitlines()
lines = lines[2:]
for x in lines: # Iterate through all networks found
info = x.split()
if len(info) < 5 or info == None or info == '': # Make sure we read in a valid entry
break;
if info[2] == ap['essid']:
ap['encryption'] = True
if info[5] == 'WEP' or (
(info[5] == 'OPEN' or info[5] == 'SHARED') and
info[4] == 'WEP'):
ap['encryption_method'] = 'WEP'
elif info[5] == 'WPA-PSK':
ap['encryption_method'] = 'WPA'
elif info[5] == 'WPA2-PSK':
ap['encryption_method'] = 'WPA2'
else:
print 'Unknown AuthMode, can\'t assign encryption_method!!'
ap['encryption_method'] = 'Unknown'
# Set signal strength here (in dBm, not %),
# ralink drivers don't return link quality
ap['strength'] = info[1]
else: else:
ap['encryption'] = False ap['encryption'] = False
# Link Quality # Link Quality
# Set strength to -1 if the quality is not found # Set strength to -1 if the quality is not found
if misc.RunRegex(strength_pattern,cell): if misc.RunRegex(strength_pattern,cell):
ap['quality'] = misc.RunRegex(strength_pattern,cell) ap['quality'] = misc.RunRegex(strength_pattern,cell)
elif misc.RunRegex(altstrength_pattern,cell): elif misc.RunRegex(altstrength_pattern,cell):
ap['quality'] = misc.RunRegex(altstrength_pattern,cell) ap['quality'] = misc.RunRegex(altstrength_pattern,cell)
else: else:
ap['quality'] = -1 ap['quality'] = -1
# Signal Strength (only used if user doesn't want link # Signal Strength (only used if user doesn't want link
# quality displayed or it isn't found) # quality displayed or it isn't found)
if misc.RunRegex(signaldbm_pattern, cell): if misc.RunRegex(signaldbm_pattern, cell):
ap['strength'] = misc.RunRegex(signaldbm_pattern, cell) ap['strength'] = misc.RunRegex(signaldbm_pattern, cell)
else: elif self.wpa_driver != 'ralink legacy': # This is already set for ralink
ap['strength'] = -1 ap['strength'] = -1
return ap return ap
def _ParseRalinkAccessPoint(self, ap, ralink_info, cell):
""" Parse encryption and signal strength info for ralink cards
Keyword arguments:
ap -- array containing info about the current access point
ralink_info -- string containing available network info
cell -- string containing cell information
Returns:
Updated array containing info about the current access point
"""
lines = ralink_info
for x in lines: # Iterate through all networks found
info = x.split()
# Make sure we read in a valid entry
if len(info) < 5 or info == None or info == '':
break
if info[2] == ap['essid']:
if misc.RunRegex(wep_pattern, cell) == 'on':
ap['encryption'] = True
if info[5] == 'WEP' or (
(info[5] == 'OPEN' or info[5] == 'SHARED') and
info[4] == 'WEP'):
ap['encryption_method'] = 'WEP'
elif info[5] == 'WPA-PSK':
ap['encryption_method'] = 'WPA'
elif info[5] == 'WPA2-PSK':
ap['encryption_method'] = 'WPA2'
else:
print 'Unknown AuthMode, can\'t assign encryption_method!!'
ap['encryption_method'] = 'Unknown'
else:
ap['encryption'] = False
# Set signal strength here (in dBm, not %),
# ralink drivers don't return link quality
ap['strength'] = info[1]
return ap
def SetMode(self, mode): def SetMode(self, mode):
""" Set the mode of the wireless interface. """ Set the mode of the wireless interface.