Enigma2-Network: update Wlan plugin to support new python-wifi.
authoracid-burn <acid-burn@opendreambox.org>
Sat, 24 Jul 2010 21:14:58 +0000 (23:14 +0200)
committeracid-burn <acid-burn@opendreambox.org>
Sat, 24 Jul 2010 21:14:58 +0000 (23:14 +0200)
some fixes and cleanups.
refs #558

lib/python/Components/About.py [changed mode: 0644->0755]
lib/python/Components/Network.py
lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py
lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py
lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py
lib/python/Screens/NetworkSetup.py

old mode 100644 (file)
new mode 100755 (executable)
index 8e332e3..6b322c9
@@ -1,5 +1,6 @@
 from Tools.Directories import resolveFilename, SCOPE_SYSETC
 from enigma import getEnigmaVersionString
 from Tools.Directories import resolveFilename, SCOPE_SYSETC
 from enigma import getEnigmaVersionString
+from os import popen
 
 class About:
        def __init__(self):
 
 class About:
        def __init__(self):
@@ -43,4 +44,14 @@ class About:
        def getEnigmaVersionString(self):
                return getEnigmaVersionString()
 
        def getEnigmaVersionString(self):
                return getEnigmaVersionString()
 
+       def getKernelVersionString(self):
+               try:
+                       result = popen("uname -r","r").read().strip("\n").split('-')
+                       kernel_version = result[0]
+                       return kernel_version
+               except:
+                       pass
+
+               return "unknown"
+
 about = About()
 about = About()
index e8a3d459cb7638a8b9276569c40bbf1408f4d5e0..e980cb8c2f0dcd5a68a840297f1f8c0c323edcc8 100755 (executable)
@@ -4,6 +4,7 @@ from socket import *
 from enigma import eConsoleAppContainer
 from Components.Console import Console
 from Components.PluginComponent import plugins
 from enigma import eConsoleAppContainer
 from Components.Console import Console
 from Components.PluginComponent import plugins
+from Components.About import about
 from Plugins.Plugin import PluginDescriptor
 
 class Network:
 from Plugins.Plugin import PluginDescriptor
 
 class Network:
@@ -349,8 +350,10 @@ class Network:
                                                return _("Zydas")+ " " + str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter.") 
                                        elif os_path.realpath(driverdir).endswith('rt73'):
                                                return _("Ralink")+ " " + str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter.") 
                                                return _("Zydas")+ " " + str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter.") 
                                        elif os_path.realpath(driverdir).endswith('rt73'):
                                                return _("Ralink")+ " " + str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter.") 
+                                       elif os_path.realpath(driverdir).endswith('rt73usb'):
+                                               return _("Ralink")+ " " + str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter.") 
                                        else:
                                        else:
-                                               return _("Unknown network adapter.")
+                                               return str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter.") 
                                else:
                                        return _("Unknown network adapter.")
 
                                else:
                                        return _("Unknown network adapter.")
 
@@ -606,24 +609,39 @@ class Network:
                                if callback is not None:
                                        callback(True)
 
                                if callback is not None:
                                        callback(True)
 
-       def detectWlanModule(self):
+       def detectWlanModule(self, iface = None):
                self.wlanmodule = None
                self.wlanmodule = None
-               rt73_dir = "/sys/bus/usb/drivers/rt73/"
-               zd1211b_dir = "/sys/bus/usb/drivers/zd1211b/"
-               madwifi_dir = "/sys/bus/pci/drivers/ath_pci/"
-               if os_path.exists(madwifi_dir):
-                       files = listdir(madwifi_dir)
-                       if len(files) >= 1:
-                               self.wlanmodule = 'madwifi'
-               if os_path.exists(rt73_dir):
-                       rtfiles = listdir(rt73_dir)
-                       if len(rtfiles) == 2 or len(rtfiles) == 5:
-                               self.wlanmodule = 'ralink'
-               if os_path.exists(zd1211b_dir):
-                       zdfiles = listdir(zd1211b_dir)
-                       if len(zdfiles) == 1 or len(zdfiles) == 5:
-                               self.wlanmodule = 'zydas'
-               return self.wlanmodule
+               classdir = "/sys/class/net/" + iface + "/device/"
+               driverdir = "/sys/class/net/" + iface + "/device/driver/"
+               if os_path.exists(classdir):
+                       classfiles = listdir(classdir)
+                       driver_found = False
+                       nl80211_found = False
+                       for x in classfiles:
+                               if x == 'driver':
+                                       driver_found = True
+                               if x.startswith('ieee80211:'):
+                                       nl80211_found = True
+
+                       if driver_found and nl80211_found:
+                               #print about.getKernelVersionString()
+                               self.wlanmodule = "nl80211"
+                       else:
+                               if driver_found and not nl80211_found:
+                                       driverfiles = listdir(driverdir)
+                                       if os_path.realpath(driverdir).endswith('ath_pci'):
+                                               if len(driverfiles) >= 1:
+                                                       self.wlanmodule = 'madwifi'
+                                       if os_path.realpath(driverdir).endswith('rt73'):
+                                               if len(driverfiles) == 2 or len(driverfiles) == 5:
+                                                       self.wlanmodule = 'ralink'                                      
+                                       if os_path.realpath(driverdir).endswith('zd1211b'):
+                                               if len(driverfiles) == 1 or len(driverfiles) == 5:
+                                                       self.wlanmodule = 'zydas'
+                       if self.wlanmodule is None:
+                               self.wlanmodule = "wext"
+                       print 'Using "%s" as wpa-supplicant driver' % (self.wlanmodule)
+                       return self.wlanmodule
        
        def calc_netmask(self,nmask):
                from struct import pack, unpack
        
        def calc_netmask(self,nmask):
                from struct import pack, unpack
index 6096ca8bcdf67923828b55769051edf6b51e5bfe..d7e83072d8d2ca7b2300ea29f7fa68b639fbeb7e 100755 (executable)
@@ -257,7 +257,7 @@ class NetworkWizard(WizardLanguage, Rc):
                                        text1 = _("Your Dreambox is now ready to use.\n\nYour internet connection is working now.\n\n")
                                        text2 = _('Accesspoint:') + "\t" + str(status[self.selectedInterface]["acesspoint"]) + "\n"
                                        text3 = _('SSID:') + "\t" + str(status[self.selectedInterface]["essid"]) + "\n"
                                        text1 = _("Your Dreambox is now ready to use.\n\nYour internet connection is working now.\n\n")
                                        text2 = _('Accesspoint:') + "\t" + str(status[self.selectedInterface]["acesspoint"]) + "\n"
                                        text3 = _('SSID:') + "\t" + str(status[self.selectedInterface]["essid"]) + "\n"
-                                       text4 = _('Link Quality:') + "\t" + str(status[self.selectedInterface]["quality"])+"%" + "\n"
+                                       text4 = _('Link Quality:') + "\t" + str(status[self.selectedInterface]["quality"])+ "\n"
                                        text5 = _('Signal Strength:') + "\t" + str(status[self.selectedInterface]["signal"]) + "\n"
                                        text6 = _('Bitrate:') + "\t" + str(status[self.selectedInterface]["bitrate"]) + "\n"
                                        text7 = _('Encryption:') + " " + str(status[self.selectedInterface]["encryption"]) + "\n"
                                        text5 = _('Signal Strength:') + "\t" + str(status[self.selectedInterface]["signal"]) + "\n"
                                        text6 = _('Bitrate:') + "\t" + str(status[self.selectedInterface]["bitrate"]) + "\n"
                                        text7 = _('Encryption:') + " " + str(status[self.selectedInterface]["encryption"]) + "\n"
@@ -421,3 +421,4 @@ class NetworkWizard(WizardLanguage, Rc):
 
        def ChoicesSelectionMoved(self):
                pass
 
        def ChoicesSelectionMoved(self):
                pass
+
index 1c1471cee25fd9fc7623abcb6c1a303a6b4d10ed..baefd435846599e84293c55edb3363270f228471 100755 (executable)
@@ -1,7 +1,3 @@
-#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
 
@@ -10,7 +6,8 @@ from string import maketrans, strip
 import sys
 import types
 from re import compile as re_compile, search as re_search
 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")
@@ -65,38 +62,42 @@ class Wlan:
                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 }
                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 }
-               #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 +105,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,12 +112,10 @@ 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
 
                                if signal is not None:
                                        data['signal'] = signal
 
@@ -130,7 +128,6 @@ class Wlan:
                                callback(True,self.wlaniface)
 
        def getAdapterAttribute(self, attribute):
                                callback(True,self.wlaniface)
 
        def getAdapterAttribute(self, attribute):
-               print "im getAdapterAttribute"
                if self.wlaniface.has_key(self.iface):
                        print "self.wlaniface.has_key",self.iface
                        if self.wlaniface[self.iface].has_key(attribute):
                if self.wlaniface.has_key(self.iface):
                        print "self.wlaniface.has_key",self.iface
                        if self.wlaniface[self.iface].has_key(attribute):
@@ -142,13 +139,17 @@ class Wlan:
 
        
        def getWirelessInterfaces(self):
 
        
        def getWirelessInterfaces(self):
-               iwifaces = None
-               try:
-                       iwifaces = getNICnames()
-               except:
-                       print "[Wlan.py] No Wireless Networkcards could be found"
-               
-               return iwifaces
+               device = re_compile('[a-z]{2,}[0-9]*:')
+               ifnames = []
+
+               fp = open('/proc/net/wireless', 'r')
+               for line in fp:
+                       try:
+                               # append matching pattern, without the trailing colon
+                               ifnames.append(device.search(line).group()[:-1])
+                       except AttributeError:
+                               pass
+               return ifnames
 
        
        def getNetworkList(self):
 
        
        def getNetworkList(self):
@@ -156,8 +157,8 @@ class Wlan:
                ifobj = Wireless(self.iface) # a Wireless NIC Object
                
                #Association mappings
                ifobj = Wireless(self.iface) # a Wireless NIC Object
                
                #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()
 
                try:
                        scanresults = ifobj.scan()
@@ -167,55 +168,47 @@ 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
 
                
@@ -226,12 +219,11 @@ 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]))),
@@ -326,7 +318,6 @@ 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
                                        if split[1] == "WPA" :
                                                mode = 'WPA'
                                        config.plugins.wlan.encryption.enabled.value = True
                                        if split[1] == "WPA" :
                                                mode = 'WPA'
@@ -354,12 +345,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
                                
@@ -436,24 +424,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 +461,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:
@@ -480,28 +473,30 @@ class Status:
                                        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 
                                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('/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
 
@@ -515,12 +510,10 @@ class Status:
                                        callback(True,self.wlaniface)
 
        def getAdapterAttribute(self, iface, attribute):
                                        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()
index a687714d1861153c223c701644c529e9c6e2e35a..28ee363edccf01ea13097e0095ec997246f95b36 100755 (executable)
@@ -1,4 +1,4 @@
-from enigma import eTimer
+from enigma import eTimer, eTPM
 from Screens.Screen import Screen
 from Components.ActionMap import ActionMap, NumberActionMap
 from Components.Pixmap import Pixmap,MultiPixmap
 from Screens.Screen import Screen
 from Components.ActionMap import ActionMap, NumberActionMap
 from Components.Pixmap import Pixmap,MultiPixmap
@@ -14,7 +14,9 @@ from Plugins.Plugin import PluginDescriptor
 from os import system, path as os_path, listdir
 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
 from Tools.LoadPixmap import LoadPixmap
 from os import system, path as os_path, listdir
 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
 from Tools.LoadPixmap import LoadPixmap
+from Tools.HardwareInfo import HardwareInfo
 from Wlan import Wlan, wpaSupplicant, iStatus
 from Wlan import Wlan, wpaSupplicant, iStatus
+import sha
 
 plugin_path = "/usr/lib/enigma2/python/Plugins/SystemPlugins/WirelessLan"
 
 
 plugin_path = "/usr/lib/enigma2/python/Plugins/SystemPlugins/WirelessLan"
 
@@ -122,7 +124,7 @@ class WlanStatus(Screen):
                                if status is not None:
                                        self["BSSID"].setText(status[self.iface]["acesspoint"])
                                        self["ESSID"].setText(status[self.iface]["essid"])
                                if status is not None:
                                        self["BSSID"].setText(status[self.iface]["acesspoint"])
                                        self["ESSID"].setText(status[self.iface]["essid"])
-                                       self["quality"].setText(status[self.iface]["quality"]+"%")
+                                       self["quality"].setText(status[self.iface]["quality"])
                                        self["signal"].setText(status[self.iface]["signal"])
                                        self["bitrate"].setText(status[self.iface]["bitrate"])
                                        self["enc"].setText(status[self.iface]["encryption"])
                                        self["signal"].setText(status[self.iface]["signal"])
                                        self["bitrate"].setText(status[self.iface]["bitrate"])
                                        self["enc"].setText(status[self.iface]["encryption"])
@@ -373,6 +375,45 @@ class WlanScan(Screen):
                return self.WlanList
 
 
                return self.WlanList
 
 
+def bin2long(s):
+       return reduce( lambda x,y:(x<<8L)+y, map(ord, s))
+
+def long2bin(l):
+       res = ""
+       for byte in range(128):
+               res += chr((l >> (1024 - (byte + 1) * 8)) & 0xff)
+       return res
+
+def rsa_pub1024(src, mod):
+       return long2bin(pow(bin2long(src), 65537, bin2long(mod)))
+       
+def decrypt_block(src, mod):
+       if len(src) != 128 and len(src) != 202:
+               return None
+       dest = rsa_pub1024(src[:128], mod)
+       hash = sha.new(dest[1:107])
+       if len(src) == 202:
+               hash.update(src[131:192])       
+       result = hash.digest()
+       if result == dest[107:127]:
+               return dest
+       return None
+
+def validate_cert(cert, key):
+       buf = decrypt_block(cert[8:], key) 
+       if buf is None:
+               return None
+       return buf[36:107] + cert[139:196]
+
+def read_random():
+       try:
+               fd = open("/dev/urandom", "r")
+               buf = fd.read(8)
+               fd.close()
+               return buf
+       except:
+               return None
+
 def WlanStatusScreenMain(session, iface):
        session.open(WlanStatus, iface)
 
 def WlanStatusScreenMain(session, iface):
        session.open(WlanStatus, iface)
 
@@ -387,8 +428,32 @@ def callFunction(iface):
 
 
 def configStrings(iface):
 
 
 def configStrings(iface):
-       driver = iNetwork.detectWlanModule()
-       print "Found WLAN-Driver:",driver
+       hardware_info = HardwareInfo()
+       if  hardware_info.device_name != "dm7025":
+               rootkey = ['\x9f', '|', '\xe4', 'G', '\xc9', '\xb4', '\xf4', '#', '&', '\xce', '\xb3', '\xfe', '\xda', '\xc9', 'U', '`', '\xd8', '\x8c', 's', 'o', '\x90', '\x9b', '\\', 'b', '\xc0', '\x89', '\xd1', '\x8c', '\x9e', 'J', 'T', '\xc5', 'X', '\xa1', '\xb8', '\x13', '5', 'E', '\x02', '\xc9', '\xb2', '\xe6', 't', '\x89', '\xde', '\xcd', '\x9d', '\x11', '\xdd', '\xc7', '\xf4', '\xe4', '\xe4', '\xbc', '\xdb', '\x9c', '\xea', '}', '\xad', '\xda', 't', 'r', '\x9b', '\xdc', '\xbc', '\x18', '3', '\xe7', '\xaf', '|', '\xae', '\x0c', '\xe3', '\xb5', '\x84', '\x8d', '\r', '\x8d', '\x9d', '2', '\xd0', '\xce', '\xd5', 'q', '\t', '\x84', 'c', '\xa8', ')', '\x99', '\xdc', '<', '"', 'x', '\xe8', '\x87', '\x8f', '\x02', ';', 'S', 'm', '\xd5', '\xf0', '\xa3', '_', '\xb7', 'T', '\t', '\xde', '\xa7', '\xf1', '\xc9', '\xae', '\x8a', '\xd7', '\xd2', '\xcf', '\xb2', '.', '\x13', '\xfb', '\xac', 'j', '\xdf', '\xb1', '\x1d', ':', '?']
+               etpm = eTPM()
+               l2cert = etpm.getCert(eTPM.TPMD_DT_LEVEL2_CERT)
+               if l2cert is None:
+                       return
+               l2key = validate_cert(l2cert, rootkey)
+               if l2key is None:
+                       return
+               l3cert = etpm.getCert(eTPM.TPMD_DT_LEVEL3_CERT)
+               if l3cert is None:
+                       print "better run the genuine dreambox plugin"
+                       return
+               l3key = validate_cert(l3cert, l2key)
+               if l3key is None:
+                       return
+               rnd = read_random()
+               if rnd is None:
+                       return
+               val = etpm.challenge(rnd)
+               result = decrypt_block(val, l3key)
+       if hardware_info.device_name == "dm7025" or result[80:88] == rnd:
+               driver = iNetwork.detectWlanModule(iface)
+       else:
+               driver = 'dreambox'
        if driver  in ('ralink', 'zydas'):
                return "        pre-up /usr/sbin/wpa_supplicant -i"+iface+" -c/etc/wpa_supplicant.conf -B -D"+driver+"\n        post-down wpa_cli terminate"
        else:
        if driver  in ('ralink', 'zydas'):
                return "        pre-up /usr/sbin/wpa_supplicant -i"+iface+" -c/etc/wpa_supplicant.conf -B -D"+driver+"\n        post-down wpa_cli terminate"
        else:
@@ -399,4 +464,3 @@ def configStrings(iface):
 
 def Plugins(**kwargs):
        return PluginDescriptor(name=_("Wireless LAN"), description=_("Connect to a Wireless Network"), where = PluginDescriptor.WHERE_NETWORKSETUP, fnc={"ifaceSupported": callFunction, "configStrings": configStrings, "WlanPluginEntry": lambda x: "Wireless Network Configuartion..."})
 
 def Plugins(**kwargs):
        return PluginDescriptor(name=_("Wireless LAN"), description=_("Connect to a Wireless Network"), where = PluginDescriptor.WHERE_NETWORKSETUP, fnc={"ifaceSupported": callFunction, "configStrings": configStrings, "WlanPluginEntry": lambda x: "Wireless Network Configuartion..."})
-       
\ No newline at end of file
index 2e33ac3b02d519644fbee8e820b774a404a972f9..de2fa99342377647d04d6dc60a7698800a36ccdc 100755 (executable)
@@ -745,14 +745,21 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                        if self.iface in iNetwork.wlan_interfaces:
                                try:
                                        from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
                        if self.iface in iNetwork.wlan_interfaces:
                                try:
                                        from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
-                                       from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
+                                       from pythonwifi.iwlibs import Wireless
                                except ImportError:
                                        self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
                                else:
                                        ifobj = Wireless(self.iface) # a Wireless NIC Object
                                except ImportError:
                                        self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
                                else:
                                        ifobj = Wireless(self.iface) # a Wireless NIC Object
-                                       self.wlanresponse = ifobj.getStatistics()
-                                       if self.wlanresponse[0] != 19: # Wlan Interface found.
-                                               self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
+                                       try:
+                                               self.wlanresponse = ifobj.getAPaddr()
+                                       except IOError:
+                                               self.wlanresponse = ifobj.getStatistics()
+                                       if self.wlanresponse:
+                                               if self.wlanresponse[0] not in (19,95): # 19 = 'No such device', 95 = 'Operation not supported'
+                                                       self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
+                                               else:
+                                                       # Display Wlan not available Message
+                                                       self.showErrorMessage()
                                        else:
                                                # Display Wlan not available Message
                                                self.showErrorMessage()
                                        else:
                                                # Display Wlan not available Message
                                                self.showErrorMessage()
@@ -765,28 +772,42 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                if self["menulist"].getCurrent()[1] == 'scanwlan':
                        try:
                                from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
                if self["menulist"].getCurrent()[1] == 'scanwlan':
                        try:
                                from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
-                               from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
+                               from pythonwifi.iwlibs import Wireless
                        except ImportError:
                                self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
                        else:
                                ifobj = Wireless(self.iface) # a Wireless NIC Object
                        except ImportError:
                                self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
                        else:
                                ifobj = Wireless(self.iface) # a Wireless NIC Object
-                               self.wlanresponse = ifobj.getStatistics()
-                               if self.wlanresponse[0] != 19:
-                                       self.session.openWithCallback(self.WlanScanClosed, WlanScan, self.iface)
+                               try:
+                                       self.wlanresponse = ifobj.getAPaddr()
+                               except IOError:
+                                       self.wlanresponse = ifobj.getStatistics()
+                               if self.wlanresponse:
+                                       if self.wlanresponse[0] not in (19,95): # 19 = 'No such device', 95 = 'Operation not supported'
+                                               self.session.openWithCallback(self.WlanScanClosed, WlanScan, self.iface)
+                                       else:
+                                               # Display Wlan not available Message
+                                               self.showErrorMessage()
                                else:
                                        # Display Wlan not available Message
                                        self.showErrorMessage()
                if self["menulist"].getCurrent()[1] == 'wlanstatus':
                        try:
                                from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
                                else:
                                        # Display Wlan not available Message
                                        self.showErrorMessage()
                if self["menulist"].getCurrent()[1] == 'wlanstatus':
                        try:
                                from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
-                               from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
+                               from pythonwifi.iwlibs import Wireless
                        except ImportError:
                                self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
                        else:   
                                ifobj = Wireless(self.iface) # a Wireless NIC Object
                        except ImportError:
                                self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
                        else:   
                                ifobj = Wireless(self.iface) # a Wireless NIC Object
-                               self.wlanresponse = ifobj.getStatistics()
-                               if self.wlanresponse[0] != 19:
-                                       self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
+                               try:
+                                       self.wlanresponse = ifobj.getAPaddr()
+                               except IOError:
+                                       self.wlanresponse = ifobj.getStatistics()
+                               if self.wlanresponse:
+                                       if self.wlanresponse[0] not in (19,95): # 19 = 'No such device', 95 = 'Operation not supported'
+                                               self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
+                                       else:
+                                               # Display Wlan not available Message
+                                               self.showErrorMessage()
                                else:
                                        # Display Wlan not available Message
                                        self.showErrorMessage()
                                else:
                                        # Display Wlan not available Message
                                        self.showErrorMessage()
@@ -898,14 +919,21 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                        if ret[0] == 'ok' and (self.iface in iNetwork.wlan_interfaces) and iNetwork.getAdapterAttribute(self.iface, "up") is True:
                                try:
                                        from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
                        if ret[0] == 'ok' and (self.iface in iNetwork.wlan_interfaces) and iNetwork.getAdapterAttribute(self.iface, "up") is True:
                                try:
                                        from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
-                                       from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
+                                       from pythonwifi.iwlibs import Wireless
                                except ImportError:
                                        self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
                                else:   
                                        ifobj = Wireless(self.iface) # a Wireless NIC Object
                                except ImportError:
                                        self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
                                else:   
                                        ifobj = Wireless(self.iface) # a Wireless NIC Object
-                                       self.wlanresponse = ifobj.getStatistics()
-                                       if self.wlanresponse[0] != 19:
-                                               self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
+                                       try:
+                                               self.wlanresponse = ifobj.getAPaddr()
+                                       except IOError:
+                                               self.wlanresponse = ifobj.getStatistics()
+                                       if self.wlanresponse:
+                                               if self.wlanresponse[0] not in (19,95): # 19 = 'No such device', 95 = 'Operation not supported'
+                                                       self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
+                                               else:
+                                                       # Display Wlan not available Message
+                                                       self.showErrorMessage()
                                        else:
                                                # Display Wlan not available Message
                                                self.showErrorMessage()
                                        else:
                                                # Display Wlan not available Message
                                                self.showErrorMessage()
@@ -916,7 +944,7 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
 
        def WlanStatusClosed(self, *ret):
                if ret is not None and len(ret):
 
        def WlanStatusClosed(self, *ret):
                if ret is not None and len(ret):
-                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
                        iStatus.stopWlanConsole()
                        self.updateStatusbar()
 
                        iStatus.stopWlanConsole()
                        self.updateStatusbar()
 
@@ -924,7 +952,7 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                if ret[0] is not None:
                        self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,ret[0],ret[1])
                else:
                if ret[0] is not None:
                        self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,ret[0],ret[1])
                else:
-                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
                        iStatus.stopWlanConsole()
                        self.updateStatusbar()
                        
                        iStatus.stopWlanConsole()
                        self.updateStatusbar()
                        
@@ -1335,7 +1363,7 @@ class NetworkAdapterTest(Screen):
        def getLinkState(self,iface):
                if iface in iNetwork.wlan_interfaces:
                        try:
        def getLinkState(self,iface):
                if iface in iNetwork.wlan_interfaces:
                        try:
-                               from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+                               from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
                        except:
                                        self["Network"].setForegroundColorNum(1)
                                        self["Network"].setText(_("disconnected"))
                        except:
                                        self["Network"].setForegroundColorNum(1)
                                        self["Network"].setText(_("disconnected"))
@@ -1417,7 +1445,7 @@ class NetworkAdapterTest(Screen):
                iNetwork.stopLinkStateConsole()
                iNetwork.stopDNSConsole()
                try:
                iNetwork.stopLinkStateConsole()
                iNetwork.stopDNSConsole()
                try:
-                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
                except ImportError:
                        pass
                else:
                except ImportError:
                        pass
                else: