#!/bin/bash
#
# hwup-qeth
# $Id: hwup-qeth 1069 2004-09-02 18:23:18Z zoz $
#
# Configuration script for OSA/Express devices
# Sets the portname if configured and 
# sets the adapter online
#

SCRIPTNAME=${0##*/}
HWDESC=$1

# Read in common functions
. ./scripts/functions
test -r ./config && . ./config

if test -z "$SYSFS"; then
    message "sysfs not mounted, aborting."
    exit 1
fi

if [ -z "$DEVPATH" ]; then
    message "no device path given, aborting."
    exit 1
fi

# Read in the configuration file
. ./hwcfg-${HWDESC}

# Set sysfs paths
_ccwgroup_dir=${SYSFS}${DEVPATH}

# Check whether the channel group is configured
message_n "Configuring device ${_ccwgroup_dir##*/}: "
if test -d "$_ccwgroup_dir" ; then
    read _online < $_ccwgroup_dir/online
    # We do not check for the value of CCW_CHAN_MODE, since we
    # might want to switch back and forth between several modes
    if test "$_online" -eq "0" ; then
	# Set the portname
	if [ "$CCW_CHAN_MODE" ]; then
	    message_n "(portname $CCW_CHAN_MODE) "
	    echo "$CCW_CHAN_MODE" > $_ccwgroup_dir/portname
	fi
	# Enable IP address takeover
	if [ "$QETH_IPA_TAKEOVER" ]; then
	    if [ "$QETH_IPA_TAKEOVER" = "1" ]; then
		message_n "(IP takeover) "
		echo 1 > $_ccwgroup_dir/ipa_takeover/enable
	    fi
	fi
	# Set additional options
	if [ "$QETH_OPTIONS" ]; then
	    for opt in $QETH_OPTIONS; do
		saved_IFS="$IFS"
		IFS='='
		set -- $opt
		opt_name=$1
		opt_val=$2
		IFS="$saved_IFS"
		if [ "$opt_name" -a "$opt_val" ]; then
		    case "$opt_name" in
			add_hhlen|broadcast_mode|canonical_macaddr|\
			checksumming|fake_broadcast|fake_ll|\
			priority_queueing|route4|route6|buffer_count)
			    message_n "($opt_name) "
			    echo "$opt_val" > $_ccwgroup_dir/$opt_name
			    ;;
			*)
			    # Skip invalid names
			    ;;
		    esac
		fi
	    done
	fi

	echo "1" > $_ccwgroup_dir/online
	message "ok."
    else
	message "already online."
    fi
else
    message "not available."
fi

#EOF
