1#!/bin/bash 2 3export POWER_BTN_HIGH=0xFF 4export POWER_BTN_LOW=0xFE 5export RESET_BTN_HIGH=0xFF 6export RESET_BTN_LOW=0xFD 7export power_seq=( "$POWER_BTN_HIGH" "$POWER_BTN_LOW" "$POWER_BTN_HIGH" ) 8export reset_seq=( "$RESET_BTN_HIGH" "$RESET_BTN_LOW" "$RESET_BTN_HIGH") 9export SERVICE="xyz.openbmc_project.Ipmi.Channel.Ipmb" 10export OBJECT_PATH="/xyz/openbmc_project/Ipmi/Channel/Ipmb" 11export INTERFACE="org.openbmc.Ipmb" 12export DATA_LEN=0x05 13export NETFN=0x06 14export LUN=0x00 15export CMD=0x52 16export STATE_OFF=0 17export STATE_ON=1 18export STATE_UNKNOWN=-1 19export CPLD_BUS_NUM=12 20export CPLD_PWR_CTRL_ADDR=0xf 21export POW_ON_SLOT=0x01 22export POW_OFF_SLOT=0x00 23export PWRGD_SYS_PWROK_INDEX=12 24export IANA="0x15 0xA0 0x0" 25export IANA_LEN=3 26export CHASSIS_BUS_NAME="xyz.openbmc_project.State.Chassis" 27export CHASSIS_OBJ_PATH="/xyz/openbmc_project/state/chassis" 28export CHASSIS_INTF_NAME="xyz.openbmc_project.State.Chassis" 29export CHASSIS_PROPERTY_NAME="CurrentPowerState" 30export HOST_BUS_NAME="xyz.openbmc_project.State.Host" 31export HOST_OBJ_PATH="/xyz/openbmc_project/state/host" 32export HOST_INTF_NAME="xyz.openbmc_project.State.Host" 33export HOST_PROPERTY_NAME="CurrentHostState" 34export CHASSIS_ON="xyz.openbmc_project.State.Chassis.PowerState.On" 35export CHASSIS_OFF="xyz.openbmc_project.State.Chassis.PowerState.Off" 36export HOST_ON="xyz.openbmc_project.State.Host.HostState.Running" 37export HOST_OFF="xyz.openbmc_project.State.Host.HostState.Off" 38export IPMB_CMD_COMPLETE_CODE_INDEX=2 39 40host-power-status() 41{ 42 SLOT_ID=$1 43 44 response="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" 0x38 "$LUN" 0x03 0x03 0x15 0xa0 0x00)" 45 result=$(echo "$response" | cut -d" " -f "$PWRGD_SYS_PWROK_INDEX") 46 res="$(( "$result" & 0x80 ))" 47 status="$(( "$res" >> 7 ))" 48 49 echo "$status" 50 return 0 51} 52 53chassis-power-status() 54{ 55 slot=$1 56 status=-1 57 58 if [ "$slot" -le 4 ] 59 then 60 response="$(i2cget -y "$CPLD_BUS_NUM" "$CPLD_PWR_CTRL_ADDR" 0x25)" 61 res="$(( "$response" >> slot ))" 62 status="$(( "$res" & 0x01 ))" 63 fi 64 65 echo "$status" 66 return 0 67} 68