#!/bin/sh
#
#
#    Copyright (c) 1996-2006 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#
# NAME
#      bladepropshow - display blade properties
# 
# SYNOPSIS
#      bladepropshow [ --slot slotno ]
# 
# AVAILABILITY
#      all users
# 
# DESCRIPTION
#      This  command  will  display the properties of the specified
#      blade.
# 
# OPTIONS
#      [ --slot ] slotno
#                Specify which slot to operate on. If  this  option
#                is not specifed, the current slot will be assumed.
#                You can set the current slot by execution of  set-
#                slot command.
# 
# EXAMPLES
#      > bladepropshow --slot 1
#      Slot: 1
#      [2,4/8/64]
#      <0,1657/0001 1,1657/0001>
#      <2,1657/0001 3,1657/0001>
#      <4,1657/0001 5,1657/0001>
#      <6,1657/0001 7,1657/0001>
#      <0,8>=<1,9> <0,10>=<2,9> <0,6>=<3,7>
#      <1,9>=<0,8> <1,6>=<2,7> <1,10>=<3,9>
#      <2,9>=<0,10> <2,7>=<1,6> <2,10>=<3,11>
#      <3,7>=<0,6> <3,9>=<1,10> <3,11>=<2,10>
# 
# SEE ALSO
#      chippropshow(1d),  minispropshow(1d),  ptpropshow(1d),  set-
#      slot(1d)
# 
# NOTES
#      The output of this command is only for  internal  diagnostic
#      engineers and must not be interpreted by normal users in any
#      case.
# 

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

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

def_slot=0

#
# 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

#
# get sys info for multi blade
#
multiBlade=`isMultiBlade`
if [ $multiBlade = TRUE ]
then
     syntax="`/bin/basename $0` [ --slot ] slotno"
else
     syntax="`/bin/basename $0`"
fi

if [ -z $1 ]
then
  if [ -z $FABOS_SLOTNO ]
  then
    slot=$def_slot
  else
    slot=$FABOS_SLOTNO
   fi
  ans="`isValidSlot $slot -switch`"
  if [ "$ans" = TRUE ]
  then
    slot=$FABOS_SLOTNO
  else
    slot=$def_slot
  fi
else
  # check for -slot first
  s=`/usr/bin/expr "$1" : "[-]*slot"`
  if [ "0" -ne "$s" ]
  then
    ans="`isValidSlot $2 -switch`"
    if [ "$ans" = TRUE ]
    then
      slot=$2
    else 
      err "$2 is an invalid slot number"
      exit 4
    fi
  else
    err "Invalid command"
    exit 4
  fi
fi

#
# bladepropshow()
#
slot=`getValue $slot`
if [ $? != 0 ]
then
  exit 3
fi

enableSlotProc $slot
if [ $? != 0 ]
then
  exit 3
fi

path="/proc/fabos/blade/$slot"
file=$path/property

if [ $multiBlade = TRUE ]
then
  if [ ! -e "$file" ]
  then
    err "Slot: $slot not found"
  else
    echo ""
    echo "Slot: $slot"
    if [ -e "$file" ]
    then
      /bin/cat $file
    fi
  fi
else
  if [ ! -e "$file" ]
  then
    err "No properties found"
  else
    if [ -e "$file" ]
    then
      /bin/cat $file
    fi
  fi
fi

# disable the proc entries of this slot
disableSlotProc $slot
