SystemPlugins/WirelessLan: improve wireless device/module detection.
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / WirelessLan / Wlan.py
index 1c1471c..718adf9 100755 (executable)
@@ -1,16 +1,13 @@
-#from enigma import eListboxPythonMultiContent, eListbox, gFont, RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_HALIGN_CENTER
-#from Components.MultiContent import MultiContentEntryText
-#from Components.GUIComponent import GUIComponent
-#from Components.HTMLComponent import HTMLComponent
 from Components.config import config, ConfigYesNo, NoSave, ConfigSubsection, ConfigText, ConfigSelection, ConfigPassword
 from Components.Console import Console
 
 from Components.config import config, ConfigYesNo, NoSave, ConfigSubsection, ConfigText, ConfigSelection, ConfigPassword
 from Components.Console import Console
 
-from os import system
+from os import system, path as os_path
 from string import maketrans, strip
 import sys
 import types
 from re import compile as re_compile, search as re_search
 from string import maketrans, strip
 import sys
 import types
 from re import compile as re_compile, search as re_search
-from iwlibs import getNICnames, Wireless, Iwfreq
+from pythonwifi.iwlibs import getNICnames, Wireless, Iwfreq, getWNICnames
+from pythonwifi import flags as wififlags
 
 list = []
 list.append("WEP")
 
 list = []
 list.append("WEP")
@@ -49,54 +46,55 @@ class Wlan:
 
        def stopWlanConsole(self):
                if self.WlanConsole is not None:
 
        def stopWlanConsole(self):
                if self.WlanConsole is not None:
-                       print "killing self.WlanConsole"
+                       print "[Wlan] killing self.WlanConsole"
+                       self.WlanConsole.killAll()
                        self.WlanConsole = None
                        del self.WlanConsole
                        
        def getDataForInterface(self, callback = None):
                        self.WlanConsole = None
                        del self.WlanConsole
                        
        def getDataForInterface(self, callback = None):
-               #get ip out of ip addr, as avahi sometimes overrides it in ifconfig.
-               print "self.iface im getDataForInterface",self.iface
                if len(self.WlanConsole.appContainers) == 0:
                        self.WlanConsole = Console()
                        cmd = "iwconfig " + self.iface
                        self.WlanConsole.ePopen(cmd, self.iwconfigFinished, callback)
 
        def iwconfigFinished(self, result, retval, extra_args):
                if len(self.WlanConsole.appContainers) == 0:
                        self.WlanConsole = Console()
                        cmd = "iwconfig " + self.iface
                        self.WlanConsole.ePopen(cmd, self.iwconfigFinished, callback)
 
        def iwconfigFinished(self, result, retval, extra_args):
-               print "self.iface im iwconfigFinished",self.iface
                callback = extra_args
                data = { 'essid': False, 'frequency': False, 'acesspoint': False, 'bitrate': False, 'encryption': False, 'quality': False, 'signal': False }
                callback = extra_args
                data = { 'essid': False, 'frequency': False, 'acesspoint': False, 'bitrate': False, 'encryption': False, 'quality': False, 'signal': False }
-               #print "result im iwconfigFinished",result
                
                for line in result.splitlines():
                
                for line in result.splitlines():
-                       #print "line",line
                        line = line.strip()
                        if "ESSID" in line:
                                if "off/any" in line:
                                        ssid = _("No Connection")
                                else:
                        line = line.strip()
                        if "ESSID" in line:
                                if "off/any" in line:
                                        ssid = _("No Connection")
                                else:
-                                       tmpssid=(line[line.index('ESSID')+7:len(line)-1])
-                                       if tmpssid == '':
-                                               ssid = _("Hidden networkname")
-                                       elif tmpssid ==' ':
-                                               ssid = _("Hidden networkname")
+                                       if "Nickname" in line:
+                                               tmpssid=(line[line.index('ESSID')+7:line.index('"  Nickname')])
+                                               if tmpssid == '':
+                                                       ssid = _("Hidden networkname")
+                                               elif tmpssid ==' ':
+                                                       ssid = _("Hidden networkname")
+                                               else:
+                                                       ssid = tmpssid
                                        else:
                                        else:
-                                           ssid = tmpssid
-                               #print "SSID->",ssid
+                                               tmpssid=(line[line.index('ESSID')+7:len(line)-1])
+                                               if tmpssid == '':
+                                                       ssid = _("Hidden networkname")
+                                               elif tmpssid ==' ':
+                                                       ssid = _("Hidden networkname")
+                                               else:
+                                                       ssid = tmpssid                                          
                                if ssid is not None:
                                        data['essid'] = ssid
                        if 'Frequency' in line:
                                frequency = line[line.index('Frequency')+10 :line.index(' GHz')]
                                if ssid is not None:
                                        data['essid'] = ssid
                        if 'Frequency' in line:
                                frequency = line[line.index('Frequency')+10 :line.index(' GHz')]
-                               #print "Frequency",frequency   
                                if frequency is not None:
                                        data['frequency'] = frequency
                        if "Access Point" in line:
                                ap=line[line.index('Access Point')+14:len(line)-1]
                                if frequency is not None:
                                        data['frequency'] = frequency
                        if "Access Point" in line:
                                ap=line[line.index('Access Point')+14:len(line)-1]
-                               #print "AP",ap
                                if ap is not None:
                                        data['acesspoint'] = ap
                        if "Bit Rate" in line:
                                br = line[line.index('Bit Rate')+9 :line.index(' Mb/s')]
                                if ap is not None:
                                        data['acesspoint'] = ap
                        if "Bit Rate" in line:
                                br = line[line.index('Bit Rate')+9 :line.index(' Mb/s')]
-                               #print "Bitrate",br
                                if br is not None:
                                        data['bitrate'] = br
                        if 'Encryption key' in line:
                                if br is not None:
                                        data['bitrate'] = br
                        if 'Encryption key' in line:
@@ -104,7 +102,6 @@ class Wlan:
                                    enc = _("Disabled")
                                else:
                                    enc = line[line.index('Encryption key')+15 :line.index('   Security')]
                                    enc = _("Disabled")
                                else:
                                    enc = line[line.index('Encryption key')+15 :line.index('   Security')]
-                               #print "Encryption key",enc 
                                if enc is not None:
                                        data['encryption'] = _("Enabled")
                        if 'Quality' in line:
                                if enc is not None:
                                        data['encryption'] = _("Enabled")
                        if 'Quality' in line:
@@ -112,53 +109,39 @@ class Wlan:
                                        qual = line[line.index('Quality')+8:line.index('/100')]
                                else:
                                        qual = line[line.index('Quality')+8:line.index('Sig')]
                                        qual = line[line.index('Quality')+8:line.index('/100')]
                                else:
                                        qual = line[line.index('Quality')+8:line.index('Sig')]
-                               #print "Quality",qual
                                if qual is not None:
                                        data['quality'] = qual
                        if 'Signal level' in line:
                                if qual is not None:
                                        data['quality'] = qual
                        if 'Signal level' in line:
-                               signal = line[line.index('Signal level')+14 :line.index(' dBm')]
-                               #print "Signal level",signal            
+                               signal = line[line.index('Signal level')+13 :line.index(' dBm')]
                                if signal is not None:
                                        data['signal'] = signal
 
                self.wlaniface[self.iface] = data
                
                if len(self.WlanConsole.appContainers) == 0:
                                if signal is not None:
                                        data['signal'] = signal
 
                self.wlaniface[self.iface] = data
                
                if len(self.WlanConsole.appContainers) == 0:
-                       print "self.wlaniface after loading:", self.wlaniface
-                       self.WlanConsole = None
+                       print "[Wlan.py] self.wlaniface after loading:", self.wlaniface
                        if callback is not None:
                                callback(True,self.wlaniface)
 
        def getAdapterAttribute(self, attribute):
                        if callback is not None:
                                callback(True,self.wlaniface)
 
        def getAdapterAttribute(self, attribute):
-               print "im getAdapterAttribute"
                if self.wlaniface.has_key(self.iface):
                if self.wlaniface.has_key(self.iface):
-                       print "self.wlaniface.has_key",self.iface
+                       print "[Wlan.py] self.wlaniface.has_key",self.iface
                        if self.wlaniface[self.iface].has_key(attribute):
                                return self.wlaniface[self.iface][attribute]
                return None
                
        def asciify(self, str):
                return str.translate(self.asciitrans)
                        if self.wlaniface[self.iface].has_key(attribute):
                                return self.wlaniface[self.iface][attribute]
                return None
                
        def asciify(self, str):
                return str.translate(self.asciitrans)
-
        
        def getWirelessInterfaces(self):
        
        def getWirelessInterfaces(self):
-               iwifaces = None
-               try:
-                       iwifaces = getNICnames()
-               except:
-                       print "[Wlan.py] No Wireless Networkcards could be found"
-               
-               return iwifaces
+               return getWNICnames()
 
 
-       
        def getNetworkList(self):
                system("ifconfig "+self.iface+" up")
                ifobj = Wireless(self.iface) # a Wireless NIC Object
        def getNetworkList(self):
                system("ifconfig "+self.iface+" up")
                ifobj = Wireless(self.iface) # a Wireless NIC Object
-               
                #Association mappings
                #Association mappings
-               stats, quality, discard, missed_beacon = ifobj.getStatistics()
-               snr = quality.signallevel - quality.noiselevel
-
+               #stats, quality, discard, missed_beacon = ifobj.getStatistics()
+               #snr = quality.signallevel - quality.noiselevel
                try:
                        scanresults = ifobj.scan()
                except:
                try:
                        scanresults = ifobj.scan()
                except:
@@ -167,57 +150,48 @@ class Wlan:
                
                if scanresults is not None:
                        aps = {}
                
                if scanresults is not None:
                        aps = {}
+                       (num_channels, frequencies) = ifobj.getChannelInfo()
+                       index = 1
                        for result in scanresults:
                        for result in scanresults:
-                       
                                bssid = result.bssid
                                bssid = result.bssid
-               
-                               encryption = map(lambda x: hex(ord(x)), result.encode)
-               
-                               if encryption[-1] == "0x8":
+
+                               if result.encode.flags & wififlags.IW_ENCODE_DISABLED > 0:
+                                       encryption = False
+                               elif result.encode.flags & wififlags.IW_ENCODE_NOKEY > 0:
                                        encryption = True
                                else:
                                        encryption = True
                                else:
-                                       encryption = False
-               
+                                       encryption = None
+                               
+                               signal = str(result.quality.siglevel-0x100) + " dBm"
+                               quality = "%s/%s" % (result.quality.quality,ifobj.getQualityMax().quality)
+                               
                                extra = []
                                for element in result.custom:
                                        element = element.encode()
                                        extra.append( strip(self.asciify(element)) )
                                extra = []
                                for element in result.custom:
                                        element = element.encode()
                                        extra.append( strip(self.asciify(element)) )
-                               
-                               if result.quality.sl is 0 and len(extra) > 0:
-                                       begin = extra[0].find('SignalStrength=')+15
-                                                                       
-                                       done = False
-                                       end = begin+1
-                                       
-                                       while not done:
-                                               if extra[0][begin:end].isdigit():
-                                                       end += 1
-                                               else:
-                                                       done = True
-                                                       end -= 1
-                                       
-                                       signal = extra[0][begin:end]
-                                       #print "[Wlan.py] signal is:" + str(signal)
+                               for element in extra:
+                                       print element
+                                       if 'SignalStrength' in element:
+                                               signal = element[element.index('SignalStrength')+15:element.index(',L')]                                        
+                                       if 'LinkQuality' in element:
+                                               quality = element[element.index('LinkQuality')+12:len(element)]                         
 
 
-                               else:
-                                       signal = str(result.quality.sl)
-                               
                                aps[bssid] = {
                                        'active' : True,
                                        'bssid': result.bssid,
                                aps[bssid] = {
                                        'active' : True,
                                        'bssid': result.bssid,
-                                       'channel': result.frequency.getChannel(result.frequency.getFrequency()),
+                                       'channel': frequencies.index(ifobj._formatFrequency(result.frequency.getFrequency())) + 1,
                                        'encrypted': encryption,
                                        'essid': strip(self.asciify(result.essid)),
                                        'iface': self.iface,
                                        'encrypted': encryption,
                                        'essid': strip(self.asciify(result.essid)),
                                        'iface': self.iface,
-                                       'maxrate' : result.rate[-1],
-                                       'noise' : result.quality.getNoiselevel(),
-                                       'quality' : str(result.quality.quality),
-                                       'signal' : signal,
+                                       'maxrate' : ifobj._formatBitrate(result.rate[-1][-1]),
+                                       'noise' : '',#result.quality.nlevel-0x100,
+                                       'quality' : str(quality),
+                                       'signal' : str(signal),
                                        'custom' : extra,
                                }
                                        'custom' : extra,
                                }
-                               print aps[bssid]
+                               #print "GOT APS ENTRY:",aps[bssid]
+                               index = index + 1
                        return aps
                        return aps
-
                
        def getStatus(self):
                ifobj = Wireless(self.iface)
                
        def getStatus(self):
                ifobj = Wireless(self.iface)
@@ -226,38 +200,34 @@ class Wlan:
                        self.channel = str(fq.getChannel(str(ifobj.getFrequency()[0:-3])))
                except:
                        self.channel = 0
                        self.channel = str(fq.getChannel(str(ifobj.getFrequency()[0:-3])))
                except:
                        self.channel = 0
-               #print ifobj.getStatistics()
                status = {
                status = {
-                                 'BSSID': str(ifobj.getAPaddr()),
+                                 'BSSID': str(ifobj.getAPaddr()), #ifobj.getStatistics()
                                  'ESSID': str(ifobj.getEssid()),
                                  'ESSID': str(ifobj.getEssid()),
-                                 'quality': str(ifobj.getStatistics()[1].quality),
-                                 'signal': str(ifobj.getStatistics()[1].sl),
+                                 'quality': "%s/%s" % (ifobj.getStatistics()[1].quality,ifobj.getQualityMax().quality),
+                                 'signal': str(ifobj.getStatistics()[1].siglevel-0x100) + " dBm",
                                  'bitrate': str(ifobj.getBitrate()),
                                  'channel': str(self.channel),
                                  #'channel': str(fq.getChannel(str(ifobj.getFrequency()[0:-3]))),
                }
                                  'bitrate': str(ifobj.getBitrate()),
                                  'channel': str(self.channel),
                                  #'channel': str(fq.getChannel(str(ifobj.getFrequency()[0:-3]))),
                }
-               
                for (key, item) in status.items():
                        if item is "None" or item is "":
                                        status[key] = _("N/A")
                for (key, item) in status.items():
                        if item is "None" or item is "":
                                        status[key] = _("N/A")
-                               
                return status
 
 
 class wpaSupplicant:
                return status
 
 
 class wpaSupplicant:
-       def __init__(self):
+       def __init__(self, iface):
+               self.iface = iface
                pass
                pass
-       
                
        def writeConfig(self):  
                
        def writeConfig(self):  
-                       
                        essid = config.plugins.wlan.essid.value
                        hiddenessid = config.plugins.wlan.hiddenessid.value
                        encrypted = config.plugins.wlan.encryption.enabled.value
                        encryption = config.plugins.wlan.encryption.type.value
                        wepkeytype = config.plugins.wlan.encryption.wepkeytype.value
                        psk = config.plugins.wlan.encryption.psk.value
                        essid = config.plugins.wlan.essid.value
                        hiddenessid = config.plugins.wlan.hiddenessid.value
                        encrypted = config.plugins.wlan.encryption.enabled.value
                        encryption = config.plugins.wlan.encryption.type.value
                        wepkeytype = config.plugins.wlan.encryption.wepkeytype.value
                        psk = config.plugins.wlan.encryption.psk.value
-                       fp = file('/etc/wpa_supplicant.conf', 'w')
+                       fp = file('/etc/' + self.iface + '_wpa_supplicant.conf', 'w')
                        fp.write('#WPA Supplicant Configuration by enigma2\n')
                        fp.write('ctrl_interface=/var/run/wpa_supplicant\n')
                        fp.write('eapol_version=1\n')
                        fp.write('#WPA Supplicant Configuration by enigma2\n')
                        fp.write('ctrl_interface=/var/run/wpa_supplicant\n')
                        fp.write('eapol_version=1\n')
@@ -273,23 +243,22 @@ class wpaSupplicant:
                                fp.write('\tssid="'+essid+'"\n')
                        fp.write('\tscan_ssid=0\n')                     
                        if encrypted:
                                fp.write('\tssid="'+essid+'"\n')
                        fp.write('\tscan_ssid=0\n')                     
                        if encrypted:
-                               if encryption == 'WPA' or encryption == 'WPA2' or encryption == 'WPA/WPA2' :
+                               if encryption in ('WPA', 'WPA2', 'WPA/WPA2'):
                                        fp.write('\tkey_mgmt=WPA-PSK\n')
                                        fp.write('\tkey_mgmt=WPA-PSK\n')
-                                       
+               
                                        if encryption == 'WPA':
                                                fp.write('\tproto=WPA\n')
                                                fp.write('\tpairwise=TKIP\n')
                                                fp.write('\tgroup=TKIP\n')
                                        elif encryption == 'WPA2':
                                        if encryption == 'WPA':
                                                fp.write('\tproto=WPA\n')
                                                fp.write('\tpairwise=TKIP\n')
                                                fp.write('\tgroup=TKIP\n')
                                        elif encryption == 'WPA2':
+                                               fp.write('\tproto=RSN\n')
+                                               fp.write('\tpairwise=CCMP\n')
+                                               fp.write('\tgroup=CCMP\n')
+                                       else:
                                                fp.write('\tproto=WPA RSN\n')
                                                fp.write('\tpairwise=CCMP TKIP\n')
                                                fp.write('\tproto=WPA RSN\n')
                                                fp.write('\tpairwise=CCMP TKIP\n')
-                                               fp.write('\tgroup=CCMP TKIP\n')                                         
-                                       else:
-                                               fp.write('\tproto=WPA WPA2\n')
-                                               fp.write('\tpairwise=CCMP\n')
-                                               fp.write('\tgroup=TKIP\n')                                      
+                                               fp.write('\tgroup=CCMP TKIP\n')
                                        fp.write('\tpsk="'+psk+'"\n')
                                        fp.write('\tpsk="'+psk+'"\n')
-                                               
                                elif encryption == 'WEP':
                                        fp.write('\tkey_mgmt=NONE\n')
                                        if wepkeytype == 'ASCII':
                                elif encryption == 'WEP':
                                        fp.write('\tkey_mgmt=NONE\n')
                                        if wepkeytype == 'ASCII':
@@ -301,12 +270,16 @@ class wpaSupplicant:
                        fp.write('}')
                        fp.write('\n')
                        fp.close()
                        fp.write('}')
                        fp.write('\n')
                        fp.close()
-                       system("cat /etc/wpa_supplicant.conf")
+                       system('cat /etc/' + self.iface + '_wpa_supplicant.conf')
                
        def loadConfig(self):
                
        def loadConfig(self):
+               configfile = '/etc/wpa_supplicant.conf'
+               if os_path.isfile('/etc/' + self.iface + '_wpa_supplicant.conf'):
+                       configfile = '/etc/' + self.iface + '_wpa_supplicant.conf'
+               print "[wpaSupplicant] using configfile:",configfile
                try:
                        #parse the wpasupplicant configfile
                try:
                        #parse the wpasupplicant configfile
-                       fp = file('/etc/wpa_supplicant.conf', 'r')
+                       fp = file(configfile, 'r')
                        supplicant = fp.readlines()
                        fp.close()
                        ap_scan = False
                        supplicant = fp.readlines()
                        fp.close()
                        ap_scan = False
@@ -326,25 +299,16 @@ class wpaSupplicant:
                                        essid = split[1][1:-1]
                                        
                                elif split[0] == 'proto':
                                        essid = split[1][1:-1]
                                        
                                elif split[0] == 'proto':
-                                       print "split[1]",split[1]
                                        config.plugins.wlan.encryption.enabled.value = True
                                        config.plugins.wlan.encryption.enabled.value = True
-                                       if split[1] == "WPA" :
+                                       if split[1] == 'WPA' :
                                                mode = 'WPA'
                                                mode = 'WPA'
-                                       if split[1] == "WPA WPA2" :
-                                               mode = 'WPA/WPA2'
-                                       if split[1] == "WPA RSN" :
+                                       if split[1] == 'RSN':
                                                mode = 'WPA2'
                                                mode = 'WPA2'
+                                       if split[1] in ('WPA RSN', 'WPA WPA2'):
+                                               mode = 'WPA/WPA2'
                                        config.plugins.wlan.encryption.type.value = mode
                                        print "[Wlan.py] Got Encryption: "+mode
                                        
                                        config.plugins.wlan.encryption.type.value = mode
                                        print "[Wlan.py] Got Encryption: "+mode
                                        
-                               #currently unused !
-                               #elif split[0] == 'key_mgmt':
-                               #       print "split[1]",split[1]
-                               #       if split[1] == "WPA-PSK" :
-                               #               config.plugins.wlan.encryption.enabled.value = True
-                               #               config.plugins.wlan.encryption.type.value = "WPA/WPA2"
-                               #       print "[Wlan.py] Got Encryption: "+ config.plugins.wlan.encryption.type.value
-                                       
                                elif split[0] == 'wep_key0':
                                        config.plugins.wlan.encryption.enabled.value = True
                                        config.plugins.wlan.encryption.type.value = 'WEP'
                                elif split[0] == 'wep_key0':
                                        config.plugins.wlan.encryption.enabled.value = True
                                        config.plugins.wlan.encryption.type.value = 'WEP'
@@ -354,12 +318,9 @@ class wpaSupplicant:
                                        else:
                                                config.plugins.wlan.encryption.wepkeytype.value = 'HEX'
                                                config.plugins.wlan.encryption.psk.value = split[1]                                             
                                        else:
                                                config.plugins.wlan.encryption.wepkeytype.value = 'HEX'
                                                config.plugins.wlan.encryption.psk.value = split[1]                                             
-                                       print "[Wlan.py] Got Encryption: WEP - keytype is: "+config.plugins.wlan.encryption.wepkeytype.value
-                                       print "[Wlan.py] Got Encryption: WEP - key0 is: "+config.plugins.wlan.encryption.psk.value
                                        
                                elif split[0] == 'psk':
                                        config.plugins.wlan.encryption.psk.value = split[1][1:-1]
                                        
                                elif split[0] == 'psk':
                                        config.plugins.wlan.encryption.psk.value = split[1][1:-1]
-                                       print "[Wlan.py] Got PSK: "+split[1][1:-1]
                                else:
                                        pass
                                
                                else:
                                        pass
                                
@@ -392,9 +353,8 @@ class wpaSupplicant:
                                                wsconfig['encryption_wepkeytype'] = "ASCII"
                                        if key == 'encryption':
                                                wsconfig['key'] = "mysecurewlan"
                                                wsconfig['encryption_wepkeytype'] = "ASCII"
                                        if key == 'encryption':
                                                wsconfig['key'] = "mysecurewlan"
-
                except:
                except:
-                       print "[Wlan.py] Error parsing /etc/wpa_supplicant.conf"
+                       print "[Wlan.py] Error parsing ",configfile
                        wsconfig = {
                                        'hiddenessid': "home",
                                        'ssid': "home",
                        wsconfig = {
                                        'hiddenessid': "home",
                                        'ssid': "home",
@@ -406,10 +366,6 @@ class wpaSupplicant:
                print "[Wlan.py] WS-CONFIG-->",wsconfig
                return wsconfig
 
                print "[Wlan.py] WS-CONFIG-->",wsconfig
                return wsconfig
 
-       
-       def restart(self, iface):
-               system("start-stop-daemon -K -x /usr/sbin/wpa_supplicant")
-               system("start-stop-daemon -S -x /usr/sbin/wpa_supplicant -- -B -i"+iface+" -c/etc/wpa_supplicant.conf")
 
 class Status:
        def __init__(self):
 
 class Status:
        def __init__(self):
@@ -419,7 +375,8 @@ class Status:
 
        def stopWlanConsole(self):
                if self.WlanConsole is not None:
 
        def stopWlanConsole(self):
                if self.WlanConsole is not None:
-                       print "killing self.WlanConsole"
+                       print "[iStatus] killing self.WlanConsole"
+                       self.WlanConsole.killAll()
                        self.WlanConsole = None
                        
        def getDataForInterface(self, iface, callback = None):
                        self.WlanConsole = None
                        
        def getDataForInterface(self, iface, callback = None):
@@ -436,24 +393,30 @@ class Status:
                                if "off/any" in line:
                                        ssid = _("No Connection")
                                else:
                                if "off/any" in line:
                                        ssid = _("No Connection")
                                else:
-                                       tmpssid=(line[line.index('ESSID')+7:len(line)-1])
-                                       if tmpssid == '':
-                                               ssid = _("Hidden networkname")
-                                       elif tmpssid ==' ':
-                                               ssid = _("Hidden networkname")
+                                       if "Nickname" in line:
+                                               tmpssid=(line[line.index('ESSID')+7:line.index('"  Nickname')])
+                                               if tmpssid == '':
+                                                       ssid = _("Hidden networkname")
+                                               elif tmpssid ==' ':
+                                                       ssid = _("Hidden networkname")
+                                               else:
+                                                       ssid = tmpssid
                                        else:
                                        else:
-                                           ssid = tmpssid
-                               #print "SSID->",ssid
+                                               tmpssid=(line[line.index('ESSID')+7:len(line)-1])
+                                               if tmpssid == '':
+                                                       ssid = _("Hidden networkname")
+                                               elif tmpssid ==' ':
+                                                       ssid = _("Hidden networkname")
+                                               else:
+                                                       ssid = tmpssid                                          
                                if ssid is not None:
                                        data['essid'] = ssid
                        if 'Frequency' in line:
                                frequency = line[line.index('Frequency')+10 :line.index(' GHz')]
                                if ssid is not None:
                                        data['essid'] = ssid
                        if 'Frequency' in line:
                                frequency = line[line.index('Frequency')+10 :line.index(' GHz')]
-                               #print "Frequency",frequency   
                                if frequency is not None:
                                        data['frequency'] = frequency
                        if "Access Point" in line:
                                ap=line[line.index('Access Point')+14:len(line)]
                                if frequency is not None:
                                        data['frequency'] = frequency
                        if "Access Point" in line:
                                ap=line[line.index('Access Point')+14:len(line)]
-                               #print "AP",ap
                                if ap is not None:
                                        data['acesspoint'] = ap
                                        if ap == "Not-Associated":
                                if ap is not None:
                                        data['acesspoint'] = ap
                                        if ap == "Not-Associated":
@@ -467,7 +430,6 @@ class Status:
                                                br += " Mb/s"
                                else:
                                        br = line[line.index('Bit Rate')+9 :line.index(' Mb/s')] + " Mb/s"
                                                br += " Mb/s"
                                else:
                                        br = line[line.index('Bit Rate')+9 :line.index(' Mb/s')] + " Mb/s"
-                               #print "Bitrate",br
                                if br is not None:
                                        data['bitrate'] = br
                        if 'Encryption key' in line:
                                if br is not None:
                                        data['bitrate'] = br
                        if 'Encryption key' in line:
@@ -476,32 +438,37 @@ class Status:
                                                enc = _("Unsupported")
                                        else:
                                                enc = _("Disabled")
                                                enc = _("Unsupported")
                                        else:
                                                enc = _("Disabled")
-                               else:
+                               elif "Security" in line:
                                        enc = line[line.index('Encryption key')+15 :line.index('   Security')]
                                        if enc is not None:
                                                enc = _("Enabled")
                                        enc = line[line.index('Encryption key')+15 :line.index('   Security')]
                                        if enc is not None:
                                                enc = _("Enabled")
-                               #print "Encryption key",enc 
+                               else:
+                                       enc = line[line.index('Encryption key')+15 :len(line)]
+                                       if enc is not None:
+                                               enc = _("Enabled")                                      
                                if enc is not None:
                                        data['encryption'] = enc
                        if 'Quality' in line:
                                if "/100" in line:
                                if enc is not None:
                                        data['encryption'] = enc
                        if 'Quality' in line:
                                if "/100" in line:
-                                       qual = line[line.index('Quality')+8:line.index('/100')]
+                                       qual = line[line.index('Quality')+8:line.index('  Signal')]
                                else:
                                        qual = line[line.index('Quality')+8:line.index('Sig')]
                                else:
                                        qual = line[line.index('Quality')+8:line.index('Sig')]
-                               #print "Quality",qual
                                if qual is not None:
                                        data['quality'] = qual
                        if 'Signal level' in line:
                                if "dBm" in line:
                                if qual is not None:
                                        data['quality'] = qual
                        if 'Signal level' in line:
                                if "dBm" in line:
-                                       signal = line[line.index('Signal level')+14 :line.index(' dBm')]
+                                       signal = line[line.index('Signal level')+13 :line.index(' dBm')]
                                        signal += " dBm"
                                elif "/100" in line:
                                        signal += " dBm"
                                elif "/100" in line:
-                                       signal = line[line.index('Signal level')+13:line.index('/100  Noise')]
-                                       signal += "%"
+                                       if "Noise" in line:
+                                               signal = line[line.index('Signal level')+13:line.index('  Noise')]
+                                       else:
+                                               signal = line[line.index('Signal level')+13:len(line)]
                                else:
                                else:
-                                       signal = line[line.index('Signal level')+13:line.index('  Noise')]
-                                       signal += "%"
-                               #print "Signal level",signal            
+                                       if "Noise" in line:
+                                               signal = line[line.index('Signal level')+13:line.index('  Noise')]
+                                       else:
+                                               signal = line[line.index('Signal level')+13:len(line)]                                          
                                if signal is not None:
                                        data['signal'] = signal
 
                                if signal is not None:
                                        data['signal'] = signal
 
@@ -510,17 +477,15 @@ class Status:
                
                if self.WlanConsole is not None:
                        if len(self.WlanConsole.appContainers) == 0:
                
                if self.WlanConsole is not None:
                        if len(self.WlanConsole.appContainers) == 0:
-                               print "self.wlaniface after loading:", self.wlaniface
+                               print "[Wlan.py] self.wlaniface after loading:", self.wlaniface
                                if callback is not None:
                                        callback(True,self.wlaniface)
 
        def getAdapterAttribute(self, iface, attribute):
                                if callback is not None:
                                        callback(True,self.wlaniface)
 
        def getAdapterAttribute(self, iface, attribute):
-               print "im getAdapterAttribute"
                self.iface = iface
                if self.wlaniface.has_key(self.iface):
                self.iface = iface
                if self.wlaniface.has_key(self.iface):
-                       print "self.wlaniface.has_key",self.iface
                        if self.wlaniface[self.iface].has_key(attribute):
                                return self.wlaniface[self.iface][attribute]
                return None
        
                        if self.wlaniface[self.iface].has_key(attribute):
                                return self.wlaniface[self.iface][attribute]
                return None
        
-iStatus = Status()
\ No newline at end of file
+iStatus = Status()