#!/bin/sh
#
#
#    Copyright (c) 1996-2005 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#    File name:   setbplbmode
#    Module name: diag/scripts
#
#    This file implements the setbplbmode command.
#
# NAME
#    setbplbmode - enable or disable bklb mode
#
# SYNOPSIS
#    setbplbmode [ mode | show ]
#
# AVAILABILITY
#    swt_mfg
#
# DESCRIPTION
#    This command enables bplb mode if the "mode" operand is non-zero
#    and disables the bplb mode if the "mode" operand is a 0. The
#    mode is saved in flash memory and stays in that mode until the
#    next execution of setbplbmode.
#
#    The mode becomes active as soon as this command is executed.
#    It does not require a reboot to take effect.
#
#    The BPLB mode, when enabled, allows diagnostics to set back end
#    ports to cable loop-back (lb_mode 0 or 1).
#
#    The BPLB mode, when disabled, forces diagnostic to limit loop-
#    back to the serdis (ext) for back end ports.
#
#
#
# OPERANDS
#    The following operand is optional:
#
#       mode            Zero means disable bplb mode, any other value
#                       will enable bplb mode.  The default action
#                       if no parameter is specified is to disable
#                       bplb mode.
#
#

# Check RBAC permission on command
/fabos/libexec/rbac_check `/bin/basename $0`

echo "Command not applicable to this platform."
exit 3

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

#
#
# Load library -- must be first.
#
home="/fabos/share"
util="diagcommon.sh"
ok=0
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.mode.bplb"	# config string to update
config_name="Bplb Mode"		# User name of config.
config_default=0		# default value
config_mode=$INTEGER		# config mode

syntax="`/bin/basename $0` [ show \| enable \| disable ]" ; export syntax
bool_false="Disabled" ; export bool_false
bool_true="Enabled" ; export bool_true

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

if [ "$val" -ne "0" ]
then
	val=1
fi

if [ "$val" -ne "0" ]
then
     res=$bool_true
else
     res=$bool_false
fi
cur_val=`getConfig $config_string $config_mode $config_default`
if [ "$cur_val" != "$val" ]
then
	setConfig $config_string $config_mode $val
	updateConfig
	echo "$config_name is now $val ($res)."
else
	echo "$config_name is still $val ($res)."
fi
exit 0
