meta-facebook: greatlakes: fix power control command

-Add condition for checking ipmb commands result.
-Fix wrong command call for chassis power off.

Tested: tested and verified on grwatlakes platform.
Change-Id: Id7262df4f8687b34e5ca0d6eabb9914e332dfe1a
Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
diff --git a/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/chassis-powercycle b/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/chassis-powercycle
index ab9c457..bbf1c91 100644
--- a/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/chassis-powercycle
+++ b/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/chassis-powercycle
@@ -18,6 +18,12 @@
         then
             i2cset -y "$CPLD_BUS_NUM" "$CPLD_PWR_CTRL_ADDR" "$OFFSET" "$POW_OFF_SLOT"
             sleep 10
+            chassis_status=$(chassis-power-status $SLOT)
+            if [ "$chassis_status" -ne "$STATE_OFF" ]
+            then
+                echo "chassis$CHASSIS_ID power off fail"
+                exit 1
+            fi
         fi
         i2cset -y "$CPLD_BUS_NUM" "$CPLD_PWR_CTRL_ADDR" "$OFFSET" "$POW_ON_SLOT"
         sleep 2
diff --git a/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/chassis-poweroff b/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/chassis-poweroff
index 9417352..bde6ce0 100644
--- a/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/chassis-poweroff
+++ b/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/chassis-poweroff
@@ -11,7 +11,7 @@
 # Server 12v power off
 chassis-power-off()
 {
-        result=$(i2cset -y "$CPLD_BUS_NUM" "$CPLD_PWR_CTRL_ADDR" "$OFFSET $POW_OFF_SLOT")
+        result=$(i2cset -y "$CPLD_BUS_NUM" "$CPLD_PWR_CTRL_ADDR" "$OFFSET" "$POW_OFF_SLOT")
         echo "$result"
         sleep 1
 
diff --git a/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-powercycle b/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-powercycle
index daaebc8..47fecfc 100644
--- a/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-powercycle
+++ b/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-powercycle
@@ -13,8 +13,14 @@
         power_delay=$1
         for pwr_cmd in "${power_seq[@]}"
         do
-             result="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" "$NETFN" "$LUN" "$CMD" "$DATA_LEN" 0x01 0x42 0x01 0x00 "$pwr_cmd")"
-             echo "$result"
+             response="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" "$NETFN" "$LUN" "$CMD" "$DATA_LEN" 0x01 0x42 0x01 0x00 "$pwr_cmd")"
+             echo "$response"
+             result=$(echo "$response" | cut -d" " -f "$IPMB_CMD_COMPLETE_CODE_INDEX")
+             if [ "$result" -ne 0 ]
+             then
+                     echo "Failed to send ipmb command"
+                     exit 1
+             fi
              if [ "$pwr_cmd" == "$POWER_BTN_LOW" ]
              then
                      sleep "$power_delay"
@@ -43,5 +49,3 @@
   echo "Host is Off"
   exit 1;
 fi
-
-
diff --git a/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-poweroff b/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-poweroff
index 624d6d5..b322faa 100644
--- a/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-poweroff
+++ b/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-poweroff
@@ -12,8 +12,14 @@
 {
         for pwr_cmd in "${power_seq[@]}"
         do
-             result="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" "$NETFN" "$LUN" "$CMD" "$DATA_LEN" 0x01 0x42 0x01 0x00 "$pwr_cmd")"
-             echo "$result"
+             response="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" "$NETFN" "$LUN" "$CMD" "$DATA_LEN" 0x01 0x42 0x01 0x00 "$pwr_cmd")"
+             echo "$response"
+             result=$(echo "$response" | cut -d" " -f "$IPMB_CMD_COMPLETE_CODE_INDEX")
+             if [ "$result" -ne 0 ]
+             then
+                     echo "Failed to send ipmb command"
+                     exit 1
+             fi
              if [ "$pwr_cmd" == "$POWER_BTN_LOW" ]
              then
                      sleep 6
diff --git a/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-poweron b/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-poweron
index bd72979..5d8fab3 100644
--- a/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-poweron
+++ b/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-poweron
@@ -11,8 +11,14 @@
 {
         for pwr_cmd in "${power_seq[@]}"
         do
-             result="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" "$NETFN" "$LUN" "$CMD" "$DATA_LEN" 0x01 0x42 0x01 0x00 "$pwr_cmd")"
-             echo "$result"
+             response="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" "$NETFN" "$LUN" "$CMD" "$DATA_LEN" 0x01 0x42 0x01 0x00 "$pwr_cmd")"
+             echo "$response"
+             result=$(echo "$response" | cut -d" " -f "$IPMB_CMD_COMPLETE_CODE_INDEX")
+             if [ "$result" -ne 0 ]
+             then
+                     echo "Failed to send ipmb command"
+                     exit 1
+             fi
              if [ "$pwr_cmd" == "$POWER_BTN_LOW" ]
              then
                      sleep 2
diff --git a/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-powerreset b/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-powerreset
index 938c914..b90c5f0 100644
--- a/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-powerreset
+++ b/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/host-powerreset
@@ -12,8 +12,14 @@
 {
     for reset_cmd in "${reset_seq[@]}"
     do
-        result="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" "$NETFN" "$LUN" "$CMD" "$DATA_LEN" 0x01 0x42 0x01 0 "$reset_cmd")"
-        echo "$result"
+        response="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" "$NETFN" "$LUN" "$CMD" "$DATA_LEN" 0x01 0x42 0x01 0 "$reset_cmd")"
+        echo "$response"
+        result=$(echo "$response" | cut -d" " -f "$IPMB_CMD_COMPLETE_CODE_INDEX")
+        if [ "$result" -ne 0 ]
+        then
+            echo "Failed to send ipmb command"
+            exit 1
+        fi
         if [ "$reset_cmd" == "$POWER_BTN_LOW" ]
         then
             sleep "$1"
diff --git a/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd b/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd
index ed75851..44ed0dc 100644
--- a/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd
+++ b/meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd
@@ -35,6 +35,7 @@
 export CHASSIS_OFF="xyz.openbmc_project.State.Chassis.PowerState.Off"
 export HOST_ON="xyz.openbmc_project.State.Host.HostState.Running"
 export HOST_OFF="xyz.openbmc_project.State.Host.HostState.Off"
+export IPMB_CMD_COMPLETE_CODE_INDEX=2
 
 host-power-status()
 {