#!/bin/sh
#
#
#    Copyright (c) 1996-2006 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#
# NAME
#      diagloopid - select the diagnostics loop ID
# 
# SYNOPSIS
#      diagloopid [ id | -show ]
# 
# AVAILABILITY
#      admin
# 
# DESCRIPTION
#      This command selects the loop ID to be used by FL mode diag-
#      nostics.  The value entered will be converted from a loop ID
#      to  the  corresponding ALPA and used as the port address for
#      any diagnostics that operate  in  FL  port  mode.  The  mode
#      becomes  active as soon as this command is executed. It does
#      not require a reboot to take effect.
# 
#      The actual behavior of diagloopid depends on the test  meth-
#      ods that use it.
# 
# OPTIONS
#      id        Specify the loop id for FL mode diagnostics.
# 
#      -show     If specified or no id is given,the current loop id
#                will be displayed.
# 
# EXAMPLES
#      > diagloopid -show
#      FL mode Loop ID is 125.
# 
# NOTES
#      Currently no FL mode tests exist.
# 

#
#
# Load library -- must be first.
#
echo "Command not applicable to this platform."
exit 3


home="/fabos/share"
util="diagcommon.sh"
ok=0

if [ $# -eq 0 ]; then
	# Check RBAC permission on command
	/fabos/libexec/rbac_check `/bin/basename $0`
else
	# Check RBAC permission on identified options
	/fabos/libexec/rbac_check `/bin/basename $0` $1
fi

if [ $? -ne 0 ]; then
	exit 127
fi

for f in "./$util" "$FABOSHOME/share/$util" "$home/$util" ; do
	if [ -r $f ] ; then
		. $f
		ok=1
		break;
	fi
done
if [ $ok -ne 1 ] ; then
	echo "Error -- could not locate $util"
	exit 3
fi

#
# Program customization
#

config_string="diag.loopID"	# config string to update
config_name="FL mode Loop ID"	# User name of config.
config_default=125		# default value
config_mode=$INTEGER		# config mode


#
# diagloopid()
#
checkForShow "$config_name" "$config_string" "$config_mode" "$config_default" $1
val=`getValue $1`
if [ $? != 0 ] ; then exit 3 ; fi

if [ $val -lt 0 -o $val -gt 125 ]
then
    err "Loop ID must be within [0..125]"
    exit 3
fi

cur_val=`getConfig $config_string $config_mode $config_default`
if [ "$cur_val" != "$val" ]
then
	setConfig $config_string $config_mode $val
	echo $config_name is now $val.
	updateConfig
else
	echo $config_name is still $val.
fi
exit 0
