mirror of
https://github.com/gryf/wicd.git
synced 2025-12-25 07:32:29 +01:00
Starting implementation of current bitrate retrieval
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
""" ioctl Network interface control tools for wicd.
|
||||
|
||||
@@ -479,6 +480,19 @@ 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]
|
||||
try:
|
||||
result = fcntl.ioctl(self.sock.fileno(), SIOCGIWAP, data)[16:]
|
||||
except IOError, e:
|
||||
if self.verbose:
|
||||
print "SIOCGIWAP failed: " + str(e)
|
||||
return ""
|
||||
raw_addr = struct.unpack("xxBBBBBB", result[:8])
|
||||
return "%02X:%02X:%02X:%02X:%02X:%02X" % raw_addr
|
||||
|
||||
def GetSignalStrength(self, iwconfig=None):
|
||||
""" Get the signal strength of the current network.
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
""" networking - Provides wrappers for common network operations
|
||||
|
||||
@@ -624,6 +625,16 @@ class Wireless(Controller):
|
||||
"""
|
||||
return self.wiface.GetBSSID()
|
||||
|
||||
def GetCurrentBitrate(self):
|
||||
""" 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()
|
||||
|
||||
def GetIwconfig(self):
|
||||
""" Get the out of iwconfig. """
|
||||
return self.wiface.GetIwconfig()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
""" wicd - wireless connection daemon implementation.
|
||||
|
||||
@@ -995,6 +996,10 @@ class WirelessDaemon(dbus.service.Object):
|
||||
def GetApBssid(self):
|
||||
return self.wifi.GetBSSID()
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def GetCurrentBitrate(self):
|
||||
return self.wifi.GetCurrentBitrate()
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def CreateAdHocNetwork(self, essid, channel, ip, enctype, key, encused,
|
||||
ics):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
""" Network interface control tools for wicd.
|
||||
|
||||
@@ -59,6 +60,7 @@ 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)
|
||||
|
||||
# Regular expressions for wpa_cli output
|
||||
auth_pattern = re.compile('.*wpa_state=(.*?)\n', __re_mode)
|
||||
@@ -1056,6 +1058,9 @@ class BaseWirelessInterface(BaseInterface):
|
||||
freq = misc.RunRegex(freq_pattern, cell)
|
||||
ap['channel'] = self._FreqToChannel(freq)
|
||||
|
||||
# Bit Rate
|
||||
ap['bitrate'] = misc.RunRegex(bitrate_pattern, cell)
|
||||
|
||||
# BSSID
|
||||
ap['bssid'] = misc.RunRegex(ap_mac_pattern, cell)
|
||||
|
||||
@@ -1180,6 +1185,18 @@ class BaseWirelessInterface(BaseInterface):
|
||||
bssid = misc.RunRegex(bssid_pattern, output)
|
||||
return bssid
|
||||
|
||||
def GetCurrentBitrate(self, iwconfig=None):
|
||||
""" Get the MAC address 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 + 's'
|
||||
|
||||
def _get_link_quality(self, output):
|
||||
""" Parse out the link quality from iwlist scan or iwconfig output. """
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user