Wireless Network Setup for my iBook in Debian


There are many ways to setup your wireless network; here is how I do mine under Debian.

Firstly you want the wireless-tools package so you have iwconfig and the dialog package so you have dialog.

Secondly, create a file /etc/defaults/wireless with a template below.  Each profile for a wireless network you wish to connect to should have an entry in the WIRELESS_PROFILES variable, and then a series of variables that describe the wireless network configuration.

/etc/defaults/wireless
#WIRELESS OPTIONS
 
WIRELESS_DEVICE=eth1
WIRELESS_PROFILES="home cse noid"
 
home_NAME="home"
home_ESSID="your.essid"
home_RATE="auto"
home_NICK="mingus"
home_MODE="Managed"
home_KEY="your.wep.key"
home_DESCR="At Home"
 
cse_NAME="cse"
cse_ESSID="CSE_wireless"
cse_RATE="auto"
cse_NICK="mingus"
cse_MODE="Ad-Hoc"
cse_DESCR="CSE Wireless"
 
noid_NAME="noid"
noid_ESSID="off"
noid_RATE="auto"
noid_NICK="mingus"
noid_MODE="Ad-Hoc"
noid_DESCR="No ESSID/WAP KEY"


Next, add two scripts to /usr/local/bin.  Make sure you chmod +x them!

/usr/local/bin/init_wireless
#!/bin/bash -x

PATH=/sbin/

if [ $# -ne 1 ] ; then
    echo Please specify your location
    exit 0
fi

if [ -f /etc/default/wireless ] ; then
    . /etc/default/wireless
else
    echo Please setup /etc/default/wireless
    exit 0
fi

ESSID_VAR=$1_ESSID ; ESSID=${!ESSID_VAR}
RATE_VAR=$1_RATE ; RATE=${!RATE_VAR}
NICK_VAR=$1_NICK ; NICK=${!NICK_VAR}
MODE_VAR=$1_MODE ; MODE=${!MODE_VAR}
KEY_VAR=$1_KEY; KEY=${!KEY_VAR}
CHANNEL_VAR=$1_CHANNEL; CHANNEL=${!CHANNEL_VAR}

echo Setting nick $NICK mode $MODE rate $RATE essid $ESSID channel $CHANNEL on $WIRELESS_DEVICE

if [ $NICK ] ; then
    iwconfig $WIRELESS_DEVICE nick  $NICK
fi

if [ $MODE ] ; then
    iwconfig $WIRELESS_DEVICE mode  $MODE
fi

if [ $RATE ] ; then
    iwconfig $WIRELESS_DEVICE rate  $RATE
fi

if [ $ESSID ] ; then
    iwconfig $WIRELESS_DEVICE essid $ESSID
fi

if [ $CHANNEL ] ; then
	iwconfig $WIRELESS_DEVICE channel $CHANNEL
fi

if [ $KEY ] ; then  
	iwconfig $WIRELESS_DEVICE key $KEY
else
	iwconfig $WIRELESS_DEVICE key off
fi


You can obviously rename this if your wireless card comes up as something other than eth1.

/usr/local/bin/eth1-mapping
#!/bin/bash


if [ -f /etc/default/wireless ] ; then
    . /etc/default/wireless
else
    echo Please setup /etc/default/wireless
    exit 0
fi

for profile in $WIRELESS_PROFILES
do
  LOCATION_NAME=$profile\_NAME
  LOCATION_DESCR=$profile\_DESCR

  DIALOG_ARGS="$DIALOG_ARGS \"${!LOCATION_NAME}\" \"${!LOCATION_DESCR}\""
done

rm -f /tmp/eth1-tmp

LOCATION=`eval dialog --stdout --menu \"Select your wireless location\" 10 50 5 $DIALOG_ARGS`

echo eth1-$LOCATION

The final component is the eth1 stanza in /etc/network/interfaces.  For each of the names defined in the /etc/defaults/wireless file, add a map entry under the mapping section of the file.  Then for each map entry, add an iface entry that describes the environment.  Use a pre-up command to the init_wireless script with the name as the only argument (get all that?).

The premise is that ifup will call the script, which will present you with a dialog interface to choose your environment.  This echos out it's result, which is matched against the first argument of the map line.  When a match is found, the iface section that is the second argument of the map line gets called to configure the interface.  The pre-up script uses iwconfig to setup the correct paramaters for the wirless network.

eth1 section of /etc/network/defaults
mapping eth1
        script /usr/local/bin/eth1-mapping
        map home eth1-home
        map cse eth1-cse
        map noessid eth1-noessid
 
iface eth1-home inet dhcp
        pre-up /usr/local/bin/init_wireless home
iface eth1-cse inet dhcp
        pre-up /usr/local/bin/init_wireless cse
iface eth1-noid inet dhcp
        pre-up /usr/local/bin/init_wireless noid

If all went to plan, you should be presented with a dialog interface when you ifup eth1 like below

eth1 dialog interface

That's it!

ianw@ieee.org

Scripts © Ian Wienand 2003 but feel free to do what you want with them