You are not logged in.

#1 2010-11-20 18:44:46

RedScare
Member
Registered: 2009-03-28
Posts: 91

Restarting network connection with RFKILL switch

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

#2 2010-11-20 18:48:46

Coacher
Guest

Re: Restarting network connection with RFKILL switch

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)

#3 2010-11-20 19:26:31

RedScare
Member
Registered: 2009-03-28
Posts: 91

Re: Restarting network connection with RFKILL switch

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

#4 2010-11-20 19:35:36

Coacher
Guest

Re: Restarting network connection with RFKILL switch

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.

#5 2010-11-20 19:39:52

RedScare
Member
Registered: 2009-03-28
Posts: 91

Re: Restarting network connection with RFKILL switch

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

#6 2010-11-21 05:17:39

RedScare
Member
Registered: 2009-03-28
Posts: 91

Re: Restarting network connection with RFKILL switch

So I caved and decided to use net-auto-wireless, how do I restart on RFKILL? Thanks.

Offline

#7 2010-11-22 20:55:55

Coacher
Guest

Re: Restarting network connection with RFKILL switch

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)

#8 2010-11-23 02:26:06

RedScare
Member
Registered: 2009-03-28
Posts: 91

Re: Restarting network connection with RFKILL switch

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

#9 2010-11-23 19:52:18

Coacher
Guest

Re: Restarting network connection with RFKILL switch

Well. It's quite normal behaviour in case of HARD switch turned off.

#10 2010-11-23 23:27:11

RedScare
Member
Registered: 2009-03-28
Posts: 91

Re: Restarting network connection with RFKILL switch

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

#11 2010-11-23 23:47:35

Coacher
Guest

Re: Restarting network connection with RFKILL switch

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

#12 2010-11-26 00:00:58

punkeroso
Member
From: Rome, Italy
Registered: 2007-01-19
Posts: 105

Re: Restarting network connection with RFKILL switch

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

#13 2010-11-27 13:35:32

Coacher
Guest

Re: Restarting network connection with RFKILL switch

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.

#14 2010-11-27 15:28:36

Coacher
Guest

Re: Restarting network connection with RFKILL switch

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.

#15 2010-11-27 17:37:24

RedScare
Member
Registered: 2009-03-28
Posts: 91

Re: Restarting network connection with RFKILL switch

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

#16 2010-11-28 09:30:05

punkeroso
Member
From: Rome, Italy
Registered: 2007-01-19
Posts: 105

Re: Restarting network connection with RFKILL switch

RedScare wrote:

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

#17 2010-11-28 14:13:22

punkeroso
Member
From: Rome, Italy
Registered: 2007-01-19
Posts: 105

Re: Restarting network connection with RFKILL switch

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

#18 2010-11-28 23:34:18

eldragon
Member
From: Buenos Aires
Registered: 2008-11-18
Posts: 1,029

Re: Restarting network connection with RFKILL switch

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

#19 2010-11-29 16:47:52

punkeroso
Member
From: Rome, Italy
Registered: 2007-01-19
Posts: 105

Re: Restarting network connection with RFKILL switch

eldragon wrote:

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

Board footer

Powered by FluxBB