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?