rockymeza/wifi

Scheme.activate() hangs

Opened this issue · 9 comments

Whenever I run scheme.activate() it never completes. The program will just hang with no output and I don't connect to the wifi network. I tried with several different schemes (with and wtihout passkeys) and was unable to figure this out.

I get this as well:

  • Ubuntu 14.04
  • Wifi 0.3.4 installed from pip
  • Python 2.7.6

With code:

scheme = Scheme.for_cell("wlan0", "name", current_cell, current_settings['password'])
scheme.save()
scheme.activate()

The process continues to hang. If I run ifdown wlan and then ifup wlan=wlan-name then it will not work either with the following output:

$ /etc/network$ sudo /sbin/ifup wlan0=wlan0-name
wpa_supplicant: /sbin/wpa_supplicant daemon failed to start
run-parts: /etc/network/if-pre-up.d/wpasupplicant exited with return code 1
Internet Systems Consortium DHCP Client 4.2.4
Copyright 2004-2012 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlan0/a0:f3:c1:45:65:6e
Sending on   LPF/wlan0/a0:f3:c1:45:65:6e
Sending on   Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 3 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 3 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 6 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 13 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 15 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 15 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 20 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 9 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 11 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 11 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 11 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 14 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 14 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 12 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 8 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 12 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 15 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 13 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 19 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 20 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 9 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 15 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 14 (xid=0x4d442c13)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 12 (xid=0x4d442c13)
No DHCPOFFERS received.
No working leases in persistent database - sleeping.

Noticeably, there is an error there that I will investigate further: wpa_supplicant: /sbin/wpa_supplicant daemon failed to start

I've resolved this by stopping Network Manager from managing the wlan0 device - I hadn't realised that it was.

To do this I updated /etc/network/interfaces with:

auto wlan0

And then restarted Network Manager with:

sudo service network-manager restart

Not sure if there are any ramifications of this yet. There doesn't seem to be a way of disconnecting from a wireless network on the Python API yet, if I save() and delete() the config, the connection persists. Am I right about this?

Thanks

Hi balone1988,

Thank you for looking into this. Having both network manager and wifi
running at the same time is not recommended, as network manager will try to
take over.

You are right that currently there is no way to disconnect from python.
Please see the other issues for work that's being done on that front.

-rocky
2015年3月31日 上午10:56于 "balone1988" notifications@github.com写道:

I've resolved this by stopping Network Manager from managing the wlan0
device - I hadn't realised that it was.

To do this updated /etc/network/interfaces with:

auto wlan0

And then restarted Network Manager with:

sudo service network-manager restart

Not sure if there are any ramifications out of this yet. There doesn't
seem to be a way of disconnecting from a wireless network on the Python API
yet, if I save() and delete() the config, the connection persists. Am I
right about this?

Thanks


Reply to this email directly or view it on GitHub.

Hi Rocky,

I've just tested deleting the config using scheme.delete() and whilst this does delete the configuration from the /etc/networks/interfaces file, it leaves the connection active.

Once this has happened, it's hard to disconnect as ifdown wlan0 no longer knows about the connection.

I'll look forward to a disconnect() function being added like you said.

Thanks!

@balone1988, do you want to test the disconnect command from #58?

It doesn't seem to work on my computer, but maybe it does on yours.

@rockymeza I am still facing issues with the scheme.activate() hanging up. I followed @balone1988 's method but to no effect.

I am currently on Ubuntu 14.04 and using python 2.7. Could you kindly point me towards any possible solution? For your reference, Upon pressing Ctrl+C I get the following message:

line 41, in
scheme.activate()
File "/usr/local/lib/python2.7/dist-packages/wifi/scheme.py", line 173, in activate
ifup_output = subprocess.check_output(['/sbin/ifup'] + self.as_args(), stderr=subprocess.STDOUT)
File "/usr/lib/python2.7/subprocess.py", line 567, in check_output
output, unused_err = process.communicate()
File "/usr/lib/python2.7/subprocess.py", line 791, in communicate
stdout = _eintr_retry_call(self.stdout.read)
File "/usr/lib/python2.7/subprocess.py", line 476, in _eintr_retry_call
return func(*args)

can you do the following:

>>> print ' '.join(['/sbin/ifup'] + scheme.as_args())

and then run what it prints in a shell to see the output?

I am having the same issue as jainakshay91
when I replace scheme.activate() with the line above I get this output:
/sbin/ifup wlo1=wlo1-globalmanufacturing guest -o wpa-psk=25968eb2233d064cfcba2626522ed59e3e92821d9329b51fdcadc3fe5167a8cf -o wpa-ssid=globalmanufacturing guest -o wireless-channel=auto
this information is also appended to /etc/network/interfaces.

copy and pasting the return into the shell without clearing out /etc/networking/interfaces file i get this:
/etc/network/interfaces:5: unknown or no address type and no inherits keyword specified /sbin/ifup: couldn't read interfaces file "/etc/network/interfaces"

If I clear out all the appendments from /etc/networking/interfaces then I get this as the return:
Unknown interface wlo1-globalmanufacturing Unknown interface guest Unknown interface guest
I think it may be a formatting issue because there is a space in the network name.

wlo1 is my wireless interface I am not sure if it should be formatting it into the network name like this wlo1=wlo1-globalmanufacturing guest just because I would expect the proper formatting to be wlo1=globlamanufacturing\ guest am I making incorrect assumptions?

I have kinda hit my a wall in troubleshooting it so if you have any ideas please let me know and I will poke and prod at it some more to see if I can get it working proper.

here is my current attempt at getting things to work

`###Imports###
from wifi import Cell, Scheme
import getpass

###Global Declarations###
interface = 'wlo1'

###uses wifi library to sniff all of the available Wifi networks in range and connect to a selected network###
cells = Cell.all(interface)

print"\n-------AVAILABLE NETWROKS-------\n\n#: \tName:\n"

for index, elem in enumerate(cells):
print str(index),"\t", str(elem)[10:-1]

NetNum = input("\nPlease enter the number of the network you would like to connect to. \nNetwork Number: ")

NetName = str(cells[NetNum])[10:-1]
#print NetName

NetPass = getpass.getpass('\nPlease enter the passphrase for this network.\nPassphrase: ')
#print NetPass

NetSelect = Cell.all(interface)[NetNum]
scheme = Scheme.for_cell(interface, NetName, NetSelect, NetPass)
scheme.save()
#print ' '.join(['/sbin/ifup'] + scheme.as_args())
scheme.activate()`

I am runnign Kubuntu 16.04