tags:

views:

584

answers:

3

I'm trying to make a script that sleeps my wireless card in linux. For that I'm using the deepsleep command of iwpriv:

iwpriv wlan0 deepsleep 1

The problem is that this command only works if the wireless card is disconnected and disassociated. When it's connected there is no problem because if I disconnect, it disassociates automatically. But if it's disconnected, sometimes it associates (but not connects) automatically to unencrypted networks, so I cannot run the iwpriv command. The only fix I have found is to change the mode first to Ad-Hoc and then to Managed before sleep the card:

iwconfig wlan0 mode ad-hoc
iwconfig wlan0 mode managed
iwpriv wlan0 deepsleep 1

But I think it's a bit tricky.

Does exist a more direct way to disassociate a wireless card in linux?

A: 

I don't have a fix, but you could try setting the ESSID of the card to a random string and hope that no access points nearby use that ESSID. That should prevent autoconnecting to any unencrypted network found. Not a solution, but maybe a better band-aid.

jvasak
It's something I have tested, and it works in some cards, but not in mine :(Thanks.
Jaime Soriano
A: 

Won't it disassociate if you do ifconfig wlan0 down?

ypnos
No, interface is not up, it's associated, not connected. Thanks.
Jaime Soriano
Most wireless cards must be up before they are associated, and will disassociate when the interface is brought down; no scanning or association will occur while the interface is down. It's pretty reasonable to expect. What chip/driver is yours, that doesn't behave this way?
ephemient
+1  A: 

Many drivers use the convention that associating with the NULL AP disconnects from the current AP. Add to this a brief delay, and you might have what you want. For example,

iwconfig wlan0 ap 00:00:00:00:00:00
sleep 1
iwpriv wlan0 deepsleep 1

Typically, it shouldn't take more than 250-500 milliseconds to disconnect from an AP, but a fractional sleep command (e.g. sleep 0.25) isn't portable.

ctuffli