#!/bin/bash

#检查集群节点个数
G_INSPECT_MMLPATH="/opt/huawei/snas/script/inspect_mml"
source ${G_INSPECT_MMLPATH}/CheckItems
CurInspectNum="351"
CurInspectFun="$( GetInspectType $CurInspectNum )"
RESULTFILE="/tmp/tmpResult${CurInspectFun}"
>${RESULTFILE}

LOG_FILE="/var/log/inspect.log"
RepeatTimes=(1 2 3)

EXPANDERTOOL228812="/opt/hardware_firmware/rh/ses/RH228812HDD/expanderTool"
EXPANDERTOOL228825="/opt/hardware_firmware/rh/ses/RH228825HDD/expanderTool"
EXPANDERTOOL528836="/opt/huawei/snas/bin/g3Xflash"
SANS_FILE="/opt/huawei/snas/etc/snas.ini"
RH5288_BoardID=("ca" "cb")
RH2288_BoardID=("73" "75")
CheckVersion_C00="V300R006C00SPC200"
CheckVersion_C20="V300R006C20SPC300"
Product_Version=$( grep -w "ProductVersion" /opt/huawei/deploy/package/version |awk -F"=" '{print $2}' )


#RH结果是从第二个字段开始取
function RHhex2ascii()
{
    local idx=0
    local INPUT=$1
    local OUTPUT=""
    for i in $INPUT ; do
        idx=$((idx+1))
        if [ $idx -gt 1 ];then
            OUTPUT=$OUTPUT$( echo -e "\\x$i" )
        fi
    done
    echo "$OUTPUT"
}

function IsRHtypeNode
{
    local name=""
    name=$(dmidecode -t 1 | grep "Product Name:" | awk '{print $3}')
    if [ "$name" = "RH2288" -o "$name" = "RH2288H" ]; then
        return 0
    else
        return 1
    fi
}

function IsRHNode()
{
    local name=""
    name=$(dmidecode -t 1 | grep "Product Name:" | awk '{print $3}')
    if [ "$name" = "RH2288" -o "$name" = "5288" -o "$name" = "RH2288H" ]; then
        return 0
    else
        return 1
    fi
}

function getbackcpld
{
    local verioncpld=""
    local FruValue=""
    local counts=0
    local productstyle=$1
    local BackCplds=$2

    #轮询机制确定获取正确BoardID 时使用到的FruValue
    for((i=1;i<256;i++))
    do
        FruValue=$( printf "0x%x" $i )
        BoardID=$( ipmitool raw 0x30 0x90 0x29 $FruValue 0x2 2>/dev/null )
        if [ "$BoardID" = "" ];then
            continue
        fi

        for item in ${BackCplds[*]}
        do
            #ipmitool命令回显第一位是空格
            if [ " $item" = "$BoardID" ];then
               raw_version=$( ipmitool raw 0x30 0x90 0x08 $FruValue 0x02 0x00 0x0e )
               version_exp=$( RHhex2ascii "${raw_version}")
               version_exp=$( echo ${version_exp} | awk -F ")" '{print $2}' )
               verioncpld="${version_exp} ${verioncpld}"
               LOG "[FUNCNAME]verioncpld=$version_exp,BoardID=$BoardID"
               counts=$((counts+1))
               break
            fi
        done
        #5288两块背板，2288一块，找到之后直接break不再继续循环
        if [ "$productstyle" = "RH5288" -a "$counts" = "2" ] ;then
            break
        elif [ "$productstyle" = "RH2288" -a "$counts" = "1" ];then
            break
        fi
    done

    if [ "$verioncpld" = "" ];then
        verioncpld="NULL"
    fi
    echo "${verioncpld}"

}

#需Web界面升级的固件
function getBMC()
{
    local Des_BMC_Version="2.33"
    local version_bmc=""
    local isPass=0
    #获取BMC固件版本
    raw_version=$( ipmitool raw 0x30 0x90 0x08 0x0 0x01 0x00 0x0e )
    raw_version_test=$( echo ${raw_version} | grep -Ev ^[0-9,a-f,' ']+$ )
    if [ -z "${raw_version}" ] || [ ! -z "${raw_version_test}" ] ; then
        version_bmc="NULL"
    else
        version_bmc=$( RHhex2ascii "$raw_version" )
    fi

    if [ "X${Des_BMC_Version}" != "X${version_bmc}" ];then
        isPass=1
        echo "[ERR]BMC version ${version_bmc} is not match the standard version ${Des_BMC_Version}" >>${RESULTFILE} 2>&1
    fi
    echo "BMC_Version:${version_bmc}"
    return ${isPass}
}

function getBIOS()
{
    local Des_2288_BIOS_Ver_C00="3.35"
    local Des_5288_BIOS_Ver_C00="3.5|3.50"
    local Des_BIOS_Ver_C20="3.99"
    local version_bios=""
    local Des_BIOS_Ver=""
    local isPass=0

    if [ "X${CheckVersion_C00}" == "X${Product_Version}" ];then
        IsRHtypeNode
        if [ "$?" = "0" ]; then
            Des_BIOS_Ver="${Des_2288_BIOS_Ver_C00}"
        else
            Des_BIOS_Ver="${Des_5288_BIOS_Ver_C00}"
        fi
    elif [ "X${CheckVersion_C20}" == "X${Product_Version}" ];then
        Des_BIOS_Ver="${Des_BIOS_Ver_C20}"
    fi
    #获取BIOS固件版本
    raw_version=$( ipmitool raw 0x30 0x90 0x08 0x00 0x06 0x00 0x0e )
    raw_version_test=$( echo ${raw_version} |grep -Ev ^[0-9,a-f,' ']+$ )
    if [ -z "${raw_version}" ] || [ ! -z "${raw_version_test}" ] ; then
        version_bios="NULL"
    else
        version_bios=$( RHhex2ascii "${raw_version}" )
        version_bios=$( echo ${version_bios} | awk -F ")" '{print $2}' )
    fi
    if [[ "${Des_BIOS_Ver}" =~ "${version_bios}" ]];then
        continue
    else
        isPass=1
        echo "[ERR]BIOS version ${version_bios} is not match the standard version ${Des_BIOS_Ver}" >>${RESULTFILE} 2>&1
    fi
    echo "BIOS_Version:${version_bios}"
    return ${isPass}
}

#1.12	3.11		1.15	3.15
function getCPLD()
{
    local Des_2288_BackCPLD_Ver="1.08 "
    local Des_5288_BackCPLD_Ver="1.05 1.07 "
    local Des_2288_MBCPLD_Ver_C00="1.12"
    local Des_5288_MBCPLD_Ver_C00="3.11"
    local Des_2288_MBCPLD_Ver_C20="1.15"
    local Des_5288_MBCPLD_Ver_C20="3.15"
    local CPLD_Version=""
    local Des_MBCPLD_Ver=""
    local isPass=0

    IsRHtypeNode
    if [ "$?" = "0" ]; then
        #获取2288 主板CPLD固件版本
        raw_version=$( ipmitool raw 0x30 0x90 0x08 0x00 0x02 0x00 0x0e )
        raw_version_test=$( echo ${raw_version} | grep -Ev ^[0-9,a-f,' ']+$ )
        if [ -z "${raw_version}" ] || [ ! -z "${raw_version_test}" ] ; then
            version_mb_cpld="NULL"
        else
            version_mb_cpld=$( RHhex2ascii "${raw_version}" )
            version_mb_cpld=$( echo ${version_mb_cpld} | awk -F ")" '{print $2}')
        fi
        if [ "X${CheckVersion_C00}" == "X${Product_Version}" ];then
            Des_MBCPLD_Ver="${Des_2288_MBCPLD_Ver_C00}"
        elif [ "X${CheckVersion_C20}" == "X${Product_Version}" ];then
            Des_MBCPLD_Ver="${Des_2288_MBCPLD_Ver_C20}"
        fi
        if [ "X${Des_MBCPLD_Ver}" != "X${version_mb_cpld}" ];then
            isPass=1
            echo "[ERR]MainBoard CPLD version ${version_mb_cpld} is not match the standard version ${Des_MBCPLD_Ver}" >>${RESULTFILE} 2>&1
        fi
        #获取2288 背板固件版本
        Back_CPLD=$( getbackcpld "RH2288" "${RH2288_BoardID[*]}" )
        if [ "${Des_2288_BackCPLD_Ver}" != "${Back_CPLD}" ];then
            isPass=1
            echo "[ERR]BackBoard CPLD version ${Back_CPLD} is not match the standard version ${Des_2288_BackCPLD_Ver}" >>${RESULTFILE} 2>&1
        fi
        CPLD_Version="CPLD_Version:MB_CPLD=${version_mb_cpld},Back_CPLD=${Back_CPLD}"
        echo "${CPLD_Version}"

    else
        raw_version=$( ipmitool raw 0x30 0x90 0x08 0x00 0x02 0x00 0x0e )
        raw_version_test=$( echo $raw_version |grep -Ev ^[0-9,a-f,' ']+$ )
        if [ -z "$raw_version" ] || [ ! -z "$raw_version_test" ] ; then
            version_mb_cpld="NULL"
        else
            version_mb_cpld=$( RHhex2ascii "${raw_version}" )
            version_mb_cpld=$( echo $version_mb_cpld|awk -F ")" '{print $2}' )
        fi
        if [ "X${CheckVersion_C00}" == "X${Product_Version}" ];then
            Des_MBCPLD_Ver="${Des_5288_MBCPLD_Ver_C00}"
        elif [ "X${CheckVersion_C20}" == "X${Product_Version}" ];then
            Des_MBCPLD_Ver="${Des_5288_MBCPLD_Ver_C20}"
        fi
        if [ "X${Des_MBCPLD_Ver}" != "X${version_mb_cpld}" ];then
            isPass=1
            echo "[ERR]MainBoard CPLD version ${version_mb_cpld} is not match the standard version ${Des_MBCPLD_Ver}" >>${RESULTFILE} 2>&1
        fi
        #获取5288 背板固件版本
        Back_CPLD=$( getbackcpld "RH5288" "${RH5288_BoardID[*]}" )
        if [ "${Des_5288_BackCPLD_Ver}" != "${Back_CPLD}" ];then
            isPass=1
            echo "[ERR]BackBoard CPLD version ${Back_CPLD} is not match the standard version ${Des_5288_BackCPLD_Ver}" >>${RESULTFILE} 2>&1
        fi
        CPLD_Version="CPLD_Version:MB_CPLD=${version_mb_cpld},Back_CPLD=${Back_CPLD}"
        echo "${CPLD_Version}"
    fi
    return ${isPass}
}
#126,129 FirmWare：00.15.01.11 Platform version:00.11
function getSES()
{
    local RH_12_DevType="12"
    local RH_25_DevType="13"
    local Des_2288_SesVer_C00="126"
    local Des_2288_SesVer_C20="129"
    local Des_5288_FirmVer_C00="00.12.03.07"
    local Des_5288_FirmVer_C20="00.15.01.11"
    local Des_5288_PlatVer_C00="00.07"
    local Des_5288_PlatVer_C20="00.11"
    local command_tool=""
    local Des_Ses_Ver=""
    local Des_5288_FirmVer=""
    local Des_5288_PlatVer=""
    local isPass=0

    IsRHtypeNode
    if [ "$?" == "0" ];then
        devname=$(lsscsi -g |grep "Expander" |awk '{print $NF}');
        devicetype=$( grep -w "nodeType" ${SANS_FILE} | awk -F"=" '{print $2}' | sed 's/ //g')
        if [ "${RH_12_DevType}" == "${devicetype}" ];then
            command_tool="${EXPANDERTOOL228812}"
        elif [ "${RH_25_DevType}" == "${devicetype}" ];then
            command_tool="${EXPANDERTOOL228825}"
        fi
        if [ "X" == "X${command_tool}" ];then
            echo "SES_Version:NULL"
            isPass=1
            LOG "[$CurInspectFun][FUNCNAME] TOOL ${command_tool} is not exist"
            echo "[ERR]SES tool ${command_tool} is not exist,can not get SES version." >>${RESULTFILE} 2>&1
            return ${isPass}
        fi
        if [ "X${CheckVersion_C00}" == "X${Product_Version}" ];then
            Des_Ses_Ver="${Des_2288_SesVer_C00}"
        elif [ "X${CheckVersion_C20}" == "X${Product_Version}" ];then
            Des_Ses_Ver="${Des_2288_SesVer_C20}"
        fi
        sesversion=$( ${command_tool} query ${devname} | grep "Image Version" | awk -F":" '{print $2}'| sed 's/ //g' )
        if [ "X${Des_Ses_Ver}" != "X${sesversion}" ];then
            isPass=1
            echo "[ERR]SES version ${sesversion} is not match the standard version ${Des_Ses_Ver}" >>${RESULTFILE} 2>&1
            LOG "[$CurInspectFun][FUNCNAME] SES version ${sesversion} is not match the standard version ${Des_Ses_Ver}"
        fi
        echo "SES_Version:${sesversion}"

    else
        command_tool="${EXPANDERTOOL528836}"
        if [ "X${CheckVersion_C00}" == "X${Product_Version}" ];then
            if [ ! -f "${command_tool}" ];then
                isPass=1
                echo "SES_Version:NULL"
                echo "[ERR]The tool ${command_tool} does not exist,can not get SESVersion information,please apply the hot patch." >>${RESULTFILE} 2>&1
                return ${isPass}
            fi
            Des_5288_FirmVer="${Des_5288_FirmVer_C00}"
            Des_5288_PlatVer="${Des_5288_PlatVer_C00}"
        elif [ "X${CheckVersion_C20}" == "X${Product_Version}" ];then
            Des_5288_FirmVer="${Des_5288_FirmVer_C20}"
	    Des_5288_PlatVer="${Des_5288_PlatVer_C20}"
        fi
        SES_Firmware=$( ${command_tool} -i 500605b0000273bf get ver | grep "Firmware" | awk -F":" '{print $2}'| sed 's/ //g' )
        SES_Platform=$( ${command_tool} -i 500605b0000273bf get ver 3 | grep "Platform Version" |awk -F":" '{print $2}' | sed 's/\t//g' )
        if [ "X${Des_5288_FirmVer}" != "X${SES_Firmware}" ];then
            isPass=1
            echo "[ERR]SES Firmware version ${SES_Firmware} is not match the standard version ${Des_5288_FirmVer}" >>${RESULTFILE} 2>&1
        fi
        if [ "X${Des_5288_PlatVer}" != "X${SES_Platform}" ];then
            isPass=1
            echo "[ERR]SES Firmware version ${SES_Platform} is not match the standard version ${Des_5288_PlatVer}" >>${RESULTFILE} 2>&1
            LOG "[$CurInspectFun][FUNCNAME] SES Firmware version ${SES_Platform} is not match the standard version ${Des_5288_PlatVer}"
        fi
        echo "SES_Version:SES_Firmware=${SES_Firmware},SES_Platform=${SES_Platform}"

    fi
    return ${isPass}
}

function getNVDIMM()
{
    local Des_Version="V1.40"
    local isPass=0
    local command_tool="/usr/local/nvdimm/nvdimm"
    NVDIMM_Version=$( ${command_tool} getfwver | grep "FW Version" |awk -F":" '{print $2}' )
    if [ "X${Des_Version}" != "X${NVDIMM_Version}" ] && [ "$(dmidecode -t17 | grep "Synchronous Non-Volatile" -C 5 | grep "Speed:" | awk -F " " '{print$2}')" != "2933" ]; then
        #如果是镁光的版本则默认通过
        isPass=1
        echo "[ERR]NVDIMM version ${NVDIMM_Version} is not match the standard version ${Des_Version}" >>${RESULTFILE} 2>&1
        LOG "[$CurInspectFun][FUNCNAME] NVDIMM version ${NVDIMM_Version} is not match the standard version ${Des_Version}"
    fi
    echo "NVDIMM_Version:${NVDIMM_Version}"
    return ${isPass}
}

function getSAS()
{
    local Des_SAS_FW_C00="12.100.01.00"
    local Des_SAS_FW_C20="15.00.07.00"
    local Des_SAS_NVDATA_C00="0b.02.00.01"
    local Des_SAS_NVDATA_C20="0e.00.00.01"
    local Des_SAS_x86_BIOS_C00="8.29.02.00|08.29.02.00"
    local Des_SAS_x86_BIOS_C20="08.35.00.00"
    local Des_SAS_EFI_BIOS_C00="14.00.00.00"
    local Des_SAS_EFI_BIOS_C20="17.00.04.00"
    local Des_SAS_FW=""
    local Des_SAS_NVDATA=""
    local Des_SAS_x86_BIOS=""
    local Des_SAS_EFI_BIOS=""
    local sas3flashRltInfo=/tmp/_sas3flashRltInfo_f
    local isPass=0

    /opt/driver/lsisas-mpt3sas-driver/sas3flash -list >${sas3flashRltInfo}
    SAS_FW=$( grep "Firmware Version" ${sas3flashRltInfo} | awk -F":" '{print $2}' |sed 's/ //g' )
    if [ "X" == "X${SAS_FW}" ]; then
        SAS_FW="NULL"
    fi
    SAS_NVDATA=$( grep "NVDATA Version (Default)" ${sas3flashRltInfo} | awk -F":" '{print $2}' |sed 's/ //g' )
    if [ "X" == "X${SAS_NVDATA}" ]; then
        SAS_NVDATA="NULL"
    fi
    SAS_x86_BIOS=$( grep "BIOS Version" ${sas3flashRltInfo} | awk -F":" '{print $2}' |sed 's/ //g' )
    if [ "X" == "X${SAS_x86_BIOS}" ]; then
        SAS_x86_BIOS="NULL"
    fi
    SAS_EFI_BIOS=$( grep "UEFI BSD Version" ${sas3flashRltInfo} | awk -F":" '{print $2}' | sed 's/ //g' )
    if [ "X" == "X${SAS_EFI_BIOS}" ]; then
        SAS_EFI_BIOS="NULL"
    fi
    rm -f ${sas3flashRltInfo}
    if [ "X${CheckVersion_C00}" == "X${Product_Version}" ];then
        Des_SAS_FW="${Des_SAS_FW_C00}"
        Des_SAS_NVDATA="${Des_SAS_NVDATA_C00}"
        Des_SAS_x86_BIOS="${Des_SAS_x86_BIOS_C00}"
        Des_SAS_EFI_BIOS="${Des_SAS_EFI_BIOS_C00}"
    elif [ "X${CheckVersion_C20}" == "X${Product_Version}" ];then
        Des_SAS_FW="${Des_SAS_FW_C20}"
        Des_SAS_NVDATA="${Des_SAS_NVDATA_C20}"
        Des_SAS_x86_BIOS="${Des_SAS_x86_BIOS_C20}"
        Des_SAS_EFI_BIOS="${Des_SAS_EFI_BIOS_C20}"
    fi
    if [ "X${Des_SAS_FW}" != "X${SAS_FW}" ];then
        isPass=1
        echo "[ERR]SAS FW version ${SAS_FW} is not match the standard version ${Des_SAS_FW}" >>${RESULTFILE} 2>&1
        LOG "[$CurInspectFun][FUNCNAME] SAS FW version ${SAS_FW} is not match the standard version ${Des_SAS_FW}"
    fi
    if [ "X${Des_SAS_NVDATA}" != "X${SAS_NVDATA}" ];then
        isPass=1
        echo "[ERR]SAS NVDATA version ${SAS_NVDATA} is not match the standard version ${Des_SAS_NVDATA}" >>${RESULTFILE} 2>&1
        LOG "[$CurInspectFun][FUNCNAME] SAS NVDATA version ${SAS_NVDATA} is not match the standard version ${Des_SAS_NVDATA}"
    fi
    if [[ "${Des_SAS_x86_BIOS}" =~ "${SAS_x86_BIOS}" ]];then
        LOG "[$CurInspectFun][FUNCNAME] SAS_x86_BIOS:${SAS_x86_BIOS},EXPECT_SAS_x86_BIOS:${Des_SAS_x86_BIOS}."
    else
        isPass=1
        echo "[ERR]SAS x86 BIOS version ${SAS_x86_BIOS} is not match the standard version ${Des_SAS_x86_BIOS}" >>${RESULTFILE} 2>&1
        LOG "[$CurInspectFun][FUNCNAME] SAS x86 BIOS version ${SAS_x86_BIOS} is not match the standard version ${Des_SAS_x86_BIOS}"
    fi
    if [ "X${Des_SAS_EFI_BIOS}" != "X${SAS_EFI_BIOS}" ];then
        isPass=1
        echo "[ERR]SAS EFI BIOS version ${SAS_EFI_BIOS} is not match the standard version ${Des_SAS_EFI_BIOS}" >>${RESULTFILE} 2>&1
        LOG "[$CurInspectFun][FUNCNAME] SAS EFI BIOS version ${SAS_EFI_BIOS} is not match the standard version ${Des_SAS_EFI_BIOS}"
    fi
    echo "SAS_Version:SAS_FW=${SAS_FW},SAS_NVDATA=${SAS_NVDATA},SAS_x86_BIOS=${SAS_x86_BIOS},SAS_EFI_BIOS=${SAS_EFI_BIOS}"
    return ${isPass}

}

function getIBandRock()
{
    local Des_Rock_Version="14.17.1010"
    local Des_IB_40_Version="2.30.8310"
    local Des_IB_56_Version="2.33.5310"
    local Des_IB_100_Version="12.18.2000"
    local IB_rate_40="40"
    local IB_rate_56="56"
    local IB_rate_100="100"
    local temfile="/tmp/tmpfileHardWareVersionIBandRock"
    local IB_Link="InfiniBand"
    local Rock_Link="Ethernet"
    local result=""
    local IB_firmware=""
    local IB_rate=""
    local IB_result=""
    local Rock_Firmware=""
    local isPass=0

    [ -f "${temfile}" ] && rm -f "${temfile}"
    ibstat >${temfile} 2>&1
    if [ ! -s ${temfile} ];then
        echo "IB_Version:NULL||Rock_Version:NULL"
        rm -rf ${temfile}
        return ${isPass}
    fi

    dos2unix ${temfile} >/dev/null 2>&1
    while read line;do
        if [[ "$line" =~ "Firmware version" ]];then
            FirmwareVer=$( echo "${line}" | awk -F":" '{print $2}' | sed 's/ //g;s/\t//g' )
        fi
        if [[ "$line" =~ "Rate" ]];then
            Rate=$( echo "${line}" | awk -F":" '{print $2}' | sed 's/ //g;s/\t//g' )
        fi
        if [[ "$line" =~ "Link layer" ]];then
            LinkType=$( echo "${line}" | awk -F":" '{print $2}' | sed 's/ //g;s/\t//g' )
            if [ "X${IB_Link}" == "X${LinkType}" ];then
                IB_firmware="${FirmwareVer} ${IB_firmware}"
                IB_rate="${Rate} ${IB_rate}"
                IB_result="IB_firmware=${FirmwareVer},Ib_rate=${Rate};${IB_result}"
            fi
            if [ "X${Rock_Link}" == "X${LinkType}" ];then
                Rock_Firmware="${FirmwareVer} ${Rock_Firmware}"
            fi
        fi
    done <${temfile}

    if [ "X" == "X${IB_result}" ];then
        IB_result="IB_Version:NULL"
    else
        for i in $(seq 0 `expr ${#IB_rate[@]} - 1`);do

            if [ "${IB_rate_40}" == "${IB_rate[$i]}" ];then
                if [ "${Des_IB_40_Version}" != "${IB_firmware[$i]}" ];then
                    isPass=1
                    echo "[ERR]IB version ${IB_firmware[$i]} is not match the standard version ${Des_IB_40_Version} when the rate is ${IB_rate_40}." >>${RESULTFILE} 2>&1
                    LOG "[$CurInspectFun][FUNCNAME] IB version ${IB_firmware[$i]} is not match the standard version ${Des_IB_40_Version} when the rate is ${IB_rate_40}"
                fi
            elif [ "${IB_rate_56}" == "${IB_rate[$i]}" ];then
                if [ "${Des_IB_56_Version}" != "${IB_firmware[$i]}" ];then
                    isPass=1
                    echo "[ERR]IB version ${IB_firmware[$i]} is not match the standard version ${Des_IB_56_Version} when the rate is ${IB_rate_56}" >>${RESULTFILE} 2>&1
                    LOG "[$CurInspectFun][FUNCNAME] IB version ${IB_firmware[$i]} is not match the standard version ${Des_IB_56_Version} when the rate is ${IB_rate_56}"
                fi
            elif [ "${IB_rate_100}" == "${IB_rate[$i]}" ];then
                if [ "${Des_IB_100_Version}" != "${IB_firmware[$i]}" ];then
                    isPass=1
                    echo "[ERR]IB version ${IB_firmware[$i]} is not match the standard version ${Des_IB_100_Version} when the rate is ${IB_rate_100}" >>${RESULTFILE} 2>&1
                    LOG "[$CurInspectFun][FUNCNAME] IB version ${IB_firmware[$i]} is not match the standard version ${Des_IB_100_Version} when the rate is ${IB_rate_100}"
                fi
            else
                isPass=1
                echo "[ERR]IB rate ${IB_rate[$i]} is not in version (${IB_rate_40} ${IB_rate_56} ${IB_rate_100} )" >>${RESULTFILE} 2>&1
                LOG "[$CurInspectFun][FUNCNAME] IB version ${IB_firmware[$i]} is not match the standard version ${Des_IB_40_Version} when the rate is ${IB_rate_40}"
            fi

        done
    fi
    if [ "X" == "X${Rock_Firmware}" ];then
        Rock_result="Rock_result:NULL"
    else
        for rockversion in ${Rock_Firmware}
        do
            if [ "${Des_Rock_Version}" != "${rockversion}" ];then
                isPass=1
                echo "[ERR]The Rock Version ${rockversion} not match the standard version ${Des_Rock_Version}"
                LOG "[$CurInspectFun][FUNCNAME] The Rock Version ${rockversion} not match the standard version ${Des_Rock_Version}"
            fi
        done
    fi

    echo "${IB_result}||${Rock_result}"
    rm -rf ${temfile}
    return ${isPass}

}

function CheckHardwareVersion()
{
    local iRet=""
    local iRet_IB=""
    local iRet_BMC=""
    local iRet_NVDIMM=""
    local iRet_SES=""
    local iRet_SAS=""
    local iRet_BIOS=""
    local iRet_CPLD=""
    local isPass=0

    if [ "X${CheckVersion_C00}" != "X${Product_Version}" -a "X${CheckVersion_C20}" != "X${Product_Version}" ];then
        isPass=0
        echo "INFO:Only check V300R006C00SPC200 or V300R006C20SPC300 version,Other versions of nodes are not checked." >>${RESULTFILE} 2>&1
        echo "${CurInspectFun}_Pass ${isPass}" >>${RESULTFILE} 2>&1
        LOG "[$FUNCNAME]${CurInspectFun}_Pass ${isPass},Only check V300R006C00SPC200 or V300R006C20SPC300 version"
        exit 0
    fi
    IsRHNode
    iRet=$?
    if [ "${iRet}" != "0" ]; then
        isPass=0
        echo "INFO:Only check RH Node,Other types of nodes are not checked." >>${RESULTFILE} 2>&1
        echo "${CurInspectFun}_Pass ${isPass}" >>${RESULTFILE} 2>&1
        LOG "[$FUNCNAME]${CurInspectFun}_Pass ${isPass},Only check RH Node"
        exit 0
    fi
    IBandRock_Version=$( getIBandRock )
    iRet_IB=$?
    if [ "${iRet_IB}" -ne 0 ];then
        isPass=1
    fi
    BMC_Version=$( getBMC )
    iRet_BMC=$?
    if [ "${iRet_BMC}" -ne 0 ];then
        isPass=1
    fi
    NVDIMM_Version=$( getNVDIMM )
    iRet_NVDIMM=$?
    if [ "${iRet_NVDIMM}" -ne 0 ];then
        isPass=1
    fi
    SES_Version=$( getSES  )
    iRet_SES=$?
    if [ "${iRet_SES}" -ne 0 ];then
        isPass=1
    fi
    SAS_Version=$( getSAS )
    iRet_SAS=$?
    if [ "${iRet_SAS}" -ne 0 ];then
        isPass=1
    fi
    BIOS_Version=$( getBIOS )
    iRet_BIOS=$?
    if [ "${iRet_BIOS}" -ne 0 ];then
        isPass=1
    fi
    CPLD_Version=$( getCPLD )
    iRet_CPLD=$?
    if [ "${iRet_CPLD}" -ne 0 ];then
        isPass=1
    fi

    echo "${SES_Version}||${SAS_Version}||${IBandRock_Version}||${BMC_Version}||${BIOS_Version}||${CPLD_Version}||${NVDIMM_Version}" >>${RESULTFILE} 2>&1
    echo "${CurInspectFun}_Pass ${isPass}" >>${RESULTFILE} 2>&1
    LOG "[$FUNCNAME]${CurInspectFun}_Pass ${isPass},Only check V300R006C00SPC200 or V300R006C20SPC300 version"
    exit 0
}

CheckHardwareVersion


