1#!/bin/bash
2
3SERVICE_NAME="xyz.openbmc_project.Inventory.Manager"
4INVENTORY_OBJPATH=( \
5    "/xyz/openbmc_project/inventory/system/chassis/motherboard/ALL_PWR_GOOD_H"
6    "/xyz/openbmc_project/inventory/system/chassis/motherboard/FAN_STATUS_INT_L"
7    "/xyz/openbmc_project/inventory/system/chassis/motherboard/THERMAL_ALERT_L"
8    "/xyz/openbmc_project/inventory/system/chassis/motherboard/CPU_CATERR_L"
9    "/xyz/openbmc_project/inventory/system/chassis/motherboard/CPU_THERMTEIP_L"
10    "/xyz/openbmc_project/inventory/system/chassis/motherboard/PSU0_INT_L"
11    "/xyz/openbmc_project/inventory/system/chassis/motherboard/PSU1_INT_L"
12    "/xyz/openbmc_project/inventory/system/chassis/motherboard/PSU0_POWER_OK"
13    "/xyz/openbmc_project/inventory/system/chassis/motherboard/PSU1_POWER_OK"
14    "/xyz/openbmc_project/inventory/system/chassis/motherboard/PSU0_PRSNT_L"
15    "/xyz/openbmc_project/inventory/system/chassis/motherboard/PSU1_PRSNT_L"
16)
17INTERFACE_NAME="xyz.openbmc_project.Inventory.Item"
18
19IPMI_LOG_SERVICE="xyz.openbmc_project.Logging.IPMI"
20IPMI_LOG_OBJPATH="/xyz/openbmc_project/Logging/IPMI"
21IPMI_LOG_INTERFACE="xyz.openbmc_project.Logging.IPMI"
22IPMI_LOG_FUNCT="IpmiSelAdd"
23IPMI_LOG_PARA_FORMAT="ssaybq" #5 parameters, s : string, s : string, ay : byte array, b : boolean, q : UINT16
24
25LOG_ERR="Configuration Error(Incorrect_interconnection)"
26LOG_EVENT_DATA="3 0x01 0xff 0xff"
27LOG_ASSERT_FLAG="true"
28LOG_DEASSERT_FLAG="false"
29LOG_GENID_FLAG="0x0020"
30
31initial_state=("false" "false" "false" "false" "false" "false" "false" "false" "false" "false" "false" "false")
32
33for i in "${!INVENTORY_OBJPATH[@]}"
34do
35    mapper wait "${INVENTORY_OBJPATH[$i]}"
36done
37
38while true; do
39    for i in "${!INVENTORY_OBJPATH[@]}"
40    do
41        current_status="$(busctl get-property $SERVICE_NAME "${INVENTORY_OBJPATH[$i]}" $INTERFACE_NAME Present | awk '{print $2}')"
42
43        if [ "$current_status" == "true" ] && [ "${initial_state[$i]}" == "false" ];then
44            initial_state[i]="true"
45            busctl call $IPMI_LOG_SERVICE $IPMI_LOG_OBJPATH $IPMI_LOG_INTERFACE $IPMI_LOG_FUNCT $IPMI_LOG_PARA_FORMAT "$LOG_ERR" "${INVENTORY_OBJPATH[$i]}" "$LOG_EVENT_DATA" $LOG_ASSERT_FLAG $LOG_GENID_FLAG
46        elif [ "$current_status" == "false" ] && [ "${initial_state[$i]}" == "true" ]; then
47            initial_state[i]="false"
48            busctl call $IPMI_LOG_SERVICE $IPMI_LOG_OBJPATH $IPMI_LOG_INTERFACE $IPMI_LOG_FUNCT $IPMI_LOG_PARA_FORMAT "$LOG_ERR" "${INVENTORY_OBJPATH[$i]}" "$LOG_EVENT_DATA" $LOG_DEASSERT_FLAG $LOG_GENID_FLAG
49        fi
50    done
51    usleep 100000
52done
53
54exit 0
55