Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] How to start wpa_supplicant on rfkill switch flip?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
Etal
Veteran
Veteran


Joined: 15 Jul 2005
Posts: 1932

PostPosted: Fri Sep 10, 2010 11:29 pm    Post subject: [SOLVED] How to start wpa_supplicant on rfkill switch flip? Reply with quote

Hi everyone,

My laptop has a switch that controls the wireless, and when I don't need it, I like to turn it off. However, the problem is that when I turn it back on, I need to restart wpa_supplicant.

So my question is, is there a way to trigger a script when I flip the switch, like with ACPI events?

Thanks in advance!


Last edited by Etal on Sat Sep 11, 2010 9:11 pm; edited 1 time in total
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3943
Location: Hamburg

PostPosted: Sat Sep 11, 2010 6:54 am    Post subject: Reply with quote

Switching that key should give an ACPI event which can be processed in /etc/acpi/defaults.sh.
Back to top
View user's profile Send private message
Etal
Veteran
Veteran


Joined: 15 Jul 2005
Posts: 1932

PostPosted: Sat Sep 11, 2010 3:55 pm    Post subject: Reply with quote

Nope, it gets logged, but not due to ACPI:

Code:
logger: ACPI event unhandled: video/brightnessdown BRTDN 00000087 00000000
klogd: iwlagn 0000:03:00.0: RF_KILL bit toggled to enable radio.
klogd: usb 1-1.4: new full speed USB device using ehci_hcd and address 11
klogd: iwlagn 0000:03:00.0: RF_KILL bit toggled to disable radio.
klogd: usb 1-1.4: USB disconnect, address 11


(It's not a keyboard button, it's a physical switch)
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3943
Location: Hamburg

PostPosted: Sat Sep 11, 2010 4:16 pm    Post subject: Reply with quote

AM088 wrote:
[code]video/brightnessdown BRTDN 00000087 00000000
This can be used in the ACPI script, isn't it ?
Back to top
View user's profile Send private message
Etal
Veteran
Veteran


Joined: 15 Jul 2005
Posts: 1932

PostPosted: Sat Sep 11, 2010 4:35 pm    Post subject: Reply with quote

toralf wrote:
AM088 wrote:
[code]video/brightnessdown BRTDN 00000087 00000000
This can be used in the ACPI script, isn't it ?


No, that's the brightness-down which gets caught by ACPI. I put it there for contrast with the rfkill event - flipping the switch on and off (the other 4 lines) gets caught by syslog, but there is no ACPI event.
Back to top
View user's profile Send private message
Etal
Veteran
Veteran


Joined: 15 Jul 2005
Posts: 1932

PostPosted: Sat Sep 11, 2010 8:37 pm    Post subject: Reply with quote

Well, turns out hardware events are handles by a piece of software called udev. Who would have known? :P

After reading Daniel Drakes udev rules guide, I came up with a solution which somewhat works.

In /etc/udev/rules.d/, I created a file:
/etc/udev/rules.d/40-rfkill.rules:
SUBSYSTEM=="rfkill", ATTR{type}=="wlan", RUN+="/etc/udev/rfkill.sh"


and the corresponding script (mode 755): Edit: this script is wrong. See fixed one below
/etc/udev/rfkill.sh:
#!/bin/bash
if [ "${RFKILL_STATE}" == 2 ]; then
        /etc/init.d/wpa_supplicant stop
else
        /etc/init.d/wpa_supplicant start
fi


The only problem is that for some reason, every time I flip the switch, two seemingly identical events fire off. When turning off, they both have $RFKILL_STATE equal to 2, but when I turn it off, one has 0 and the other has 1, which is why I check only for the "2". The problem is that things get wierd if I use software rfkill, but I don't really need to do that.


Last edited by Etal on Sat Sep 11, 2010 9:07 pm; edited 1 time in total
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3943
Location: Hamburg

PostPosted: Sat Sep 11, 2010 8:44 pm    Post subject: Reply with quote

Wel, with a ThinkPad it is much easier b/c it has an ACPI event for that:
Code:
logger: ACPI event : ibm/hotkey HKEY 00000080 00007000
Back to top
View user's profile Send private message
Etal
Veteran
Veteran


Joined: 15 Jul 2005
Posts: 1932

PostPosted: Sat Sep 11, 2010 9:06 pm    Post subject: Reply with quote

Actually this is a ThinkPad, a T410 :)
There is an ACPI event on Fn+F5 (which does a software-block), but not the little switch on the side.

Also, after reading through some documentation, I found out that the "normal" RFKILL_STATE is "1", while "0" is software-blocked, and "2" is hardware-blocked.

So the fixed script which works with both soft ahnd hard blocks is:
/etc/udev/rfkill.sh:
#!/bin/bash
if [ "${RFKILL_STATE}" == 1 ]; then
        /etc/init.d/wpa_supplicant start
else # state is 0 or 2
        /etc/init.d/wpa_supplicant stop
fi


Now, on to discover more cool things to do with udev :D
Back to top
View user's profile Send private message
DONAHUE
Watchman
Watchman


Joined: 09 Dec 2006
Posts: 7651
Location: Goose Creek SC

PostPosted: Wed Sep 15, 2010 6:45 pm    Post subject: Reply with quote

THANKS AM088
Back to top
View user's profile Send private message
Etal
Veteran
Veteran


Joined: 15 Jul 2005
Posts: 1932

PostPosted: Wed Sep 15, 2010 8:23 pm    Post subject: Reply with quote

Glad it helped someone else :D
Back to top
View user's profile Send private message
mamac
l33t
l33t


Joined: 29 Feb 2004
Posts: 890

PostPosted: Tue Aug 16, 2011 8:24 pm    Post subject: Reply with quote

Etal,

How do you got that ${RFKILL_STATE} variable field with a value?

I can see the value in /sys/class/rfkill/rfkill0/uevent, but still this variable is blank here...
_________________
Powered by Gentoo Linux since 2003
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum