#!/bin/bash
#
# Configures a IUCV interface.
# $Id: hwup-iucv 1069 2004-09-02 18:23:18Z zoz $
#

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

# Check whether the netiucv module is loaded
_iucv_dir=${SYSFS}/bus/iucv/drivers/netiucv

if [ ! -d "$_iucv_dir" ] ; then
    # Check for older kernels
    _iucv_dir=${SYSFS}/bus/iucv/drivers/NETIUCV
    if [ ! -d "$_iucv_dir" ]; then
	message "IUCV device not initialized !"
	exit 1
    fi
fi

# Check whether this link is already established
for _dev in ${SYSFS}/bus/iucv/devices/*; do
    if [ -d "$_dev" ] ; then
	read _link < $_dev/user
	if test "$_link" = "$HWD_ID" ; then
	    message "IUCV device (link partner $HWD_ID) already established!"
	    HWD_ID=
	    break
	fi
    fi
done

if test -n "$HWD_ID" ; then
    echo "$HWD_ID" > $_iucv_dir/connection

    message "IUCV device (link partner $HW_ID) configured"
fi

# EOF

