1 from os import system, popen, path as os_path, listdir
2 from re import compile as re_compile, search as re_search
4 from enigma import eConsoleAppContainer
5 from Components.Console import Console
6 from Components.PluginComponent import plugins
7 from Components.About import about
8 from Plugins.Plugin import PluginDescriptor
13 self.configuredInterfaces = []
14 self.configuredNetworkAdapters = []
18 self.ethtool_bin = "ethtool"
19 self.container = eConsoleAppContainer()
20 self.Console = Console()
21 self.LinkConsole = Console()
22 self.restartConsole = Console()
23 self.deactivateInterfaceConsole = Console()
24 self.activateInterfaceConsole = Console()
25 self.resetNetworkConsole = Console()
26 self.DnsConsole = Console()
27 self.PingConsole = Console()
28 self.config_ready = None
29 self.friendlyNames = {}
30 self.lan_interfaces = []
31 self.wlan_interfaces = []
32 self.remoteRootFS = None
35 def onRemoteRootFS(self):
36 if self.remoteRootFS == None:
37 fp = file('/proc/mounts', 'r')
38 mounts = fp.readlines()
40 self.remoteRootFS = False
42 parts = line.strip().split()
43 if parts[1] == '/' and parts[2] == 'nfs':
44 self.remoteRootFS = True
46 return self.remoteRootFS
48 def isBlacklisted(self, iface):
49 return iface in ('lo', 'wifi0', 'wmaster0', 'sys0')
51 def getInterfaces(self, callback = None):
52 self.configuredInterfaces = []
53 for device in self.getInstalledAdapters():
54 self.getAddrInet(device, callback)
57 def regExpMatch(self, pattern, string):
61 return pattern.search(string).group()
62 except AttributeError:
65 # helper function to convert ips from a sring to a list of ints
66 def convertIP(self, ip):
67 return [ int(n) for n in ip.split('.') ]
69 def getAddrInet(self, iface, callback):
71 self.Console = Console()
72 cmd = "ip -o addr show dev " + iface
73 self.Console.ePopen(cmd, self.IPaddrFinished, [iface,callback])
75 def IPaddrFinished(self, result, retval, extra_args):
76 (iface, callback ) = extra_args
77 data = { 'up': False, 'dhcp': False, 'preup' : False, 'predown' : False, 'dns-nameservers' : False }
78 globalIPpattern = re_compile("scope global")
79 ipRegexp = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
80 netRegexp = '[0-9]{1,2}'
81 macRegexp = '[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}'
82 ipLinePattern = re_compile('inet ' + ipRegexp + '/')
83 ipPattern = re_compile(ipRegexp)
84 netmaskLinePattern = re_compile('/' + netRegexp)
85 netmaskPattern = re_compile(netRegexp)
86 bcastLinePattern = re_compile(' brd ' + ipRegexp)
87 upPattern = re_compile('UP')
88 macPattern = re_compile(macRegexp)
89 macLinePattern = re_compile('link/ether ' + macRegexp)
91 for line in result.splitlines():
92 split = line.strip().split(' ',2)
93 if (split[1][:-1] == iface) or (split[1][:-1] == (iface + '@sys0')):
94 up = self.regExpMatch(upPattern, split[2])
95 mac = self.regExpMatch(macPattern, self.regExpMatch(macLinePattern, split[2]))
99 self.configuredInterfaces.append(iface)
102 if (split[1] == iface):
103 if re_search(globalIPpattern, split[2]):
104 ip = self.regExpMatch(ipPattern, self.regExpMatch(ipLinePattern, split[2]))
105 netmask = self.calc_netmask(self.regExpMatch(netmaskPattern, self.regExpMatch(netmaskLinePattern, split[2])))
106 bcast = self.regExpMatch(ipPattern, self.regExpMatch(bcastLinePattern, split[2]))
108 data['ip'] = self.convertIP(ip)
109 if netmask is not None:
110 data['netmask'] = self.convertIP(netmask)
111 if bcast is not None:
112 data['bcast'] = self.convertIP(bcast)
114 if not data.has_key('ip'):
116 data['ip'] = [0, 0, 0, 0]
117 data['netmask'] = [0, 0, 0, 0]
118 data['gateway'] = [0, 0, 0, 0]
120 cmd = "route -n | grep " + iface
121 self.Console.ePopen(cmd,self.routeFinished, [iface, data, callback])
123 def routeFinished(self, result, retval, extra_args):
124 (iface, data, callback) = extra_args
125 ipRegexp = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
126 ipPattern = re_compile(ipRegexp)
127 ipLinePattern = re_compile(ipRegexp)
129 for line in result.splitlines():
131 if line[0:7] == "0.0.0.0":
132 gateway = self.regExpMatch(ipPattern, line[16:31])
134 data['gateway'] = self.convertIP(gateway)
136 self.ifaces[iface] = data
137 self.loadNetworkConfig(iface,callback)
139 def writeNetworkConfig(self):
140 self.configuredInterfaces = []
141 fp = file('/etc/network/interfaces', 'w')
142 fp.write("# automatically generated by enigma 2\n# do NOT change manually!\n\n")
143 fp.write("auto lo\n")
144 fp.write("iface lo inet loopback\n\n")
145 for ifacename, iface in self.ifaces.items():
146 if iface['up'] == True:
147 fp.write("auto " + ifacename + "\n")
148 self.configuredInterfaces.append(ifacename)
149 if iface['dhcp'] == True:
150 fp.write("iface "+ ifacename +" inet dhcp\n")
151 if iface['dhcp'] == False:
152 fp.write("iface "+ ifacename +" inet static\n")
153 if iface.has_key('ip'):
154 print tuple(iface['ip'])
155 fp.write(" address %d.%d.%d.%d\n" % tuple(iface['ip']))
156 fp.write(" netmask %d.%d.%d.%d\n" % tuple(iface['netmask']))
157 if iface.has_key('gateway'):
158 fp.write(" gateway %d.%d.%d.%d\n" % tuple(iface['gateway']))
159 if iface.has_key("configStrings"):
160 fp.write(iface["configStrings"])
161 if iface["preup"] is not False and not iface.has_key("configStrings"):
162 fp.write(iface["preup"])
163 if iface["predown"] is not False and not iface.has_key("configStrings"):
164 fp.write(iface["predown"])
165 if iface["dns-nameservers"] is not False and len(iface["dns-nameservers"])>0:
166 fp.write("%s" % (iface["dns-nameservers"]))
169 self.configuredNetworkAdapters = self.configuredInterfaces
170 # self.writeNameserverConfig()
172 def writeNameserverConfig(self):
173 fp = file('/etc/resolv.conf', 'w')
174 for nameserver in self.nameservers:
175 fp.write("nameserver %d.%d.%d.%d\n" % tuple(nameserver))
178 def loadNetworkConfig(self,iface,callback = None):
180 # parse the interfaces-file
182 fp = file('/etc/network/interfaces', 'r')
183 interfaces = fp.readlines()
186 print "[Network.py] interfaces - opening failed"
191 split = i.strip().split(' ')
192 if (split[0] == "iface"):
195 if (len(split) == 4 and split[3] == "dhcp"):
196 ifaces[currif]["dhcp"] = True
198 ifaces[currif]["dhcp"] = False
199 if (currif == iface): #read information only for available interfaces
200 if (split[0] == "address"):
201 ifaces[currif]["address"] = map(int, split[1].split('.'))
202 if self.ifaces[currif].has_key("ip"):
203 if self.ifaces[currif]["ip"] != ifaces[currif]["address"] and ifaces[currif]["dhcp"] == False:
204 self.ifaces[currif]["ip"] = map(int, split[1].split('.'))
205 if (split[0] == "netmask"):
206 ifaces[currif]["netmask"] = map(int, split[1].split('.'))
207 if self.ifaces[currif].has_key("netmask"):
208 if self.ifaces[currif]["netmask"] != ifaces[currif]["netmask"] and ifaces[currif]["dhcp"] == False:
209 self.ifaces[currif]["netmask"] = map(int, split[1].split('.'))
210 if (split[0] == "gateway"):
211 ifaces[currif]["gateway"] = map(int, split[1].split('.'))
212 if self.ifaces[currif].has_key("gateway"):
213 if self.ifaces[currif]["gateway"] != ifaces[currif]["gateway"] and ifaces[currif]["dhcp"] == False:
214 self.ifaces[currif]["gateway"] = map(int, split[1].split('.'))
215 if (split[0] == "pre-up"):
216 if self.ifaces[currif].has_key("preup"):
217 self.ifaces[currif]["preup"] = i
218 if (split[0] in ("pre-down","post-down")):
219 if self.ifaces[currif].has_key("predown"):
220 self.ifaces[currif]["predown"] = i
221 if (split[0] == "dns-nameservers"):
222 if self.ifaces[currif].has_key("dns-nameservers"):
223 self.ifaces[currif]["dns-nameservers"] = i
225 for ifacename, iface in ifaces.items():
226 if self.ifaces.has_key(ifacename):
227 self.ifaces[ifacename]["dhcp"] = iface["dhcp"]
229 if len(self.Console.appContainers) == 0:
230 # save configured interfacelist
231 self.configuredNetworkAdapters = self.configuredInterfaces
233 self.loadNameserverConfig()
234 print "read configured interface:", ifaces
235 print "self.ifaces after loading:", self.ifaces
236 self.config_ready = True
238 if callback is not None:
241 def loadNameserverConfig(self):
242 ipRegexp = "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
243 nameserverPattern = re_compile("nameserver +" + ipRegexp)
244 ipPattern = re_compile(ipRegexp)
248 fp = file('/etc/resolv.conf', 'r')
249 resolv = fp.readlines()
251 self.nameservers = []
253 print "[Network.py] resolv.conf - opening failed"
256 if self.regExpMatch(nameserverPattern, line) is not None:
257 ip = self.regExpMatch(ipPattern, line)
259 self.nameservers.append(self.convertIP(ip))
261 print "nameservers:", self.nameservers
263 def getInstalledAdapters(self):
264 return [x for x in listdir('/sys/class/net') if not self.isBlacklisted(x)]
266 def getConfiguredAdapters(self):
267 return self.configuredNetworkAdapters
269 def getNumberOfAdapters(self):
270 return len(self.ifaces)
272 def getFriendlyAdapterName(self, x):
273 if x in self.friendlyNames.keys():
274 return self.friendlyNames.get(x, x)
275 self.friendlyNames[x] = self.getFriendlyAdapterNaming(x)
276 return self.friendlyNames.get(x, x) # when we have no friendly name, use adapter name
278 def getFriendlyAdapterNaming(self, iface):
280 if self.isWirelessInterface(iface):
281 if iface not in self.wlan_interfaces:
282 name = _("WLAN connection")
283 if len(self.wlan_interfaces):
284 name += " " + str(len(self.wlan_interfaces)+1)
285 self.wlan_interfaces.append(iface)
287 if iface not in self.lan_interfaces:
288 name = _("LAN connection")
289 if len(self.lan_interfaces):
290 name += " " + str(len(self.lan_interfaces)+1)
291 self.lan_interfaces.append(iface)
294 def useWlCommand(self, iface):
295 return iface and os_path.exists("/tmp/bcm/%s" % iface)
297 def getFriendlyAdapterDescription(self, iface):
298 if not self.isWirelessInterface(iface):
299 return _('Ethernet network interface')
301 moduledir = self.getWlanModuleDir(iface)
303 name = os_path.basename(os_path.realpath(moduledir))
304 if name in ('ath_pci', 'ath5k'):
306 elif name in ('rt73','rt73usb','rt3070sta', 'rt5370sta'):
308 elif name == 'zd1211b':
310 elif name in ('r871x_usb_drv', 'rtw_usb_drv'):
312 elif self.isRalinkModule(iface):
314 elif self.useWlCommand(iface):
319 return name + ' ' + _('wireless network interface')
321 def isRalinkModule(self, iface):
323 # check vendor ID for lagacy driver
324 vendorID = "148f" # ralink vendor ID
325 idVendorPath = "/sys/class/net/%s/device/idVendor" % iface
326 if os.access(idVendorPath, os.R_OK):
327 if open(idVendorPath, "r").read().strip() == vendorID:
330 # check sys driver path for kernel driver
331 ralinkKmod = "rt2800usb" # ralink kernel driver name
332 driverPath = "/sys/class/net/%s/device/driver/" % iface
333 if os.path.exists(driverPath):
334 driverName = os.path.basename(os_path.realpath(driverPath))
335 if driverName == ralinkKmod:
339 def getAdapterName(self, iface):
342 def getAdapterList(self):
343 return self.ifaces.keys()
345 def getAdapterAttribute(self, iface, attribute):
346 if self.ifaces.has_key(iface):
347 if self.ifaces[iface].has_key(attribute):
348 return self.ifaces[iface][attribute]
351 def setAdapterAttribute(self, iface, attribute, value):
352 print "setting for adapter", iface, "attribute", attribute, " to value", value
353 if self.ifaces.has_key(iface):
354 self.ifaces[iface][attribute] = value
356 def removeAdapterAttribute(self, iface, attribute):
357 if self.ifaces.has_key(iface):
358 if self.ifaces[iface].has_key(attribute):
359 del self.ifaces[iface][attribute]
361 def getNameserverList(self):
362 if len(self.nameservers) == 0:
363 return [[0, 0, 0, 0], [0, 0, 0, 0]]
365 return self.nameservers
367 def clearNameservers(self):
368 self.nameservers = []
370 def addNameserver(self, nameserver):
371 if nameserver not in self.nameservers:
372 self.nameservers.append(nameserver)
374 def removeNameserver(self, nameserver):
375 if nameserver in self.nameservers:
376 self.nameservers.remove(nameserver)
378 def changeNameserver(self, oldnameserver, newnameserver):
379 if oldnameserver in self.nameservers:
380 for i in range(len(self.nameservers)):
381 if self.nameservers[i] == oldnameserver:
382 self.nameservers[i] = newnameserver
384 def resetNetworkConfig(self, mode='lan', callback = None):
385 self.resetNetworkConsole = Console()
387 self.commands.append("/etc/init.d/avahi-daemon stop")
388 for iface in self.ifaces.keys():
389 if iface != 'eth0' or not self.onRemoteRootFS():
390 self.commands.append("ip addr flush dev " + iface)
391 self.commands.append("/etc/init.d/networking stop")
392 self.commands.append("killall -9 udhcpc")
393 self.commands.append("rm /var/run/udhcpc*")
394 self.resetNetworkConsole.eBatch(self.commands, self.resetNetworkFinishedCB, [mode, callback], debug=True)
396 def resetNetworkFinishedCB(self, extra_args):
397 (mode, callback) = extra_args
398 if len(self.resetNetworkConsole.appContainers) == 0:
399 self.writeDefaultNetworkConfig(mode, callback)
401 def writeDefaultNetworkConfig(self,mode='lan', callback = None):
402 fp = file('/etc/network/interfaces', 'w')
403 fp.write("# automatically generated by enigma 2\n# do NOT change manually!\n\n")
404 fp.write("auto lo\n")
405 fp.write("iface lo inet loopback\n\n")
407 fp.write("auto wlan0\n")
408 fp.write("iface wlan0 inet dhcp\n")
409 if mode == 'wlan-mpci':
410 fp.write("auto ath0\n")
411 fp.write("iface ath0 inet dhcp\n")
413 fp.write("auto eth0\n")
414 fp.write("iface eth0 inet dhcp\n")
418 self.resetNetworkConsole = Console()
421 self.commands.append("ifconfig eth0 down")
422 self.commands.append("ifconfig ath0 down")
423 self.commands.append("ifconfig wlan0 up")
424 if mode == 'wlan-mpci':
425 self.commands.append("ifconfig eth0 down")
426 self.commands.append("ifconfig wlan0 down")
427 self.commands.append("ifconfig ath0 up")
429 self.commands.append("ifconfig eth0 up")
430 self.commands.append("ifconfig wlan0 down")
431 self.commands.append("ifconfig ath0 down")
432 self.commands.append("/etc/init.d/avahi-daemon start")
433 self.resetNetworkConsole.eBatch(self.commands, self.resetNetworkFinished, [mode,callback], debug=True)
435 def resetNetworkFinished(self,extra_args):
436 (mode, callback) = extra_args
437 if len(self.resetNetworkConsole.appContainers) == 0:
438 if callback is not None:
441 def checkNetworkState(self,statecallback):
442 self.NetworkState = 0
443 self.PingConsole = Console()
444 for testserver in ("www.heise.de", "www.google.de", "de.yahoo.com"):
445 self.PingConsole.ePopen("ping -c 1 %s" % testserver, self.checkNetworkStateFinished,statecallback)
447 def checkNetworkStateFinished(self, result, retval,extra_args):
448 (statecallback) = extra_args
449 if self.PingConsole is not None:
451 self.PingConsole = None
452 statecallback(self.NetworkState)
454 self.NetworkState += 1
455 if len(self.PingConsole.appContainers) == 0:
456 statecallback(self.NetworkState)
458 def restartNetwork(self,callback = None):
459 self.restartConsole = Console()
460 self.config_ready = False
463 self.commands.append("/etc/init.d/avahi-daemon stop")
464 for iface in self.ifaces.keys():
465 if iface != 'eth0' or not self.onRemoteRootFS():
466 self.commands.append("ifdown " + iface)
467 self.commands.append("ip addr flush dev " + iface)
468 self.commands.append("/etc/init.d/networking stop")
469 self.commands.append("killall -9 udhcpc")
470 self.commands.append("rm /var/run/udhcpc*")
471 self.commands.append("/etc/init.d/networking start")
472 self.commands.append("/etc/init.d/avahi-daemon start")
473 self.restartConsole.eBatch(self.commands, self.restartNetworkFinished, callback, debug=True)
475 def restartNetworkFinished(self,extra_args):
476 ( callback ) = extra_args
477 if callback is not None:
480 def getLinkState(self,iface,callback):
481 cmd = self.ethtool_bin + " " + iface
482 self.LinkConsole = Console()
483 self.LinkConsole.ePopen(cmd, self.getLinkStateFinished,callback)
485 def getLinkStateFinished(self, result, retval,extra_args):
486 (callback) = extra_args
488 if self.LinkConsole is not None:
489 if len(self.LinkConsole.appContainers) == 0:
492 def stopPingConsole(self):
493 if self.PingConsole is not None:
494 if len(self.PingConsole.appContainers):
495 for name in self.PingConsole.appContainers.keys():
496 self.PingConsole.kill(name)
498 def stopLinkStateConsole(self):
499 if self.LinkConsole is not None:
500 if len(self.LinkConsole.appContainers):
501 for name in self.LinkConsole.appContainers.keys():
502 self.LinkConsole.kill(name)
504 def stopDNSConsole(self):
505 if self.DnsConsole is not None:
506 if len(self.DnsConsole.appContainers):
507 for name in self.DnsConsole.appContainers.keys():
508 self.DnsConsole.kill(name)
510 def stopRestartConsole(self):
511 if self.restartConsole is not None:
512 if len(self.restartConsole.appContainers):
513 for name in self.restartConsole.appContainers.keys():
514 self.restartConsole.kill(name)
516 def stopGetInterfacesConsole(self):
517 if self.Console is not None:
518 if len(self.Console.appContainers):
519 for name in self.Console.appContainers.keys():
520 self.Console.kill(name)
522 def stopDeactivateInterfaceConsole(self):
523 if self.deactivateInterfaceConsole is not None:
524 self.deactivateInterfaceConsole.killAll()
525 self.deactivateInterfaceConsole = None
527 def stopActivateInterfaceConsole(self):
528 if self.activateInterfaceConsole is not None:
529 self.activateInterfaceConsole.killAll()
530 self.activateInterfaceConsole = None
532 def checkforInterface(self,iface):
533 if self.getAdapterAttribute(iface, 'up') is True:
536 ret=system("ifconfig " + iface + " up")
537 system("ifconfig " + iface + " down")
543 def checkDNSLookup(self,statecallback):
544 cmd1 = "nslookup www.dream-multimedia-tv.de"
545 cmd2 = "nslookup www.heise.de"
546 cmd3 = "nslookup www.google.de"
547 self.DnsConsole = Console()
548 self.DnsConsole.ePopen(cmd1, self.checkDNSLookupFinished,statecallback)
549 self.DnsConsole.ePopen(cmd2, self.checkDNSLookupFinished,statecallback)
550 self.DnsConsole.ePopen(cmd3, self.checkDNSLookupFinished,statecallback)
552 def checkDNSLookupFinished(self, result, retval,extra_args):
553 (statecallback) = extra_args
554 if self.DnsConsole is not None:
556 self.DnsConsole = None
557 statecallback(self.DnsState)
560 if len(self.DnsConsole.appContainers) == 0:
561 statecallback(self.DnsState)
563 def deactivateInterface(self,ifaces,callback = None):
564 self.config_ready = False
567 def buildCommands(iface):
568 commands.append("ifdown " + iface)
569 commands.append("ip addr flush dev " + iface)
570 #wpa_supplicant sometimes doesn't quit properly on SIGTERM
571 if os_path.exists('/var/run/wpa_supplicant/'+ iface):
572 commands.append("wpa_cli -i" + iface + " terminate")
574 if not self.deactivateInterfaceConsole:
575 self.deactivateInterfaceConsole = Console()
577 if isinstance(ifaces, (list, tuple)):
579 if iface != 'eth0' or not self.onRemoteRootFS():
582 if ifaces == 'eth0' and self.onRemoteRootFS():
583 if callback is not None:
586 buildCommands(ifaces)
587 self.deactivateInterfaceConsole.eBatch(commands, self.deactivateInterfaceFinished, [ifaces,callback], debug=True)
589 def deactivateInterfaceFinished(self,extra_args):
590 (ifaces, callback) = extra_args
591 def checkCommandResult(iface):
592 if self.deactivateInterfaceConsole and self.deactivateInterfaceConsole.appResults.has_key("ifdown " + iface):
593 result = str(self.deactivateInterfaceConsole.appResults.get("ifdown " + iface)).strip("\n")
594 if result == "ifdown: interface " + iface + " not configured":
598 #ifdown sometimes can't get the interface down.
599 if isinstance(ifaces, (list, tuple)):
601 if checkCommandResult(iface) is False:
602 Console().ePopen(("ifconfig " + iface + " down" ))
604 if checkCommandResult(ifaces) is False:
605 Console().ePopen(("ifconfig " + ifaces + " down" ))
607 if self.deactivateInterfaceConsole:
608 if len(self.deactivateInterfaceConsole.appContainers) == 0:
609 if callback is not None:
612 def activateInterface(self,iface,callback = None):
613 if self.config_ready:
614 self.config_ready = False
616 if iface == 'eth0' and self.onRemoteRootFS():
617 if callback is not None:
620 if not self.activateInterfaceConsole:
621 self.activateInterfaceConsole = Console()
623 commands.append("ifup " + iface)
624 self.activateInterfaceConsole.eBatch(commands, self.activateInterfaceFinished, callback, debug=True)
626 def activateInterfaceFinished(self,extra_args):
627 callback = extra_args
628 if self.activateInterfaceConsole:
629 if len(self.activateInterfaceConsole.appContainers) == 0:
630 if callback is not None:
633 def sysfsPath(self, iface):
634 return '/sys/class/net/' + iface
636 def isWirelessInterface(self, iface):
637 if iface in self.wlan_interfaces:
640 if os_path.isdir(self.sysfsPath(iface) + '/wireless'):
643 # r871x_usb_drv on kernel 2.6.12 is not identifiable over /sys/class/net/'ifacename'/wireless so look also inside /proc/net/wireless
644 device = re_compile('[a-z]{2,}[0-9]*:')
646 fp = open('/proc/net/wireless', 'r')
649 ifnames.append(device.search(line).group()[:-1])
650 except AttributeError:
657 def getWlanModuleDir(self, iface = None):
658 devicedir = self.sysfsPath(iface) + '/device'
659 if not os_path.exists(devicedir):
662 moduledir = devicedir + '/driver/module'
663 if os_path.isdir(moduledir):
666 # identification is not possible over default moduledir
667 for x in listdir(devicedir):
668 # rt3070 on kernel 2.6.18 registers wireless devices as usb_device (e.g. 1-1.3:1.0) and identification is only possible over /sys/class/net/'ifacename'/device/1-xxx
669 if x.startswith("1-"):
670 moduledir = devicedir + '/' + x + '/driver/module'
671 if os_path.isdir(moduledir):
673 # rt73, zd1211b, r871x_usb_drv on kernel 2.6.12 can be identified over /sys/class/net/'ifacename'/device/driver, so look also here
674 moduledir = devicedir + '/driver'
675 if os_path.isdir(moduledir):
680 def detectWlanModule(self, iface = None):
681 if not self.isWirelessInterface(iface):
684 devicedir = self.sysfsPath(iface) + '/device'
685 if os_path.isdir(devicedir + '/ieee80211'):
688 moduledir = self.getWlanModuleDir(iface)
690 module = os_path.basename(os_path.realpath(moduledir))
691 if module in ('ath_pci','ath5k'):
693 if module in ('rt73','rt73'):
695 if module == 'zd1211b':
699 def calc_netmask(self,nmask):
700 from struct import pack, unpack
701 from socket import inet_ntoa, inet_aton
704 cidr_range = range(0, 32)
706 if cidr not in cidr_range:
707 print 'cidr invalid: %d' % cidr
710 nm = ((1L<<cidr)-1)<<(32-cidr)
711 netmask = str(inet_ntoa(pack('>L', nm)))
714 def msgPlugins(self):
715 if self.config_ready is not None:
716 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKCONFIG_READ):
717 p(reason=self.config_ready)
719 def getInterfacesNameserverList(self, iface):
721 nameservers = self.getAdapterAttribute(iface, "dns-nameservers")
723 ipRegexp = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
724 ipPattern = re_compile(ipRegexp)
725 for x in nameservers.split()[1:]:
726 ip = self.regExpMatch(ipPattern, x)
728 result.append( [ int(n) for n in ip.split('.') ] )