You are not logged in.
I have a Dell XPS M1530 with a hardware switch on the side to turn wifi on and off. I learned to access the events of this switch through udev rules (i.e. I can run scripts when the switch is 'on' or 'off') as this switch does not generate acpi events.
I control it through /etc/udev/rules.d/10-rfkill.rules
SUBSYSTEM=="rfkill", ATTR{type}=="wlan", RUN+="/etc/udev/rfkill.sh"
which says to run "/etc/udev/rfkill.sh" (when the switch's positions are switched):
#!/bin/bash
if [ ${RFKILL_STATE} = 2 -o ${RFKILL_STATE} = 0 ]; then
(
/usr/bin/netcfg -a > /home/redscare/netcfgdown
) &
else
(
/usr/bin/netcfg home-wireless-static > /home/redscare/netcfgerrors
) &
fi
When I switch the switch to "off", the file netcfgdown indicates that the network successfully went down. If I switch the switch to "on", netcfgerrors indicates the following:
:: home-wireless-static up [BUSY] > wpa_supplicant did not start, possible configuration error
[FAIL]
If I then manually run "netcfg home-wireless-static", then I get the error:
RTNETLINK answers: File exists
If I finally run it one more time, I successfully connect to the network.
Is there a way to get it to work automatically from the script?
Thanks in advance for any answers.
Offline
net-auto-wireless has such an ability. check wiki
https://wiki.archlinux.org/index.php/Ne … o-wireless
Edit:fixed the link.
Last edited by Coacher (2010-11-20 18:50:47)
I'd rather write my own scripts, so could you tell me how it does this? Thanks.
Last edited by RedScare (2010-11-20 19:26:42)
Offline
Well, as I see you use netcfg so you already have net-auto-wireless. It is documented and well-known utility to suit your needs. KISS.
I agree, but I'm trying to keep the amount of daemons I am running relatively low, and if I do use net-auto-wireless, I have to start 2 additional (battery-life-draining) daemons (net-auto-wireless and wpa_actiond).
Offline
So I caved and decided to use net-auto-wireless, how do I restart on RFKILL? Thanks.
Offline
Sorry, I dont have access to that machine with configured net-auto-wireless for now, but I just followed wiki AFAIR and everything works.
Edit: as soon as get my netbook back I'll provide more info for you.
Last edited by Coacher (2010-11-22 21:59:32)
Thanks, but I did indeed follow the wiki's directions, and I actually looked at the scripts that compose net-auto-wireless, and one of the functions within one of the library files fails if it detects a hardware RFKILL switch...kinda surprising.
If anyone's interested, it's the code that stops the net-auto-wireless daemon.
This happens when /usr/bin/netcfg-wpa_actiond stop is called on the interface, which in turn calls set_rf_state from /usr/lib/network/wireless which fails if RFKILL is set to hardware in the network profile.
Offline
Well. It's quite normal behaviour in case of HARD switch turned off.
Really? It seems like more of a bug. I can't even call '/etc/rc.d/net-auto-wireless stop/restart' - I have to do all the steps manually.
Offline
Hard block cant be controlled using rfkill driver, it can handle only soft blocks. So, if you have a hard block it means for the program that: "yay! device is hardblocked and no way to unlock it. aborting."
Check this pages
http://www.mjmwired.net/kernel/Documentation/rfkill.txt
http://www.mjmwired.net/kernel/Document … ass-rfkill
Did you find the solution? I also own a vaio with an hard switch for the wireless. I tried your script for starting and stopping net-auto-wireless but it just fail!
I'm sure that this is the only way to do that since the switch doesn't launch any acpi event.
Regards
Offline
Well. I got my netbook back and I've tested the behaviour of net-auto-wireless there. True, it doesnt reconnect automatically( Sorry, for my wrong feeling about it. I was sure it does. However, now I'm gonna try both wicd as a network daemon and some kind of udev event handler as you mentioned. I'll post the feedback if anybody still interested.
Well. I tried wicd daemon. Works good, doing autoreconnects if configured to do autoreconnetcs:) However, it is more GUI oriented(has few misc options that are not mentioned in man pages but are available through GUI), and written in python so you'll have to keep it in memory constantly.
Also it is a daemon and in case of OP it will probably eat the battery faster then plain netcfg script.
Thanks all.
I guess in order to figure this out I just need someone to tell me exactly how to bring down ALL aspects of the network after the rfkill switch is switched, and how to bring ALL aspects back up again. This is clearly solveable as the network does indeed work after a few tries outside of the udev script, it's not like rfkill breaks the network driver until restart.
Offline
Thanks all.
I guess in order to figure this out I just need someone to tell me exactly how to bring down ALL aspects of the network after the rfkill switch is switched, and how to bring ALL aspects back up again. This is clearly solveable as the network does indeed work after a few tries outside of the udev script, it's not like rfkill breaks the network driver until restart.
I've edited your script in this way:
#!/bin/bash
if [ ${RFKILL_STATE} = 2 -o ${RFKILL_STATE} = 0 ]; then
(
/etc/rc.d/net-auto-wireless stop > /home/punkeroso/netstop
) &
else
(
/etc/rc.d/net-auto-wireless start > /home/punkeroso/netstart
) &
fi
I really don't understand why the net-auto-wireless doesn't start. It simply says FAIL, while if I launch It from the shell It goes flawlessly.
I tried also removing all modules needed by the wireless card to work and loading It again before the start command, but this commands simply doesn't work; they don't remove or load any module...
Offline
In this way the interface is actually brought up:
#!/bin/bash
if [ ${RFKILL_STATE} = 2 -o ${RFKILL_STATE} = 0 ]; then
(
/etc/rc.d/net-auto-wireless stop > /home/punkeroso/netstop
) &
else
(
/sbin/ifconfig wlan0 up
) &
fi
So, i think that the problem is launching a bash script from another bash script, which net-auto-wireless and netcfg are...
Offline
I really don't understand why the net-auto-wireless doesn't start. It simply says FAIL, while if I launch It from the shell It goes flawlessly.
I tried also removing all modules needed by the wireless card to work and loading It again before the start command, but this commands simply doesn't work; they don't remove or load any module...
check 'env' within a terminal
have the script output the 'env' to a file and read it later.
im almost sure there is something amiss... maybe the PATH, SHELL, TERM, HOME variables need to be set, if this is the case, i dont know how to fix it properly ....
maybe try and source /etc/profile.d/* at the begining of the script
hope i helped
Offline
I really don't understand why the net-auto-wireless doesn't start. It simply says FAIL, while if I launch It from the shell It goes flawlessly.
I tried also removing all modules needed by the wireless card to work and loading It again before the start command, but this commands simply doesn't work; they don't remove or load any module...check 'env' within a terminal
have the script output the 'env' to a file and read it later.
im almost sure there is something amiss... maybe the PATH, SHELL, TERM, HOME variables need to be set, if this is the case, i dont know how to fix it properly ....
maybe try and source /etc/profile.d/* at the begining of the script
hope i helped
You where right!!
Now the script works flawlessly:
#!/bin/bash
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/lib/perl5/core_perl/bin
if [ ${RFKILL_STATE} = 2 -o ${RFKILL_STATE} = 0 ]; then
/etc/rc.d/net-auto-wireless stop
else
/etc/rc.d/net-auto-wireless start
fi
Many thanks!
Offline