X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/ff483cd208f38b22aa9aeebba228bd361a3caf22..453af6ce0630079409e4245c6f7c74a117ee3de2:/lib/python/Components/Network.py diff --git a/lib/python/Components/Network.py b/lib/python/Components/Network.py old mode 100644 new mode 100755 index 79ec1ed6..e980cb8c --- a/lib/python/Components/Network.py +++ b/lib/python/Components/Network.py @@ -1,18 +1,48 @@ from os import system, popen, path as os_path, listdir -from re import compile as re_compile +from re import compile as re_compile, search as re_search from socket import * 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: def __init__(self): self.ifaces = {} self.configuredInterfaces = [] + self.configuredNetworkAdapters = [] + self.NetworkState = 0 + self.DnsState = 0 self.nameservers = [] - self.getInterfaces() - self.ethtool_bin = "/usr/sbin/ethtool" + self.ethtool_bin = "ethtool" self.container = eConsoleAppContainer() + self.Console = Console() + self.LinkConsole = Console() + self.restartConsole = Console() + self.deactivateConsole = Console() + self.deactivateInterfaceConsole = Console() + self.activateConsole = Console() + self.resetNetworkConsole = Console() + self.DnsConsole = Console() + self.PingConsole = Console() + self.config_ready = None + self.friendlyNames = {} + self.lan_interfaces = [] + self.wlan_interfaces = [] + self.getInterfaces() + + def onRemoteRootFS(self): + fp = file('/proc/mounts', 'r') + mounts = fp.readlines() + fp.close() + for line in mounts: + parts = line.strip().split(' ') + if parts[1] == '/' and (parts[2] == 'nfs' or parts[2] == 'smbfs'): + return True + return False - def getInterfaces(self): + def getInterfaces(self, callback = None): devicesPattern = re_compile('[a-z]+[0-9]+') self.configuredInterfaces = [] fp = file('/proc/net/dev', 'r') @@ -21,17 +51,12 @@ class Network: for line in result: try: device = devicesPattern.search(line).group() - if device == 'wifi0': + if device in ('wifi0', 'wmaster0'): continue - self.ifaces[device] = self.getDataForInterface(device) - # Show only UP Interfaces in E2 - #if self.getAdapterAttribute(device, 'up') is False: - # del self.ifaces[device] + self.getDataForInterface(device, callback) except AttributeError: pass - #print "self.ifaces:", self.ifaces - self.loadNetworkConfig() #self.writeNetworkConfig() #print ord(' ') #for line in result: @@ -54,54 +79,76 @@ class Network: ip.append(int(x)) return ip - def getDataForInterface(self, iface): - #ipRegexp = '[0-9]{1,2,3}\.[0-9]{1,2,3}\.[0-9]{1,2,3}\.[0-9]{1,2,3}' - ipRegexp = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' - ipLinePattern = re_compile('inet addr:' + ipRegexp) - netmaskLinePattern = re_compile('Mask:' + ipRegexp) - bcastLinePattern = re_compile('Bcast:' + ipRegexp) - ipPattern = re_compile(ipRegexp) - upPattern = re_compile('UP ') - macPattern = re_compile('[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}') + def getDataForInterface(self, iface,callback): + #get ip out of ip addr, as avahi sometimes overrides it in ifconfig. + if not self.Console: + self.Console = Console() + cmd = "ip -o addr" + self.Console.ePopen(cmd, self.IPaddrFinished, [iface,callback]) - fp = popen("ifconfig " + iface) - result = fp.readlines() - fp.close() + def IPaddrFinished(self, result, retval, extra_args): + (iface, callback ) = extra_args data = { 'up': False, 'dhcp': False, 'preup' : False, 'postdown' : False } - for line in result: - ip = self.regExpMatch(ipPattern, self.regExpMatch(ipLinePattern, line)) - netmask = self.regExpMatch(ipPattern, self.regExpMatch(netmaskLinePattern, line)) - bcast = self.regExpMatch(ipPattern, self.regExpMatch(bcastLinePattern, line)) - up = self.regExpMatch(upPattern, line) - mac = self.regExpMatch(macPattern, line) - if ip is not None: - data['ip'] = self.convertIP(ip) - if netmask is not None: - data['netmask'] = self.convertIP(netmask) - if bcast is not None: - data['bcast'] = self.convertIP(bcast) - if up is not None: - data['up'] = True - if iface is not 'lo': - self.configuredInterfaces.append(iface) - if mac is not None: - data['mac'] = mac + globalIPpattern = re_compile("scope global") + ipRegexp = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' + netRegexp = '[0-9]{1,2}' + macRegexp = '[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[a-z0-9]{2}\:[a-z0-9]{2}\:[a-z0-9]{2}' + ipLinePattern = re_compile('inet ' + ipRegexp + '/') + ipPattern = re_compile(ipRegexp) + netmaskLinePattern = re_compile('/' + netRegexp) + netmaskPattern = re_compile(netRegexp) + bcastLinePattern = re_compile(' brd ' + ipRegexp) + upPattern = re_compile('UP') + macPattern = re_compile('[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[a-z0-9]{2}\:[a-z0-9]{2}\:[a-z0-9]{2}') + macLinePattern = re_compile('link/ether ' + macRegexp) + + for line in result.splitlines(): + split = line.strip().split(' ',2) + if (split[1][:-1] == iface): + up = self.regExpMatch(upPattern, split[2]) + mac = self.regExpMatch(macPattern, self.regExpMatch(macLinePattern, split[2])) + if up is not None: + data['up'] = True + if iface is not 'lo': + self.configuredInterfaces.append(iface) + if mac is not None: + data['mac'] = mac + if (split[1] == iface): + if re_search(globalIPpattern, split[2]): + ip = self.regExpMatch(ipPattern, self.regExpMatch(ipLinePattern, split[2])) + netmask = self.calc_netmask(self.regExpMatch(netmaskPattern, self.regExpMatch(netmaskLinePattern, split[2]))) + bcast = self.regExpMatch(ipPattern, self.regExpMatch(bcastLinePattern, split[2])) + if ip is not None: + data['ip'] = self.convertIP(ip) + if netmask is not None: + data['netmask'] = self.convertIP(netmask) + if bcast is not None: + data['bcast'] = self.convertIP(bcast) + if not data.has_key('ip'): data['dhcp'] = True - data['ip'] = [192, 168, 1, 2] - data['netmask'] = [255, 255, 255, 0] - data['gateway'] = [192, 168, 1, 1] - - fp = popen("route -n | grep " + iface) - result = fp.readlines() - fp.close() - for line in result: + data['ip'] = [0, 0, 0, 0] + data['netmask'] = [0, 0, 0, 0] + data['gateway'] = [0, 0, 0, 0] + + cmd = "route -n | grep " + iface + self.Console.ePopen(cmd,self.routeFinished, [iface, data, callback]) + + def routeFinished(self, result, retval, extra_args): + (iface, data, callback) = extra_args + ipRegexp = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' + ipPattern = re_compile(ipRegexp) + ipLinePattern = re_compile(ipRegexp) + + for line in result.splitlines(): print line[0:7] if line[0:7] == "0.0.0.0": gateway = self.regExpMatch(ipPattern, line[16:31]) if gateway is not None: data['gateway'] = self.convertIP(gateway) - return data + + self.ifaces[iface] = data + self.loadNetworkConfig(iface,callback) def writeNetworkConfig(self): self.configuredInterfaces = [] @@ -138,8 +185,7 @@ class Network: fp.write("nameserver %d.%d.%d.%d\n" % tuple(nameserver)) fp.close() - def loadNetworkConfig(self): - self.loadNameserverConfig() + def loadNetworkConfig(self,iface,callback = None): interfaces = [] # parse the interfaces-file try: @@ -160,23 +206,44 @@ class Network: ifaces[currif]["dhcp"] = True else: ifaces[currif]["dhcp"] = False - if (currif != ""): + if (currif == iface): #read information only for available interfaces if (split[0] == "address"): ifaces[currif]["address"] = map(int, split[1].split('.')) + if self.ifaces[currif].has_key("ip"): + if self.ifaces[currif]["ip"] != ifaces[currif]["address"] and ifaces[currif]["dhcp"] == False: + self.ifaces[currif]["ip"] = map(int, split[1].split('.')) if (split[0] == "netmask"): ifaces[currif]["netmask"] = map(int, split[1].split('.')) + if self.ifaces[currif].has_key("netmask"): + if self.ifaces[currif]["netmask"] != ifaces[currif]["netmask"] and ifaces[currif]["dhcp"] == False: + self.ifaces[currif]["netmask"] = map(int, split[1].split('.')) if (split[0] == "gateway"): ifaces[currif]["gateway"] = map(int, split[1].split('.')) + if self.ifaces[currif].has_key("gateway"): + if self.ifaces[currif]["gateway"] != ifaces[currif]["gateway"] and ifaces[currif]["dhcp"] == False: + self.ifaces[currif]["gateway"] = map(int, split[1].split('.')) if (split[0] == "pre-up"): - self.ifaces[currif]["preup"] = i + if self.ifaces[currif].has_key("preup"): + self.ifaces[currif]["preup"] = i if (split[0] == "post-down"): - self.ifaces[currif]["postdown"] = i + if self.ifaces[currif].has_key("postdown"): + self.ifaces[currif]["postdown"] = i - print "read interfaces:", ifaces for ifacename, iface in ifaces.items(): if self.ifaces.has_key(ifacename): self.ifaces[ifacename]["dhcp"] = iface["dhcp"] - print "self.ifaces after loading:", self.ifaces + if self.Console: + if len(self.Console.appContainers) == 0: + # save configured interfacelist + self.configuredNetworkAdapters = self.configuredInterfaces + # load ns only once + self.loadNameserverConfig() + print "read configured interface:", ifaces + print "self.ifaces after loading:", self.ifaces + self.config_ready = True + self.msgPlugins() + if callback is not None: + callback(True) def loadNameserverConfig(self): ipRegexp = "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" @@ -200,28 +267,95 @@ class Network: print "nameservers:", self.nameservers - def deactivateNetworkConfig(self): + def deactivateNetworkConfig(self, callback = None): + if self.onRemoteRootFS(): + if callback is not None: + callback(True) + return + self.deactivateConsole = Console() + self.commands = [] + self.commands.append("/etc/init.d/avahi-daemon stop") for iface in self.ifaces.keys(): - system("ip addr flush " + iface) - system("/etc/init.d/networking stop") - system("killall -9 udhcpc") - system("rm /var/run/udhcpc*") - - def activateNetworkConfig(self): - system("/etc/init.d/networking start") - self.getInterfaces() + cmd = "ip addr flush " + iface + self.commands.append(cmd) + self.commands.append("/etc/init.d/networking stop") + self.commands.append("killall -9 udhcpc") + self.commands.append("rm /var/run/udhcpc*") + self.deactivateConsole.eBatch(self.commands, self.deactivateNetworkFinished, callback, debug=True) + + def deactivateNetworkFinished(self,extra_args): + callback = extra_args + if len(self.deactivateConsole.appContainers) == 0: + if callback is not None: + callback(True) + + def activateNetworkConfig(self, callback = None): + if self.onRemoteRootFS(): + if callback is not None: + callback(True) + return + self.activateConsole = Console() + self.commands = [] + self.commands.append("/etc/init.d/networking start") + self.commands.append("/etc/init.d/avahi-daemon start") + self.activateConsole.eBatch(self.commands, self.activateNetworkFinished, callback, debug=True) + + def activateNetworkFinished(self,extra_args): + callback = extra_args + if len(self.activateConsole.appContainers) == 0: + if callback is not None: + callback(True) + + def getConfiguredAdapters(self): + return self.configuredNetworkAdapters def getNumberOfAdapters(self): return len(self.ifaces) def getFriendlyAdapterName(self, x): - # maybe this needs to be replaced by an external list. - friendlyNames = { - "eth0": _("Integrated Ethernet"), - "wlan0": _("Wireless"), - "ath0": _("Integrated Wireless") - } - return friendlyNames.get(x, x) # when we have no friendly name, use adapter name + if x in self.friendlyNames.keys(): + return self.friendlyNames.get(x, x) + else: + self.friendlyNames[x] = self.getFriendlyAdapterNaming(x) + return self.friendlyNames.get(x, x) # when we have no friendly name, use adapter name + + def getFriendlyAdapterNaming(self, iface): + if iface.startswith('eth'): + if iface not in self.lan_interfaces and len(self.lan_interfaces) == 0: + self.lan_interfaces.append(iface) + return _("LAN connection") + elif iface not in self.lan_interfaces and len(self.lan_interfaces) >= 1: + self.lan_interfaces.append(iface) + return _("LAN connection") + " " + str(len(self.lan_interfaces)) + else: + if iface not in self.wlan_interfaces and len(self.wlan_interfaces) == 0: + self.wlan_interfaces.append(iface) + return _("WLAN connection") + elif iface not in self.wlan_interfaces and len(self.wlan_interfaces) >= 1: + self.wlan_interfaces.append(iface) + return _("WLAN connection") + " " + str(len(self.wlan_interfaces)) + + def getFriendlyAdapterDescription(self, iface): + if iface == 'eth0': + return _("Internal LAN adapter.") + else: + classdir = "/sys/class/net/" + iface + "/device/" + driverdir = "/sys/class/net/" + iface + "/device/driver/" + if os_path.exists(classdir): + files = listdir(classdir) + if 'driver' in files: + if os_path.realpath(driverdir).endswith('ath_pci'): + return _("Atheros")+ " " + str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter.") + elif os_path.realpath(driverdir).endswith('zd1211b'): + 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: + return str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter.") + else: + return _("Unknown network adapter.") def getAdapterName(self, iface): return iface @@ -268,7 +402,28 @@ class Network: if self.nameservers[i] == oldnameserver: self.nameservers[i] = newnameserver - def writeDefaultNetworkConfig(self,mode='lan'): + def resetNetworkConfig(self, mode='lan', callback = None): + if self.onRemoteRootFS(): + if callback is not None: + callback(True) + return + self.resetNetworkConsole = Console() + self.commands = [] + self.commands.append("/etc/init.d/avahi-daemon stop") + for iface in self.ifaces.keys(): + cmd = "ip addr flush " + iface + self.commands.append(cmd) + self.commands.append("/etc/init.d/networking stop") + self.commands.append("killall -9 udhcpc") + self.commands.append("rm /var/run/udhcpc*") + self.resetNetworkConsole.eBatch(self.commands, self.resetNetworkFinishedCB, [mode, callback], debug=True) + + def resetNetworkFinishedCB(self, extra_args): + (mode, callback) = extra_args + if len(self.resetNetworkConsole.appContainers) == 0: + self.writeDefaultNetworkConfig(mode, callback) + + def writeDefaultNetworkConfig(self,mode='lan', callback = None): fp = file('/etc/network/interfaces', 'w') fp.write("# automatically generated by enigma 2\n# do NOT change manually!\n\n") fp.write("auto lo\n") @@ -285,44 +440,124 @@ class Network: fp.write("\n") fp.close() - def resetNetworkConfig(self,mode='lan'): - self.deactivateNetworkConfig() - self.writeDefaultNetworkConfig(mode) + self.resetNetworkConsole = Console() + self.commands = [] if mode == 'wlan': - system("ifconfig eth0 down") - system("ifconfig ath0 down") - system("ifconfig wlan0 up") + self.commands.append("ifconfig eth0 down") + self.commands.append("ifconfig ath0 down") + self.commands.append("ifconfig wlan0 up") if mode == 'wlan-mpci': - system("ifconfig eth0 down") - system("ifconfig wlan0 down") - system("ifconfig ath0 up") + self.commands.append("ifconfig eth0 down") + self.commands.append("ifconfig wlan0 down") + self.commands.append("ifconfig ath0 up") if mode == 'lan': - system("ifconfig eth0 up") - system("ifconfig wlan0 down") - system("ifconfig ath0 down") - self.getInterfaces() - - def checkNetworkState(self): - # www.dream-multimedia-tv.de, www.heise.de, www.google.de - return system("ping -c 1 82.149.226.170") == 0 or \ - system("ping -c 1 193.99.144.85") == 0 or \ - system("ping -c 1 209.85.135.103") == 0 - - def restartNetwork(self): - iNetwork.deactivateNetworkConfig() - iNetwork.activateNetworkConfig() + self.commands.append("ifconfig eth0 up") + self.commands.append("ifconfig wlan0 down") + self.commands.append("ifconfig ath0 down") + self.commands.append("/etc/init.d/avahi-daemon start") + self.resetNetworkConsole.eBatch(self.commands, self.resetNetworkFinished, [mode,callback], debug=True) + + def resetNetworkFinished(self,extra_args): + (mode, callback) = extra_args + if len(self.resetNetworkConsole.appContainers) == 0: + if callback is not None: + callback(True,mode) + + def checkNetworkState(self,statecallback): + # www.dream-multimedia-tv.de, www.heise.de, www.google.de + self.NetworkState = 0 + cmd1 = "ping -c 1 82.149.226.170" + cmd2 = "ping -c 1 193.99.144.85" + cmd3 = "ping -c 1 209.85.135.103" + self.PingConsole = Console() + self.PingConsole.ePopen(cmd1, self.checkNetworkStateFinished,statecallback) + self.PingConsole.ePopen(cmd2, self.checkNetworkStateFinished,statecallback) + self.PingConsole.ePopen(cmd3, self.checkNetworkStateFinished,statecallback) + + def checkNetworkStateFinished(self, result, retval,extra_args): + (statecallback) = extra_args + if self.PingConsole is not None: + if retval == 0: + self.PingConsole = None + statecallback(self.NetworkState) + else: + self.NetworkState += 1 + if len(self.PingConsole.appContainers) == 0: + statecallback(self.NetworkState) + + def restartNetwork(self,callback = None): + if self.onRemoteRootFS(): + if callback is not None: + callback(True) + return + self.restartConsole = Console() + self.config_ready = False + self.msgPlugins() + self.commands = [] + self.commands.append("/etc/init.d/avahi-daemon stop") + for iface in self.ifaces.keys(): + cmd = "ip addr flush " + iface + self.commands.append(cmd) + self.commands.append("/etc/init.d/networking stop") + self.commands.append("killall -9 udhcpc") + self.commands.append("rm /var/run/udhcpc*") + self.commands.append("/etc/init.d/networking start") + self.commands.append("/etc/init.d/avahi-daemon start") + self.restartConsole.eBatch(self.commands, self.restartNetworkFinished, callback, debug=True) + + def restartNetworkFinished(self,extra_args): + ( callback ) = extra_args + if callback is not None: + callback(True) def getLinkState(self,iface,callback): - self.dataAvail = callback cmd = self.ethtool_bin + " " + iface - self.container.appClosed.get().append(self.cmdFinished) - self.container.dataAvail.get().append(callback) - self.container.execute(cmd) + self.LinkConsole = Console() + self.LinkConsole.ePopen(cmd, self.getLinkStateFinished,callback) - def cmdFinished(self,retval): - self.container.appClosed.get().remove(self.cmdFinished) - self.container.dataAvail.get().remove(self.dataAvail) + def getLinkStateFinished(self, result, retval,extra_args): + (callback) = extra_args + if self.LinkConsole is not None: + if len(self.LinkConsole.appContainers) == 0: + callback(result) + + def stopPingConsole(self): + if self.PingConsole is not None: + if len(self.PingConsole.appContainers): + for name in self.PingConsole.appContainers.keys(): + self.PingConsole.kill(name) + + def stopLinkStateConsole(self): + if self.LinkConsole is not None: + if len(self.LinkConsole.appContainers): + for name in self.LinkConsole.appContainers.keys(): + self.LinkConsole.kill(name) + + def stopDNSConsole(self): + if self.DnsConsole is not None: + if len(self.DnsConsole.appContainers): + for name in self.DnsConsole.appContainers.keys(): + self.DnsConsole.kill(name) + + def stopRestartConsole(self): + if self.restartConsole is not None: + if len(self.restartConsole.appContainers): + for name in self.restartConsole.appContainers.keys(): + self.restartConsole.kill(name) + + def stopGetInterfacesConsole(self): + if self.Console is not None: + if len(self.Console.appContainers): + for name in self.Console.appContainers.keys(): + self.Console.kill(name) + + def stopDeactivateInterfaceConsole(self): + if self.deactivateInterfaceConsole is not None: + if len(self.deactivateInterfaceConsole.appContainers): + for name in self.deactivateInterfaceConsole.appContainers.keys(): + self.deactivateInterfaceConsole.kill(name) + def checkforInterface(self,iface): if self.getAdapterAttribute(iface, 'up') is True: return True @@ -334,33 +569,99 @@ class Network: else: return False - def checkDNSLookup(self): - return system("nslookup www.dream-multimedia-tv.de") == 0 or \ - system("nslookup www.heise.de") == 0 or \ - system("nslookup www.google.de") - - def deactivateInterface(self,iface): - system("ifconfig " + iface + " down") - - def detectWlanModule(self): + def checkDNSLookup(self,statecallback): + cmd1 = "nslookup www.dream-multimedia-tv.de" + cmd2 = "nslookup www.heise.de" + cmd3 = "nslookup www.google.de" + self.DnsConsole = Console() + self.DnsConsole.ePopen(cmd1, self.checkDNSLookupFinished,statecallback) + self.DnsConsole.ePopen(cmd2, self.checkDNSLookupFinished,statecallback) + self.DnsConsole.ePopen(cmd3, self.checkDNSLookupFinished,statecallback) + + def checkDNSLookupFinished(self, result, retval,extra_args): + (statecallback) = extra_args + if self.DnsConsole is not None: + if retval == 0: + self.DnsConsole = None + statecallback(self.DnsState) + else: + self.DnsState += 1 + if len(self.DnsConsole.appContainers) == 0: + statecallback(self.DnsState) + + def deactivateInterface(self,iface,callback = None): + if self.onRemoteRootFS(): + if callback is not None: + callback(True) + return + self.deactivateInterfaceConsole = Console() + self.commands = [] + cmd1 = "ip addr flush " + iface + cmd2 = "ifconfig " + iface + " down" + self.commands.append(cmd1) + self.commands.append(cmd2) + self.deactivateInterfaceConsole.eBatch(self.commands, self.deactivateInterfaceFinished, callback, debug=True) + + def deactivateInterfaceFinished(self,extra_args): + callback = extra_args + if self.deactivateInterfaceConsole: + if len(self.deactivateInterfaceConsole.appContainers) == 0: + if callback is not None: + callback(True) + + def detectWlanModule(self, iface = 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: - self.wlanmodule = 'ralink' - if os_path.exists(zd1211b_dir): - zdfiles = listdir(zd1211b_dir) - if len(zdfiles) == 1: - 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 + from socket import inet_ntoa, inet_aton + mask = 1L<<31 + xnet = (1L<<32)-1 + cidr_range = range(0, 32) + cidr = long(nmask) + if cidr not in cidr_range: + print 'cidr invalid: %d' % cidr + return None + else: + nm = ((1L<L', nm))) + return netmask + def msgPlugins(self): + if self.config_ready is not None: + for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKCONFIG_READ): + p(reason=self.config_ready) iNetwork = Network()