#! /usr/bin/ksh
#
# @(#)u4ft_validateFRU.sh	1.7	98/07/06 SMI
#
# Copyright (c) 1998, by Sun Microsystems, Inc.
# All rights reserved.
#
# u4ft_validateFRU name number location
#
# Purpose:      To validate that a FRU is present in the given slot, that the
#		EEPROM can be read, that the FRU is of the same class as the
#		cmsdef, and that the FRU is compatable with the motherboard
#		and any other required/related FRU's.
# Result:       If the command succeeded, the Device busy lock will be unset.
#               If the command failed due to invalid arguments, device busy,
#               the request not valid or another, a message will be reported
#               to the status log and the Device busy lock will be unset.
#
# Mandatory Parameters
# name         - class name of FRU
# number       - instance number of FRU
# location     - location of FRU
#
#
# Error Codes:
# Return 0 on success, non-zero otherwise
#

# Check that three arguments have been given
if [[ $# -ne 3 ]]
then
        cmsdebug "u4ft_validateFRU: wrong no. of args $1 $2 $3"
	exit 1
fi

name="$1"
number="$2"
location="$3"

# Validate the FRU eeprom and interpret its results
cmscheckfru -l $location -c $name;
result=$?;
if [[ $result -ne 0 ]]
then
	cmsdebug "cmscheckfru -l $location -c $name failed"
	case $result in
	1)   cmslog 2 "$name $number in $location not found"
	     cmsreport $name $number present no
	     cmsreport $name $number info "FRU not found in $location"
	     ;;
	2)   cmsreport $name $number faulty yes
	     cmsledctl -l $location -n
	     cmslog 2 "$name $number in $location has previous fault"
	     cmsreport $name $number present yes
	     cmsreport $name $number info \
		"FRU in $location has a previous fault"
	     exit 0
	     ;;
	3)   cmslog 2 "$name $number in $location not correct FRU class"
	     cmsreport $name $number present no
	     cmsreport $name $number info \
		"FRU in $location is not of class $name"
	     ;;
	4)   cmslog 2 "$name $number in $location failed compatibility check"
	     cmsreport $name $number present yes
	     cmsreport $name $number info \
		"FRU in $location has failed compatabilty checks"
	     ;;
	*)   cmslog 2 "$name $number in $location: cmscheckfru returned $result"
	     ;;
	esac ;
	exit 2;
fi;
cmsreport $name $number present yes
cmsreport $name $number fault_acknowledged no
cmsledctl -l $location -f
exit 0
