Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix a multitude of problems in set_scheme_manual.

When waiting for a wireless connection: loop until iwconfig shows us
actually connected.
Don't do wireless stuff for wired connections.
Catch the mysterious error where the /sys/class device file sometimes
isn't there (may related to switching between wired/wireless?)
Fix a few code factoring errors (modules not loaded).
Add a comment explaining that the misleading Connection class isn't used.
  • Loading branch information...
commit 56b5fe41776f2fbf1ca418a4618338f847af777c 1 parent 3df50d0
Akkana Peck authored
Showing with 33 additions and 9 deletions.
  1. +22 −3 netscheme
  2. +11 −6 netutils.py
25 netscheme
View
@@ -168,7 +168,9 @@ auto %s""" % (iface.name)
print "Calling ifconfig up"
iface.ifconfig_up()
- if self.encryption == "wep" or self.encryption == "open" :
+ if not iface.wireless :
+ pass
+ elif self.encryption == "wep" or self.encryption == "open" :
# iwconfig doesn't work reliably on some systems unless you
# specify the MAC address of the accesspoint.
# However, this code isn't working on Pangolin, not sure why,
@@ -203,7 +205,7 @@ auto %s""" % (iface.name)
#iwargs.append("off")
iwargs.append("channel")
iwargs.append("auto")
- print "Calling", iwargs
+ print "===== Calling", iwargs
subprocess.call(iwargs)
print "Called iwconfig: now it says"
@@ -222,12 +224,29 @@ key_mgmt=WPA-PSK
psk="%s"
}""" % (self.essid, self.key)
tempfp.close()
+ print "Calling wpa_supplicant -Dwext -i", iface.name, "-c", tempname
subprocess.Popen(["wpa_supplicant", "wpa_supplicant",
"-Dwext", "-i", iface.name, "-c", tempname])
# Is 1 second long enough for wpa_supplicant to open the file?
# 2 might be safer. What a drag.
+ # Or maybe we shouldn't unlink it at all.
+ #time.sleep(2)
+ #os.unlink(tempname)
+
+ # Wait for a connection:
+ while iface.wireless :
+ proc = subprocess.Popen(["iwconfig", iface.name],
+ stdout=subprocess.PIPE)
+ line = proc.communicate()[0].split('\n')[0]
+ essidpos = line.find('ESSID:')
+ if essidpos >= 0 :
+ bound = line[essidpos+6:].strip().strip('"')
+ # strip leading/trailing spaces first, then double quotes
+ if bound == self.essid :
+ print "We made it! Bound to", self.essid
+ break
+ print "Not bound to %s yet: '%s' (%s)" % (self.essid, bound, line)
time.sleep(2)
- os.unlink(tempname)
if self.dhcp :
print "Getting dhcp"
17 netutils.py
View
@@ -14,6 +14,8 @@
NetInterface: name, ip, broadcast, netmask, essid, encryption, wireless
AccessPoint : address, essid, encryption, quality, interface
Route : display or change network routing tables.
+ There's also a Connection class but it's just experimental,
+ not currently used.
Functions outside of classes:
get_interfaces(only_up=False): returns a list of all NetInterface.
@@ -25,7 +27,7 @@
of the names in namelist. Return a list of actual process names killed.
"""
-import os, subprocess, re, shutil
+import sys, os, subprocess, re, shutil
class NetInterface :
"""A network interface, like eth1 or wlan0."""
@@ -70,11 +72,12 @@ def reload(self) :
try :
# Sometimes the device doesn't exist. I have no idea why.
fp = open("/sys/class/net/" + self.name + "/device/uevent")
+ # Another way to get this: ethtool -i self.name
except :
- print "Couldn't open device /sys/class/net/" + self.name
- sys.exit(0)
+ print "Not resetting: couldn't open device /sys/class/net/" \
+ + self.name
+ return
- # Another way to get this: ethtool -i self.name
line = fp.readline()
fp.close()
if line[0:7] == "DRIVER=" :
@@ -111,7 +114,8 @@ def connect(self, essid):
"""Connect to a particular essid doing all the steps manually.
Pass essid=None to de-associate the interface from any essid.
"""
- netutils.ifdown_all()
+ print "==== ManualConnection: connect", essid
+ ifdown_all()
iface.ifconfig_up()
@@ -126,7 +130,8 @@ def connect(self, essid):
iwargs.append("off")
iwargs.append("enc")
iwargs.append("off")
-
+
+ print "==== Calling", iwargs
subprocess.call(iwargs)
# Check whether we succeeded -- don't bother calling DHCP
Please sign in to comment.
Something went wrong with that request. Please try again.