blob: f5a0118202a04a9ab965e3bc51a1d7bfc4f18650 [file] [log] [blame]
Karthikeyan Pasupathi36f035b2022-08-28 17:35:29 +05301#!/bin/bash
2
3# Provide source directive to shellcheck.
Patrick Williams9afd92e2024-02-15 15:28:34 -06004# shellcheck source=meta-facebook/meta-greatlakes/recipes-phosphor/state/phosphor-state-manager/power-cmd
Delphine CC Chiuab1722f2022-12-01 11:43:35 +08005source /usr/libexec/phosphor-state-manager/power-cmd
Karthikeyan Pasupathi36f035b2022-08-28 17:35:29 +05306
Delphine CC Chiu17539d82023-03-09 15:27:47 +08007HOST_ID=$1
Karthikeyan Pasupathi36f035b2022-08-28 17:35:29 +05308SLOT_ID=$(( $1-1 << 2 ))
9
10# Host Power Off
11host-power-off()
12{
13 for pwr_cmd in "${power_seq[@]}"
14 do
BonnieLo-wiwynn052ee412023-03-31 14:27:50 +080015 response="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" "$NETFN" "$LUN" "$CMD" "$DATA_LEN" 0x01 0x42 0x01 0x00 "$pwr_cmd")"
16 echo "$response"
17 result=$(echo "$response" | cut -d" " -f "$IPMB_CMD_COMPLETE_CODE_INDEX")
18 if [ "$result" -ne 0 ]
19 then
20 echo "Failed to send ipmb command"
21 exit 1
22 fi
Delphine CC Chiu17539d82023-03-09 15:27:47 +080023 if [ "$pwr_cmd" == "$POWER_BTN_LOW" ]
Karthikeyan Pasupathi36f035b2022-08-28 17:35:29 +053024 then
25 sleep 6
26 fi
27 done
Delphine CC Chiu17539d82023-03-09 15:27:47 +080028
29 # Check host stattus after doing host power off
30 host_status=$(host-power-status $SLOT_ID)
31 if [ "$host_status" == "$STATE_OFF" ]
32 then
33 busctl set-property "$HOST_BUS_NAME""$HOST_ID" "$HOST_OBJ_PATH""$HOST_ID" "$HOST_INTF_NAME" "$HOST_PROPERTY_NAME" s "$HOST_OFF"
34 echo "Host power off"
35 exit 0;
36 else
37 busctl set-property "$HOST_BUS_NAME""$HOST_ID" "$HOST_OBJ_PATH""$HOST_ID" "$HOST_INTF_NAME" "$HOST_PROPERTY_NAME" s "$HOST_ON"
38 echo "Host power on"
39 exit 0;
40 fi
Karthikeyan Pasupathi36f035b2022-08-28 17:35:29 +053041}
42
43# Check Host Response and Status
Delphine CC Chiu17539d82023-03-09 15:27:47 +080044host_status=$(host-power-status $SLOT_ID)
45if [ "$host_status" == "$STATE_ON" ]
46then
47 host-power-off
48else
49 echo "Power is already off"
50 exit 1;
51fi