#!/bin/sh
#
# wireless network 1.63 2000/02/09 03:12:42 (David Hinds/Jean Tourrilhes)
#
# Specific configuration of a PCMCIA wireless LAN adapter
#
# This script is invoked automatically by the network script; it should
# not be executed by hand.
#
# Note : it would be real cool to have the name of the driver as part
# of the extended device address
#

if [ `basename $0` != 'network' ] ; then
    echo "Invalid invocation: this script should not be executed directly"
    exit 1
fi

# Load site-specific settings
if [ -r ./wireless.opts ] ; then
    . ./wireless.opts
else
    . /etc/pcmcia/wireless.opts
fi

# Find the path where wireless tools are installed
for IWPATH in /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin /sbin ; do
    if [ -x $IWPATH/iwconfig ] ; then break ; fi
done

case "$ACTION" in

'start')
    [ -n "$VERBOSE" -a -n "$INFO" ] && echo "$INFO"
    # Set all desired settings via iwconfig

    # Mode need to be first : some settings apply only in a specific mode !
    if [ -n "$MODE" ] ; then
	log $IWPATH/iwconfig $DEVICE mode $MODE
    fi
    # This is a bit hackish, but should do the job right...
    if [ ! -n "$NICKNAME" ] ; then
        NICKNAME=`/bin/hostname`
    fi
    if [ -n "$ESSID" -o -n "$MODE" ] ; then
	log $IWPATH/iwconfig $DEVICE nick \"$NICKNAME\" >/dev/null 2>&1
    fi
    # Regular stuff...
    if [ -n "$NWID" ] ; then
	log $IWPATH/iwconfig $DEVICE nwid $NWID
    fi
    if [ -n "$FREQ" ] ; then
	log $IWPATH/iwconfig $DEVICE freq $FREQ
    elif [ -n "$CHANNEL" ] ; then
	log $IWPATH/iwconfig $DEVICE channel $CHANNEL
    fi
    if [ -n "$SENS" ] ; then
	log $IWPATH/iwconfig $DEVICE sens $SENS
    fi
    if [ -n "$RATE" ] ; then
	log $IWPATH/iwconfig $DEVICE rate $RATE
    fi
    if [ -n "$KEY" ] ; then
	log $IWPATH/iwconfig $DEVICE key $KEY
    fi
    if [ -n "$RTS" ] ; then
	log $IWPATH/iwconfig $DEVICE rts $RTS
    fi
    if [ -n "$FRAG" ] ; then
	log $IWPATH/iwconfig $DEVICE frag $FRAG
    fi
    # More specific parameters
    if [ -n "$IWCONFIG" ] ; then
	log $IWPATH/iwconfig $DEVICE $IWCONFIG
    fi
    if [ -n "$IWSPY" ] ; then
	log $IWPATH/iwspy $DEVICE $IWSPY
    fi
    if [ -n "$IWPRIV" ] ; then
	log $IWPATH/iwpriv $DEVICE $IWPRIV
    fi
    # ESSID need to be last : most device re-perform the scanning/discovery
    # when this is set, and things like encryption keys are better be
    # defined if we want to discover the right set of APs/nodes.
    if [ -n "$ESSID" ] ; then
	log $IWPATH/iwconfig $DEVICE essid \"$ESSID\"
    fi
    ;;

'cksum')
    chk_simple "$NEW_SCHEME,$SOCKET,$INSTANCE,$HWADDR"
    WIRELESS=$?
    ;;

'stop'|'check'|'restart'|'suspend'|'resume')
    ;;

*)
    usage
    ;;

esac
