xref: /openbmc/openpower-debug-collector/dump/tools/common/include/opfunctions (revision 1bee03b8426b0f69ec3bae2fd6a4714f2b4a0678)
1#!/usr/bin/env bash
2
3declare -rx TYPE_FAULTDATA="faultdata"
4#Dump originator variables
5declare -x ORIGINATOR_TYPE=""
6declare -x ORIGINATOR_ID=""
7
8# @brief fetch serial number
9# @param serial number
10function fetch_serial_number() {
11    serialNo=$(busctl get-property xyz.openbmc_project.Inventory.Manager \
12            /xyz/openbmc_project/inventory/system xyz.openbmc_project.Inventory.Decorator.Asset \
13        SerialNumber | cut -d " " -f 2 | sed "s/^\(\"\)\(.*\)\1\$/\2/g")
14
15    if [ -z "$serialNo" ]; then
16        serialNo="0000000"
17    fi
18}
19
20# @brief Add BMC dump File Name
21# @param BMC Dump File Name
22function get_bmc_dump_filename() {
23    fetch_serial_number
24    dump_id=$(printf %08d $dump_id)
25    if [ $dump_type = "$TYPE_FAULTDATA" ]; then
26        header_dump_name="FLTDUMP"
27        name="NAGDUMP.${serialNo}.${dump_id}.${dDay}"
28    else
29        header_dump_name="BMCDUMP"
30        name="BMCDUMP.${serialNo}.${dump_id}.${dDay}"
31    fi
32}
33
34# @brief Function to get the Originator details
35# @param Originator Type and Originator ID
36function get_originator_details() {
37    if [ -z "$dump_dir" ]; then
38        return
39    fi
40
41    dump_type_received=""
42    dump_entry_id="$dump_id"
43
44    if [ "$1" = "bmc" ] || [ "$1" = "system" ]; then
45        dump_type_received="$1"
46    else
47        echo "Invalid dump type received"
48        return
49    fi
50
51    if [ "$dump_type_received" = "bmc" ]; then
52        dump_entry_id=$(echo "$dump_entry_id" | sed "s/^0*//")
53    fi
54
55    local DBUS_DUMP_MANAGER="xyz.openbmc_project.Dump.Manager"
56    local DBUS_DUMP_PATH="/xyz/openbmc_project/dump/$dump_type_received/entry/$dump_entry_id"
57    local DBUS_DUMP_ORIGINATOR_IFACE="xyz.openbmc_project.Common.OriginatedBy"
58    local DBUS_ORIGINATOR_TYPE_STRING="OriginatorType"
59    local DBUS_ORIGINATOR_ID_STRING="OriginatorId"
60
61    ORIGINATOR_TYPE=$(busctl get-property "$DBUS_DUMP_MANAGER" \
62            "$DBUS_DUMP_PATH" "$DBUS_DUMP_ORIGINATOR_IFACE" \
63        "$DBUS_ORIGINATOR_TYPE_STRING")
64
65    ORIGINATOR_ID=$(busctl get-property "$DBUS_DUMP_MANAGER" \
66            "$DBUS_DUMP_PATH" "$DBUS_DUMP_ORIGINATOR_IFACE" \
67        "$DBUS_ORIGINATOR_ID_STRING")
68
69    # The following two lines would extract the originator type and id
70    # from the received long string in response of the above dbus calls
71    # like <s "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal">
72    # to only <Internal> for the originator type and so on for the originator ID
73    ORIGINATOR_TYPE=$(echo "$ORIGINATOR_TYPE" | cut -d' ' -f 2 \
74        | cut -d'.' -f 6 | cut -d'"' -f 1)
75
76    ORIGINATOR_ID=$(echo "$ORIGINATOR_ID" | cut -d' ' -f 2 \
77        | cut -d'"' -f 2)
78
79    # This hash map for Originator Type is populated based on
80    # the info provided by the OriginatedBy.interface.yaml file under
81    # https://github.com/openbmc/phosphor-dbus-interfaces/
82    # Feel free to amend the table as per the evolving requirement
83    local -A originator_type_enum_map
84    originator_type_enum_map["Client"]=0
85    originator_type_enum_map["Internal"]=1
86    originator_type_enum_map["SupportingService"]=2
87
88    local originator_type_mapped="$ORIGINATOR_TYPE"
89    # If the originator type comes something which is not known to
90    # the enum list/map then make it blank so that can be filled
91    # with null bytes in gendumpheader script and won't be
92    # breaking the dump extraction
93    ORIGINATOR_TYPE=""
94    for key in "${!originator_type_enum_map[@]}"
95    do
96        if [ "$key" = "$originator_type_mapped" ]; then
97            ORIGINATOR_TYPE="${originator_type_enum_map[$key]}"
98            break
99        fi
100    done
101}
102