1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-24 07:02:29 +01:00

Merge in Dario Freddi's additions, with some modifications.

This commit is contained in:
Dan O'Reilly
2009-03-08 22:49:24 -04:00
4 changed files with 133 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" ioctl Network interface control tools for wicd.
@@ -66,6 +67,7 @@ SIOCGIWESSID = 0x8B1B
SIOCGIWRANGE = 0x8B0B
SIOCGIWAP = 0x8B15
SIOCGIWSTATS = 0x8B0F
SIOCGIWRATE = 0x8B21
# Got these from /usr/include/sockios.h
SIOCGIFADDR = 0x8915
@@ -295,6 +297,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
ap["bssid"] = cell["bssid"]
ap["mode"] = cell["mode"]
ap["bitrates"] = cell["bitrate"]
if cell["enc"]:
ap["encryption"] = True
@@ -479,6 +482,31 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
raw_addr = struct.unpack("xxBBBBBB", result[:8])
return "%02X:%02X:%02X:%02X:%02X:%02X" % raw_addr
def GetCurrentBitrate(self, iwconfig=None):
""" Get the current bitrate for the interface. """
if not self.iface: return ""
data = (self.iface + '\0' * 32)[:32]
fmt = "ihbb"
size = struct.calcsize(fmt)
try:
result = fcntl.ioctl(self.sock.fileno(), SIOCGIWRATE, data)[16:]
except IOError, e:
if self.verbose:
print "SIOCGIWRATE failed: " + str(e)
return ""
f, e, x, x = struct.unpack(fmt, result[:size])
return "%s %s" % ((f / 1000000), 'Mb/s')
#def GetOperationalMode(self, iwconfig=None):
# """ Get the operational mode for the interface. """
# TODO: implement me
# return ''
#def GetAvailableAuthMethods(self, iwlistauth=None):
# """ Get the authentication methods for the interface. """
# TODO: Implement me
# return ''
def GetSignalStrength(self, iwconfig=None):
""" Get the signal strength of the current network.
@@ -544,3 +572,4 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
return None
return buff.strip('\x00')

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" networking - Provides wrappers for common network operations
@@ -629,6 +630,36 @@ class Wireless(Controller):
"""
return self.wiface.GetBSSID()
def GetCurrentBitrate(self, iwconfig):
""" Get the current bitrate of the interface.
Returns:
The bitrate of the active access point as a string, or
None the bitrate can't be found.
"""
return self.wiface.GetCurrentBitrate(iwconfig)
def GetOperationalMode(self, iwconfig):
""" Get the current operational mode of the interface.
Returns:
The operational mode of the interface as a string, or
None if the operational mode can't be found.
"""
return self.wiface.GetOperationalMode(iwconfig)
def GetAvailableAuthMethods(self, iwlistauth):
""" Get the available authentication methods for the interface.
Returns:
The available authentication methods of the interface as a string, or
None if the auth methods can't be found.
"""
return self.wiface.GetAvailableAuthMethods(iwlistauth)
def GetIwconfig(self):
""" Get the out of iwconfig. """
return self.wiface.GetIwconfig()

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" wicd - wireless connection daemon implementation.
@@ -993,8 +994,24 @@ class WirelessDaemon(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wireless')
def GetApBssid(self):
""" Gets the MAC address for the active network. """
return self.wifi.GetBSSID()
@dbus.service.method('org.wicd.daemon.wireless')
def GetCurrentBitrate(self, iwconfig):
""" Returns the current bitrate for the active network. """
return self.wifi.GetCurrentBitrate(iwconfig)
@dbus.service.method('org.wicd.daemon.wireless')
def GetOperationalMode(self, iwconfig):
""" Returns the operational mode for the iwconfig parameter """
return misc.to_unicode(self.wifi.GetOperationalMode(iwconfig))
@dbus.service.method('org.wicd.daemon.wireless')
def GetAvailableAuthMethods(self, iwlistauth):
""" Returns the operational mode for the iwlistauth parameter """
return misc.to_unicode(self.wifi.GetAvailableAuthMethods(iwlistauth))
@dbus.service.method('org.wicd.daemon.wireless')
def CreateAdHocNetwork(self, essid, channel, ip, enctype, key, encused,
ics):
@@ -1125,6 +1142,12 @@ class WirelessDaemon(dbus.service.Object):
ip = self.wifi.GetIP(ifconfig)
return ip
@dbus.service.method('org.wicd.daemon.wireless')
def GetOperationalMode(self, ifconfig=""):
""" Returns the IP associated with the wireless interface. """
ip = self.wifi.GetOperationalMode(ifconfig)
return ip
@dbus.service.method('org.wicd.daemon.wireless')
def CheckWirelessConnectingMessage(self):
""" Returns the wireless interface's status message. """
@@ -1677,3 +1700,4 @@ if __name__ == '__main__':
sys.exit(1)
gobject.threads_init()
main(sys.argv)

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Network interface control tools for wicd.
@@ -49,6 +50,7 @@ channel_pattern = re.compile('.*Channel:? ?(\d\d?)', __re_mode)
strength_pattern = re.compile('.*Quality:?=? ?(\d+)\s*/?\s*(\d*)', __re_mode)
altstrength_pattern = re.compile('.*Signal level:?=? ?(\d+)\s*/?\s*(\d*)', __re_mode)
signaldbm_pattern = re.compile('.*Signal level:?=? ?(-\d\d*)', __re_mode)
bitrates_pattern = re.compile('.*Bit Rates:(.*?)E', __re_mode)
mode_pattern = re.compile('.*Mode:(.*?)\n', __re_mode)
freq_pattern = re.compile('.*Frequency:(.*?)\n', __re_mode)
wep_pattern = re.compile('.*Encryption key:(.*?)\n', __re_mode)
@@ -59,6 +61,9 @@ wpa2_pattern = re.compile('(WPA2)', __re_mode)
#iwconfig-only regular expressions.
ip_pattern = re.compile(r'inet [Aa]d?dr[^.]*:([^.]*\.[^.]*\.[^.]*\.[0-9]*)',re.S)
bssid_pattern = re.compile('.*Access Point: (([0-9A-Z]{2}:){5}[0-9A-Z]{2})', __re_mode)
bitrate_pattern = re.compile('.*Bit Rate=(.*?/s)', __re_mode)
opmode_pattern = re.compile('.*Mode:(.*?) ', __re_mode)
authmethods_pattern = re.compile('.*Authentication capabilities :\n(.*?)Current', __re_mode)
# Regular expressions for wpa_cli output
auth_pattern = re.compile('.*wpa_state=(.*?)\n', __re_mode)
@@ -1035,7 +1040,6 @@ class BaseWirelessInterface(BaseInterface):
A dictionary containing the cell networks properties.
"""
ap = {}
ap['essid'] = misc.RunRegex(essid_pattern, cell)
try:
@@ -1056,6 +1060,10 @@ class BaseWirelessInterface(BaseInterface):
freq = misc.RunRegex(freq_pattern, cell)
ap['channel'] = self._FreqToChannel(freq)
# Bit Rate
ap['bitrates'] = misc.RunRegex(bitrates_pattern, cell).split('\n')
ap['bitrates'] = '; '.join(m.strip() for m in ap['bitrates']).rstrip('; ')
# BSSID
ap['bssid'] = misc.RunRegex(ap_mac_pattern, cell)
@@ -1180,6 +1188,45 @@ class BaseWirelessInterface(BaseInterface):
bssid = misc.RunRegex(bssid_pattern, output)
return bssid
def GetCurrentBitrate(self, iwconfig=None):
""" Get the current bitrate for the interface. """
if not iwconfig:
cmd = 'iwconfig ' + self.iface
if self.verbose: print cmd
output = misc.Run(cmd)
else:
output = iwconfig
bitrate = misc.RunRegex(bitrate_pattern, output)
return bitrate
def GetOperationalMode(self, iwconfig=None):
""" Get the operational mode for the interface. """
if not iwconfig:
cmd = 'iwconfig ' + self.iface
if self.verbose: print cmd
output = misc.Run(cmd)
else:
output = iwconfig
opmode = misc.RunRegex(opmode_pattern, output)
if opmode:
opmode = opmode.strip()
return opmode
def GetAvailableAuthMethods(self, iwlistauth=None):
""" Get the available authentication methods for the interface. """
if not iwlistauth:
cmd = 'iwlist ' + self.iface + ' auth'
if self.verbose: print cmd
output = misc.Run(cmd)
else:
output = iwlistauth
authm = misc.RunRegex(authmethods_pattern, output)
authm_list = [m.strip() for m in authm.split('\n') if m.strip()]
return ';'.join(authm_list)
def _get_link_quality(self, output):
""" Parse out the link quality from iwlist scan or iwconfig output. """
try:
@@ -1247,3 +1294,4 @@ class BaseWirelessInterface(BaseInterface):
if network:
network = misc.to_unicode(network)
return network