mirror of
https://github.com/gryf/wicd.git
synced 2025-12-28 09:22:36 +01:00
Implement iwconfig bitrate setting
This commit is contained in:
@@ -634,7 +634,8 @@ class Wireless(Controller):
|
||||
self.after_script, self.pre_disconnect_script,
|
||||
self.post_disconnect_script, self.global_dns_1,
|
||||
self.global_dns_2, self.global_dns_3, self.global_dns_dom,
|
||||
self.global_search_dom, self.wiface, self.should_verify_ap, debug)
|
||||
self.global_search_dom, self.wiface, self.should_verify_ap,
|
||||
self.bitrate, self.allow_lower_bitrates, debug)
|
||||
self.connecting_thread.setDaemon(True)
|
||||
self.connecting_thread.start()
|
||||
return True
|
||||
@@ -708,6 +709,15 @@ class Wireless(Controller):
|
||||
"""
|
||||
return self.wiface.GetAvailableAuthMethods(iwlistauth)
|
||||
|
||||
def GetAvailableBitrates(self):
|
||||
""" Get the available bitrates for the interface.
|
||||
|
||||
Returns:
|
||||
The available bitrates of the interface as a string, or None if the
|
||||
bitrates can't be found.
|
||||
"""
|
||||
return self.wiface.GetAvailableBitrates()
|
||||
|
||||
def GetIwconfig(self):
|
||||
""" Get the out of iwconfig. """
|
||||
return self.wiface.GetIwconfig()
|
||||
@@ -838,7 +848,7 @@ class WirelessConnectThread(ConnectThread):
|
||||
def __init__(self, network, wireless, wpa_driver, before_script,
|
||||
after_script, pre_disconnect_script, post_disconnect_script,
|
||||
gdns1, gdns2, gdns3, gdns_dom, gsearch_dom, wiface,
|
||||
should_verify_ap, debug=False):
|
||||
should_verify_ap, bitrate, allow_lower_bitrates, debug=False):
|
||||
""" Initialise the thread with network information.
|
||||
|
||||
Keyword arguments:
|
||||
@@ -852,6 +862,8 @@ class WirelessConnectThread(ConnectThread):
|
||||
gdns1 -- global DNS server 1
|
||||
gdns2 -- global DNS server 2
|
||||
gdns3 -- global DNS server 3
|
||||
bitrate -- chosen interface bitrate
|
||||
allow_lower_bitrates -- whether to allow lower bitrates or not
|
||||
|
||||
"""
|
||||
ConnectThread.__init__(self, network, wireless, before_script,
|
||||
@@ -860,7 +872,8 @@ class WirelessConnectThread(ConnectThread):
|
||||
gdns3, gdns_dom, gsearch_dom, wiface, debug)
|
||||
self.wpa_driver = wpa_driver
|
||||
self.should_verify_ap = should_verify_ap
|
||||
|
||||
self.bitrate = bitrate
|
||||
self.allow_lower_bitrates = allow_lower_bitrates
|
||||
|
||||
def _connect(self):
|
||||
""" The main function of the connection thread.
|
||||
@@ -896,6 +909,7 @@ class WirelessConnectThread(ConnectThread):
|
||||
self.stop_wpa(wiface)
|
||||
self.flush_routes(wiface)
|
||||
wiface.SetMode(self.network['mode'])
|
||||
wiface.SetBitrate(self.bitrate, self.allow_lower_bitrates)
|
||||
|
||||
# Put interface up.
|
||||
self.SetStatus('configuring_interface')
|
||||
|
||||
@@ -1029,6 +1029,22 @@ class WirelessDaemon(dbus.service.Object):
|
||||
""" Returns the operational mode for the iwlistauth parameter """
|
||||
return misc.to_unicode(self.wifi.GetAvailableAuthMethods(iwlistauth))
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def GetAvailableBitrates(self):
|
||||
""" Returns the available bitrates the wifi card can use """
|
||||
return self.wifi.GetAvailableBitrates()
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def GetOperableBitrates(self, networkid):
|
||||
""" Returns the real bitrates a connection to a network can use.
|
||||
|
||||
This is the intersection between the bitrates the AP can transmit to,
|
||||
and the bitrates the wireless card can use.
|
||||
"""
|
||||
a = set(self.GetAvailableBitrates())
|
||||
b = set(self.GetWirelessProperty(networkid, 'bitrates'))
|
||||
return sorted(list(a & b), lambda x, y: int(float(x) - float(y)))
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def CreateAdHocNetwork(self, essid, channel, ip, enctype, key, encused,
|
||||
ics):
|
||||
@@ -1157,6 +1173,9 @@ class WirelessDaemon(dbus.service.Object):
|
||||
'predisconnectscript')
|
||||
self.wifi.post_disconnect_script = self.GetWirelessProperty(id,
|
||||
'postdisconnectscript')
|
||||
self.wifi.bitrate = self.GetWirelessProperty(id, 'bitrate')
|
||||
self.wifi.allow_lower_bitrates = self.GetWirelessProperty(id,
|
||||
'allow_lower_bitrates')
|
||||
print 'Connecting to wireless network ' + str(self.LastScan[id]['essid'])
|
||||
# disconnect to make sure that scripts are run
|
||||
self.wifi.Disconnect()
|
||||
|
||||
@@ -36,6 +36,7 @@ import re
|
||||
import random
|
||||
import time
|
||||
from string import maketrans, translate
|
||||
import dbus
|
||||
|
||||
import wpath
|
||||
import misc
|
||||
@@ -49,7 +50,7 @@ channel_pattern = re.compile('.*Channel:?=? ?(\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('(\d+\s+\S+/s)', _re_mode)
|
||||
bitrates_pattern = re.compile('([\d\.]+)\s+\S+/s', _re_mode)
|
||||
mode_pattern = re.compile('.*Mode:([A-Za-z-]*?)\n', _re_mode)
|
||||
freq_pattern = re.compile('.*Frequency:(.*?)\n', _re_mode)
|
||||
wep_pattern = re.compile('.*Encryption key:(.*?)\n', _re_mode)
|
||||
@@ -1113,6 +1114,22 @@ class BaseWirelessInterface(BaseInterface):
|
||||
if self.verbose: print cmd
|
||||
misc.Run(cmd)
|
||||
|
||||
@neediface(False)
|
||||
def SetBitrate(self, bitrate, allow_lower=False):
|
||||
''' Set the desired bitrate for the interface.
|
||||
|
||||
Keyword arguments:
|
||||
bitrate -- desired bitrate (string)
|
||||
allow_lower -- whether to allow lower bitrates, or keep it fixed (bool)
|
||||
'''
|
||||
# FIXME: what if, in future, bitrates won't be "M(egabit per second)"
|
||||
#+anymore?
|
||||
if allow_lower:
|
||||
cmd = 'iwconfig %s rate %sM auto' % (self.iface, bitrate)
|
||||
else:
|
||||
cmd = 'iwconfig %s rate %sM fixed' % (self.iface, bitrate)
|
||||
misc.Run(cmd)
|
||||
|
||||
@neediface(False)
|
||||
def Associate(self, essid, channel=None, bssid=None):
|
||||
""" Associate with the specified wireless network.
|
||||
@@ -1293,9 +1310,14 @@ class BaseWirelessInterface(BaseInterface):
|
||||
ap['channel'] = self._FreqToChannel(freq)
|
||||
|
||||
# Bit Rate
|
||||
ap['bitrates'] = misc.RunRegex(bitrates_pattern,
|
||||
cell.split("Bit Rates")[-1])
|
||||
|
||||
bitrates = cell.split('Bit Rates')[-1].replace('\n', '; ')
|
||||
m = re.findall(bitrates_pattern, bitrates)
|
||||
if m:
|
||||
# numeric sort
|
||||
ap['bitrates'] = sorted(m, lambda x, y: int(float(x) - float(y)))
|
||||
else:
|
||||
ap['bitrates'] = None
|
||||
|
||||
# BSSID
|
||||
ap['bssid'] = misc.RunRegex(ap_mac_pattern, cell)
|
||||
|
||||
@@ -1456,6 +1478,20 @@ class BaseWirelessInterface(BaseInterface):
|
||||
authm_list = [m.strip() for m in authm.split('\n') if m.strip()]
|
||||
return ';'.join(authm_list)
|
||||
|
||||
@neediface('')
|
||||
def GetAvailableBitrates(self):
|
||||
""" Get the available bitrates the wifi card can use. """
|
||||
|
||||
cmd = 'iwlist ' + self.iface + ' rate'
|
||||
if self.verbose: print cmd
|
||||
rates = misc.Run(cmd)
|
||||
|
||||
# process the output
|
||||
rates = rates.split('\n')
|
||||
rates = filter(None, map(lambda x: x.strip().split(' ')[0], rates))
|
||||
rates = filter(lambda x: x[0].isdigit(), rates)
|
||||
return dbus.Array(rates, signature='v')
|
||||
|
||||
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