automatic client configuration

Frank Thieme frank
Thu May 26 12:40:33 PDT 2005


so, after some reading wlan-ng scripts and initng scripts I hacked
something together to get the same auto configuration feature as wlan-ng
has.

For all the others like me:

in /etc/pcmcia/hostap_cs.conf edit

device "hostap_cs"
   class "network" module "hostap", "hostap_cs"

in 

device "hostap_cs"
   class "wpa_supplicant" module "hostap", "hostap_cs"

That will start /etc/pcmcia/wpa_supplicant instead of
/etc/pcmcia/network on card insert.

now if you followed the wpa_supplicant instructions to insert some lines
in /etc/pcmcia/wireless remove them. wpa_supplicant will be started from
the script

now place the script in /etc/pcmcia 

So things like WEP/WPA will be handles via wpa_supplicant. The script
gets the currently attaeched ssid and sets the pcmcia scheme to include
the ssid. Then /etc/pcmcia/network will be called and you can edit
network.opts to you IP configuration, you even can start your vpn or
such in there.

case "$ADDRESS" in
*SSID,*,*,*)
...

selects the right SSID

have fun...

Bye...Frank

-------------- next part --------------
#! /bin/sh
#

if [ -r ./shared ] ; then . ./shared ; else . /etc/pcmcia/shared ; fi

wlan_usage ()
{
    echo "usage: wpa_supplicant [action] [device name] [debug]"
    echo "  actions: start|resume, stop|suspend, check|cksum|restart"
    echo "  debug  : enables shell debug"
    exit 1
}

wlan_set_ssid_schemefile ()
{
        # $1 == SSID

        # Find the scheme file 
        if [ -r /var/lib/misc/pcmcia-scheme ] ; then
                # Debian
                WLAN_SCHEMEFILE="/var/lib/misc/pcmcia-scheme"
        elif [ -d /var/state/pcmcia ] ; then
                WLAN_SCHEMEFILE="/var/state/pcmcia/scheme"
        elif [ -d /var/lib/pcmcia ] ; then
                WLAN_SCHEMEFILE="/var/lib/pcmcia/scheme"
        else
                WLAN_SCHEMEFILE="/var/run/pcmcia-scheme"
        fi

        # Collect the current scheme name and save the file
        if [ -r $WLAN_SCHEMEFILE ] ; then
                WLAN_SCHEME=`cat $WLAN_SCHEMEFILE`
                cp $WLAN_SCHEMEFILE /tmp/wlan_scheme_`date +"%T"`.tmp
        else
                touch /tmp/wlan_scheme_`date +"%T"`.tmp
                
        fi

        # Set up the <scheme:SSID> string
        if [ ! "$WLAN_SCHEME" ] ; then 
                WLAN_SCHEME="default"
        fi
        WLAN_SCHEME="$WLAN_SCHEME:$1"

        # Write to schemefile
        echo $WLAN_SCHEME > $WLAN_SCHEMEFILE
}

wlan_restore_schemefile ()
{
        # Find the scheme file 
        if [ -r /var/lib/misc/pcmcia-scheme ] ; then
                # Debian
                WLAN_SCHEMEFILE="/var/lib/misc/pcmcia-scheme"
        elif [ -d /var/state/pcmcia ] ; then
                WLAN_SCHEMEFILE="/var/state/pcmcia/scheme"
        elif [ -d /var/lib/pcmcia ] ; then
                WLAN_SCHEMEFILE="/var/lib/pcmcia/scheme"
        else
                WLAN_SCHEMEFILE="/var/run/pcmcia-scheme"
        fi

        TMPFILE=`ls /tmp/wlan_scheme*.tmp | tail -n 1`

        if [ -r $TMPFILE ] ; then
                cat $TMPFILE > $WLAN_SCHEMEFILE
                rm -f $TMPFILE
        else
                ${ECHO} "wlan_restore_schemefile: No wlan_scheme\*.tmp file found."
        fi
}

if [ "$3" = "debug" ]; then set -x ; fi

# If number of args is less than 2 display usage
if [ $# -lt 2 ]; then wlan_usage ; fi

# XXXX we can do stuff with $SCHEME still..?
case "$ACTION" in

'start'|'resume')
	# start supplicant
        /usr/bin/wpa_supplicant -Bw -c/etc/wpa_supplicant.conf \
                -i$DEVICE

	# find ESSID
        for (( i=0; i<5; i++ )); do
                CurESSID=$( /usr/bin/wpa_cli -i$DEVICE status | /usr/bin/sed -n -e 's/^ssid=//p' )
                if [[ -n ${CurESSID} ]]; then
                        echo ${CurESSID}
                        continue 5
                else 
                        sleep 1
		fi
        done

        # stolen from wlan-ng
        # ==========PCMCIA NETDEVICE=============================
        # Append the SSID to the pcmcia scheme name
        wlan_set_ssid_schemefile "${CurESSID}"

        # Call the normal network initialization
        ./network $1 $2
        if [ $? = 1 ] ; then
#               echo "/etc/pcmcia/network $1 $2 failed."
                wlan_restore_schemefile
                exit 1
        fi
        
        # Restore scheme file to it's prior contents
        wlan_restore_schemefile
	;;

'stop'|'suspend')

    	for (( i=0; i<5; i++ )); do
                CurESSID=$( /usr/bin/wpa_cli -i$DEVICE status | /usr/bin/sed -n -e 's/^ssid=//p' )
                if [[ -n ${CurESSID} ]]; then
                        echo ${CurESSID}
                        continue 5
                else 
                        sleep 1
		fi
        done

	killall wpa_supplicant
       
	# stolen from wlan-ng
        # ==========PCMCIA NETDEVICE=============================
        # Append the SSID to the pcmcia scheme name
        wlan_set_ssid_schemefile "${CurESSID}"

        # Call the normal network initialization
        ./network $1 $2
        if [ $? = 1 ] ; then
#               echo "/etc/pcmcia/network $1 $2 failed."
                wlan_restore_schemefile
                exit 1
        fi
        
        # Restore scheme file to it's prior contents
        wlan_restore_schemefile

	;;

'check'|'cksum'|'restart')
	;;

*)
    wlan_usage
    ;;

esac

exit 0



More information about the Hostap mailing list