You are not logged in.

#1 2004-11-04 23:17:20

tezem
Member
Registered: 2004-11-04
Posts: 51
Website

Wlan & LAN dynamic managing Configuration?

Well, I search for a script or something like this to manage 4 possible Internet Connections.
I've got 1 Wlan and 1 LAN Connection at Home and the same on my university. What I want now is to manage these possible connections automatically. When only one Wlan connection is available the proper one should be used, and when there is a Wlan connection and a LAN connection available the LAN connection should be used.
With dynamic or automatically I mean that when I put off my LAN-cable the connection should also switch to Wlan and if I put the cable on again the LAN should be used again. The priority thing in here is unimportant but very nice if it's possible but really important for me is that this dynamic switching of connections is possible without manually do anything. Everything should work at every time from init away. Also important is that when there are two connections available and ready to use these two shouldn't block the other and lead to a nothing works situation.

Hope somebody has an idea about this.

The other thing I would like to know is that I use the init script from there http://wiki.archlinux.org/index.php/Wireless%20setup and it works fine for me but I don't know how to set the wlan profiles in the rc.conf and where when I use the daemon startup.

Offline

#2 2004-11-04 23:25:54

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Wlan & LAN dynamic managing Configuration?

tezem:
if you're using the wireless-profiles script, you're going to want to add WIRELESS_PROFILES=() in rc.conf for WLAN interfaces connected on boot.  The rc.d script is called then.  Calling the script directly allows you to manually switch profiles - for instance, in some WMs you could bind a key combination - let's say Ctrl+Alt+KP_1 calls "/etc/rc.d/wireless profile home up" and Ctrl+Alt+KP_2 calls "/etc/rc.d/wireless profile school up"...

as for the plugged LAn connection - try looking into ifplugd - very useful for laptops.

Offline

#3 2004-11-05 03:13:04

wdemoss
Member
From: WV - USA
Registered: 2004-01-18
Posts: 222

Re: Wlan & LAN dynamic managing Configuration?

for auto connection of an ethernet lan i've uded ifplugd and quickswitch in the past. ifplugd will automatically bring up/down and eth interface on network cable plugging. Quckswitch is done manually, but can handle both eth and wireless devices, automatically bringing connected devices down when you switch between profiles. You can even tell it to unload the wireless driver when you bring down the inteface to save battery.

I'm currently completely wireless and have had great success using wifi_radar. (http://www.bitbuilder.com/wifi_radar/) It switches between wireless profiles farely well.

hth,
wd


Hobbes : Shouldn't we read the instructions?
Calvin : Do I look like a sissy?

Offline

#4 2004-11-05 09:32:54

tezem
Member
Registered: 2004-11-04
Posts: 51
Website

Re: Wlan & LAN dynamic managing Configuration?

Thx for help now everything works like a charm.
I use ifplugd as a switch now. I've set the up and down delay of the ifplugd daemon in the /etc/ifplugd/ifplugd.conf to 0 (zero) to change between the interfaces as fast as possible and it works absolutly flawless with the following changes in the /etc/ifplugd/ifplugd.action but the wireless init script from above is used to bring the wlan interface up and down.
If anybody say for any reason this should be made with another way please say it.

case "$2" in
  up)
    ifup $1
    # ugly way to load up gateway, since
    # al's net configuration doesn't associate
    # gateways with specific interfaces
    /sbin/route add $gateway
    /etc/rc.d/wireless stop # added by me
  ;;
  down)
    ifdown $1
    # same as up...
    /sbin/route del $gateway
    /etc/rc.d/wireless start # added by me
  ;;

Offline

#5 2004-11-05 09:58:01

tezem
Member
Registered: 2004-11-04
Posts: 51
Website

Re: Wlan & LAN dynamic managing Configuration?

@phrakture: Your script is really nice but I would like to see that when I use more than one profiles for the daemon the others which can't be started shouldn't bring up a fail on the init. In my opinion it would be better to make only one status report for all devices so when I have one of them started correctly it should be displayed done otherwise fail.

Offline

#6 2004-11-05 15:14:09

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Wlan & LAN dynamic managing Configuration?

tezem wrote:

@phrakture: Your script is really nice but I would like to see that when I use more than one profiles for the daemon the others which can't be started shouldn't bring up a fail on the init. In my opinion it would be better to make only one status report for all devices so when I have one of them started correctly it should be displayed done otherwise fail.

that sounds like a good idea - to see if i understand correctly:
if WIRELESS_PROFILES=('home' 'school')
on boot at school it tries the home profile, fails, then tries school and succeeds?
i'll work that in there when i get the time

Offline

#7 2004-11-05 17:39:45

tezem
Member
Registered: 2004-11-04
Posts: 51
Website

Re: Wlan & LAN dynamic managing Configuration?

yes this is the idea.

Offline

#8 2005-01-29 18:25:57

tezem
Member
Registered: 2004-11-04
Posts: 51
Website

Re: Wlan & LAN dynamic managing Configuration?

I've changed the script a little bit so it fits my need.
Now it's much faster on starting more than 1 profiles when the first listed in rc.conf isn't the proper one. It should start in O(1) no matter in which position the profile is listed in rc.conf.
I have also changed the fail done and so on status messages so there is not much information about the exact start and stop procedure. Only one done or fail is shown on start and stop.
I have tested this script as good as possible but there could be bugs in there.

I thought also of the feature that the script could automatically join open Wlan Accesspoints if no profile is available but a open AP but I don't think this is of much help because open APs should be really very rare.

Here you can keep a look into the script:
(@phrakture: when you like it update the arch wlan wiki with this script imho it's a fairly good improvement over the original one.)

#!/bin/sh
# ArchLinux Wireless Initialization [http://www.archlinux.org]
# - Aaron Griffin (phrakture) -
# - Thomas Mader (tezem) -

. /etc/rc.conf
. /etc/rc.d/functions

# wireless_up <profile_name>
wireless_up()
{
  if [ ! -f /etc/conf.d/wireless-profiles/${1} ]; then
    echo "Profile [$1] NOT found!"
    return 1
  fi

  . /etc/conf.d/wireless-profiles/${1}
  if [ ! -n "$INTERFACE" ]; then
    echo "Profile [$1] has no interface defined!"
    return 1
  elif [ -f /etc/dhcpc/dhcpcd-${INTERFACE}.pid ]; then
    echo "Interface $INTERFACE already active"
    return 1 
  fi
  

  if [ -n "$ESSID" ]; then
    /usr/sbin/iwconfig $INTERFACE essid $ESSID
  fi

  if [ -n "$MODE" ]; then
    /usr/sbin/iwconfig $INTERFACE mode $MODE
  fi

  if [ -n "$NWID" ]; then
    /usr/sbin/iwconfig $INTERFACE nwid $NWID
  fi

  if [ -n "$FREQ" ]; then
    /usr/sbin/iwconfig $INTERFACE freq $FREQ
  elif [ -n "$CHANNEL" ]; then
    /usr/sbin/iwconfig $INTERFACE channel $CHANNEL
  fi

  if [ -n "$KEY" ]; then
    /usr/sbin/iwconfig $INTERFACE key $KEY
  fi

  if [ -n "$SENS" ]; then
    /usr/sbin/iwconfig $INTERFACE sens $SENS
  fi

  if [ -n "$RATE" ] ; then
    /usr/sbin/iwconfig $INTERFACE rate $RATE
  fi

  if [ -n "$RTS" ]; then
    /usr/sbin/iwconfig $INTERFACE rts $RTS
  fi

  if [ -n "$FRAG" ]; then
    /usr/sbin/iwconfig $INTERFACE frag $FRAG
  fi

  if [ -n "$PARAMS" ]; then
    /usr/sbin/iwconfig $INTERFACE $PARAMS
  fi

  /sbin/ifconfig $INTERFACE up

  if [ "$IFOPTS" = "dhcp" ]; then
    rm -f /etc/dhcpc/dhcpcd-${INTERFACE}.{pid,cache} >/dev/null 2>&1
    /usr/sbin/dhcpcd -t 10 -h $HOSTNAME $INTERFACE
  else
    /sbin/ifconfig $IFOPTS
  fi

  return $?
}

# wireless_down <profile_name>
wireless_down()
{
  if [ ! -f /etc/conf.d/wireless-profiles/${1} ]; then
    echo "Profile [$1] NOT found!"
    return 1
  fi

  . /etc/conf.d/wireless-profiles/${1}

  if [ "$IFOPTS" = "dhcp" ]; then
    if [ -f /etc/dhcpc/dhcpcd-${INTERFACE}.pid ]; then
      /bin/kill `cat /etc/dhcpc/dhcpcd-${INTERFACE}.pid`
    fi
  fi

  /sbin/ifconfig $INTERFACE down

  return $?
}

case "$1" in
  start)
    stat_busy "Starting Wireless Connection"
    for profile in ${WIRELESS_PROFILES[@]}; do
      . /etc/conf.d/wireless-profiles/$profile
      iwlist $INTERFACE scan | grep -q "$ESSID"
      
      if [ $? -eq 0 ]; then
        wireless_up $profile
        if [ $? -eq 0 ]; then
          add_daemon wireless_${profile}
          stat_done
          exit
        fi
      fi
    done
    stat_fail
    ;;
  stop)
    stat_busy "Stopping Wireless Connection"
    for profile in ${WIRELESS_PROFILES[@]}; do
      if ! ck_daemon wireless_${profile}; then
        rm_daemon wireless_${profile}
        wireless_down $profile
        if [ $? -eq 0 ]; then
          stat_done
          exit
        fi
      fi
    done
    stat_fail
    ;;
  restart)
    $0 stop
    sleep 2
    $0 start
    ;;
  profile)
    if [ "$3" = "up" ]; then
      if ! ck_daemon wireless_${2}; then
        echo "Profile [$2] is already up"
      else
        wireless_up $2
        if [ $? -eq 0 ]; then
          add_daemon wireless_${2}
          stat_done
        else
          stat_fail
        fi
      fi
    elif [ "$3" = "down" ]; then
      if ck_daemon wireless_${2}; then
        echo "Profile [$2] is not running"
      else
        wireless_down $2
        if [ $? -eq 0 ]; then
          rm_daemon wireless_${2}
          stat_done
        else
          stat_fail
        fi
      fi
    fi
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"
    echo "usage: $0 profile <profile_name> {up|down}"
    ;;
esac

Offline

#9 2005-01-31 15:55:11

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Wlan & LAN dynamic managing Configuration?

hmmm, yes I like it - I haven't seen much of the changes... have to diff them when I get home... I like the addition of iwlist in there...
good idea

I was also thinking about adding in a prenamed profile "scan" which will just be a bash script in wireless-profiles that scans using iwlist and gets the strongest signal, setting all parameters accordingly...

the scan profile will be included by default, so as to allow a WIRELESS_PROFILES=(scan) setting by default

Offline

#10 2005-01-31 16:10:17

tezem
Member
Registered: 2004-11-04
Posts: 51
Website

Re: Wlan & LAN dynamic managing Configuration?

Yes this would be the idea of the connection to default open Accesspoints but I think this should really only made when none of the "normal" profiles fits because it could be that a open connection doesn't give you the ability to go into the net and so on.
This extra script should also cycle through every AP available beginning at the strongest link testing if a connection is possible and going step by step down until a connection is up and ends if the last one fails. This could take some time on places with many APs so this should really made only if no profile AP is usable.
This would be the very best and I thought of this also but the parsing of the iwlist output with shell commands isn't a simple task for me right now.

Offline

#11 2005-01-31 16:16:34

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Wlan & LAN dynamic managing Configuration?

tezem wrote:

Yes this would be the idea of the connection to default open Accesspoints but I think this should really only made when none of the "normal" profiles fits because it could be that a open connection doesn't give you the ability to go into the net and so on.
This extra script should also cycle through every AP available beginning at the strongest link testing if a connection is possible and going step by step down until a connection is up and ends if the last one fails. This could take some time on places with many APs so this should really made only if no profile AP is usable.
This would be the very best and I thought of this also but the parsing of the iwlist output with shell commands isn't a simple task for me right now.

yeah, I think the quickest way to add this functionality in there is to make profiles.... seeing as they are just sourced scripts.

you could have multiple profiles....
scan-first (connects to the first AP it finds)
scan-strongest (connects to the strongest signal)
etc etc etc

I'll put some thought into it later on

Offline

#12 2005-03-09 14:08:21

tezem
Member
Registered: 2004-11-04
Posts: 51
Website

Re: Wlan & LAN dynamic managing Configuration?

I've made some correction to the script again.
I added some lines in wireless_up() to delete the *.pid file in /etc/dhcpc/ which is there when the machine wasn't halted correctly for some reason.
I think everybody who is using this script realized that the script didn't start correctly on init when the script wasn't able to shutdown the wireless connection. For example this was the case when power blackout was happening and the wireless connection was up at this time.
The *.pid file will only be removed if the dhcp client daemon with the pid, out of the *.pid file isn't running any more.
You can see the hole script at the end of this post.

I don't think I need the automatic scanning for free accessible APs so I will not add this feature until my needs changes.

@phrakture: It would be nice when you could change the script files on your repo so everyone could benefit from the changes.
I would also recommend to add a example for Encryption key entry in the wireless default profile because I had to search to find out how I have to put my key into the profile properly AFAIR. For example you could uncomment the key option and write KEY="s:yourKey" or something like this.

#!/bin/sh
# ArchLinux Wireless Initialization [http://www.archlinux.org]
# - Aaron Griffin (phrakture) -
# - Thomas Mader (tezem) -

. /etc/rc.conf
. /etc/rc.d/functions

# wireless_up <profile_name>
wireless_up()
{
  if [ ! -f /etc/conf.d/wireless-profiles/${1} ]; then
    echo "Profile [$1] NOT found!"
    return 1
  fi

  . /etc/conf.d/wireless-profiles/${1}
  if [ ! -n "$INTERFACE" ]; then
    echo "Profile [$1] has no interface defined!"
    return 1
  # remove *.pid file if machine wasn't halted properly
  elif ! ps -e | grep --file=/etc/dhcpc/dhcpcd-${INTERFACE}.pid >/dev/null 2>&1; then
    if [ -f /etc/dhcpc/dhcpcd-${INTERFACE}.pid ]; then
      rm /etc/dhcpc/dhcpcd-${INTERFACE}.pid
    fi
  elif [ -f /etc/dhcpc/dhcpcd-${INTERFACE}.pid ]; then
    echo "Interface $INTERFACE already active"
    return 1 
  fi
  

  if [ -n "$ESSID" ]; then
    /usr/sbin/iwconfig $INTERFACE essid $ESSID
  fi

  if [ -n "$MODE" ]; then
    /usr/sbin/iwconfig $INTERFACE mode $MODE
  fi

  if [ -n "$NWID" ]; then
    /usr/sbin/iwconfig $INTERFACE nwid $NWID
  fi

  if [ -n "$FREQ" ]; then
    /usr/sbin/iwconfig $INTERFACE freq $FREQ
  elif [ -n "$CHANNEL" ]; then
    /usr/sbin/iwconfig $INTERFACE channel $CHANNEL
  fi

  if [ -n "$KEY" ]; then
    /usr/sbin/iwconfig $INTERFACE key $KEY
  fi

  if [ -n "$SENS" ]; then
    /usr/sbin/iwconfig $INTERFACE sens $SENS
  fi

  if [ -n "$RATE" ] ; then
    /usr/sbin/iwconfig $INTERFACE rate $RATE
  fi

  if [ -n "$RTS" ]; then
    /usr/sbin/iwconfig $INTERFACE rts $RTS
  fi

  if [ -n "$FRAG" ]; then
    /usr/sbin/iwconfig $INTERFACE frag $FRAG
  fi

  if [ -n "$PARAMS" ]; then
    /usr/sbin/iwconfig $INTERFACE $PARAMS
  fi

  /sbin/ifconfig $INTERFACE up

  if [ "$IFOPTS" = "dhcp" ]; then
    rm -f /etc/dhcpc/dhcpcd-${INTERFACE}.{pid,cache} >/dev/null 2>&1
    /usr/sbin/dhcpcd -t 10 -h $HOSTNAME $INTERFACE
  else
    /sbin/ifconfig $IFOPTS
  fi

  return $?
}

# wireless_down <profile_name>
wireless_down()
{
  if [ ! -f /etc/conf.d/wireless-profiles/${1} ]; then
    echo "Profile [$1] NOT found!"
    return 1
  fi

  . /etc/conf.d/wireless-profiles/${1}

  if [ "$IFOPTS" = "dhcp" ]; then
    if [ -f /etc/dhcpc/dhcpcd-${INTERFACE}.pid ]; then
      /bin/kill `cat /etc/dhcpc/dhcpcd-${INTERFACE}.pid`
    fi
  fi

  /sbin/ifconfig $INTERFACE down

  return $?
}

case "$1" in
  start)
    stat_busy "Starting Wireless Connection"

    for profile in ${WIRELESS_PROFILES[@]}; do
      . /etc/conf.d/wireless-profiles/$profile
      if iwlist $INTERFACE scan | grep -q "$ESSID"; then
        wireless_up $profile
        if [ $? -eq 0 ]; then
          add_daemon wireless_${profile}
          stat_done
          exit
        fi
      fi
    done
    stat_fail
    ;;
  stop)
    stat_busy "Stopping Wireless Connection"
    for profile in ${WIRELESS_PROFILES[@]}; do
      if ! ck_daemon wireless_${profile}; then
        rm_daemon wireless_${profile}
        wireless_down $profile
        if [ $? -eq 0 ]; then
          stat_done
          exit
        fi
      fi
    done
    stat_fail
    ;;
  restart)
    $0 stop
    sleep 2
    $0 start
    ;;
  profile)
    if [ "$3" = "up" ]; then
      if ! ck_daemon wireless_${2}; then
        echo "Profile [$2] is already up"
      else
        wireless_up $2
        if [ $? -eq 0 ]; then
          add_daemon wireless_${2}
          stat_done
        else
          stat_fail
        fi
      fi
    elif [ "$3" = "down" ]; then
      if ck_daemon wireless_${2}; then
        echo "Profile [$2] is not running"
      else
        wireless_down $2
        if [ $? -eq 0 ]; then
          rm_daemon wireless_${2}
          stat_done
        else
          stat_fail
        fi
      fi
    fi
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"
    echo "usage: $0 profile <profile_name> {up|down}"
    ;;
esac

Offline

#13 2005-03-09 21:06:52

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Wlan & LAN dynamic managing Configuration?

making changes now, and also incorporating some other changes as well

Offline

Board footer

Powered by FluxBB