pldmtool: Display GetPDR state set ID possible state names in an array

Note: Also, displays OEM state set and their possible states.
      Created new oem_ibm_state_set.hpp for OEM IBM PDR's possible states.

Example:

{
    "nextRecordHandle": 115,
    "responseCount": 27,
    "recordHandle": 114,
    "PDRHeaderVersion": 1,
    "PDRType": "State Sensor PDR",
    "recordChangeNumber": 0,
    "dataLength": 17,
    "PLDMTerminusHandle": 0,
    "sensorID": 93,
    "entityType": "[Physical] Unspecified",
    "entityInstanceNumber": 0,
    "containerID": 0,
    "sensorInit": "noInit",
    "sensorAuxiliaryNamesPDR": false,
    "compositeSensorCount": 1,
    "stateSetID[0]": "Identify State(17)",
    "possibleStatesSize[0]": 1,
    "possibleStates[0]": [
        "Identify State Unasserted(1)",
        "Identify State Asserted(2)"
    ]
}

{
    "nextRecordHandle": 125,
    "responseCount": 27,
    "recordHandle": 124,
    "PDRHeaderVersion": 1,
    "PDRType": "State Sensor PDR",
    "recordChangeNumber": 0,
    "dataLength": 17,
    "PLDMTerminusHandle": 0,
    "sensorID": 103,
    "entityType": "[Physical] System chassis (main enclosure)",
    "entityInstanceNumber": 1,
    "containerID": 0,
    "sensorInit": "noInit",
    "sensorAuxiliaryNamesPDR": false,
    "compositeSensorCount": 1,
    "stateSetID[0]": "Operational Fault Status(10)",
    "possibleStatesSize[0]": 1,
    "possibleStates[0]": [
        "Normal(1)",
        "Stressed(2)"
    ]
}

{
    "nextRecordHandle": 249,
    "responseCount": 30,
    "recordHandle": 248,
    "PDRHeaderVersion": 1,
    "PDRType": "State Effecter PDR",
    "recordChangeNumber": 0,
    "dataLength": 16,
    "PLDMTerminusHandle": 1,
    "effecterID": 116,
    "entityType": "[Physical] OEM IBM Firmware Update",
    "entityInstanceNumber": 1,
    "containerID": 0,
    "effecterSemanticID": 0,
    "effecterInit": "noInit",
    "effecterDescriptionPDR": false,
    "compositeEffecterCount": 1,
    "stateSetID[0]": "OEM IBM Boot State(32769)",
    "possibleStatesSize[0]": 2,
    "possibleStates[0]": [
        "P Side(1)",
        "T side(2)"
    ]
}

Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
Change-Id: Iae44b14dab071683c86fd65c95e984b9287eca80
diff --git a/pldmtool/oem/ibm/oem_ibm_state_set.hpp b/pldmtool/oem/ibm/oem_ibm_state_set.hpp
new file mode 100644
index 0000000..a804ba1
--- /dev/null
+++ b/pldmtool/oem/ibm/oem_ibm_state_set.hpp
@@ -0,0 +1,105 @@
+#include "oem/ibm/libpldmresponder/oem_ibm_handler.hpp"
+
+using namespace pldm::responder::oem_ibm_platform;
+
+/** @brief PLDM OEM State Set range as per DSP0249_1.1.0 specification
+ */
+enum pldm_oem_state_set_id_codes
+{
+    PLDM_OEM_STATE_SET_START = 32768,
+    PLDM_OEM_STATE_SET_END = 65535,
+
+};
+
+/** @brief PLDM OEM IBM Code Update possible state set values
+ */
+enum pldm_oem_ibm_cu_state_set_values
+{
+    OEM_IBM_STATE_SET_CU_START = 1,
+    OEM_IBM_STATE_SET_CU_END = 2,
+    OEM_IBM_STATE_SET_CU_FAIL = 3,
+    OEM_IBM_STATE_SET_CU_ABORT = 4,
+    OEM_IBM_STATE_SET_CU_ACCEPT = 5,
+    OEM_IBM_STATE_SET_CU_REJECT = 6,
+};
+
+/** @brief PLDM OEM IBM Verification possible state set values
+ */
+enum pldm_oem_ibm_verification_state_set_values
+{
+    OEM_IBM_STATE_SET_VERFICATION_VALID = 0,
+    OEM_IBM_STATE_SET_VERFICATION_ENTITLEMENT_FAIL = 1,
+    OEM_IBM_STATE_SET_VERFICATION_BANNED_PLATFORM_FAIL = 2,
+    OEM_IBM_STATE_SET_VERFICATION_MIN_MIF_FAIL = 4,
+};
+
+/** @brief PLDM OEM IBM system power state possible state set values
+ */
+enum pldm_oem_ibm_sys_power_state_set_values
+{
+    OEM_IBM_STATE_SET_SYS_PWR_STATE_RECYCLE_HARD = 1,
+};
+
+/** @brief PLDM OEM IBM boot state possible state set values
+ */
+enum pldm_oem_ibm_boot_state_set_values
+{
+    OEM_IBM_STATE_SET_BOOT_STATE_P_SIDE = 1,
+    OEM_IBM_STATE_SET_BOOT_STATE_T_SIDE = 2,
+};
+
+/** @brief Map for PLDM OEM IBM Entity Types
+ */
+extern const std::map<uint8_t, std::string> OemIBMEntityType{
+    {PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, "OEM IBM Firmware Update"},
+    {PLDM_OEM_ENTITY_TYPE_START, "OEM IBM Entity Type Start"},
+    {PLDM_OEM_ENTITY_TYPE_END, "OEM IBM Entity Type End"},
+};
+
+/** @brief Map for PLDM OEM IBM State Sets
+ */
+extern const std::map<uint16_t, std::string> OemIBMstateSet{
+    {PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE, "OEM IBM Firmware Update State"},
+    {PLDM_OEM_IBM_BOOT_STATE, "OEM IBM Boot State"},
+    {PLDM_OEM_IBM_VERIFICATION_STATE, "OEM IBM Verification State"},
+    {PLDM_OEM_IBM_SYSTEM_POWER_STATE, "OEM IBM System Power State"}};
+
+/** @brief Map for PLDM OEM IBM firmware update possible state values
+ */
+extern const std::map<uint8_t, std::string> SetOemIBMFWUpdateStateValues{
+    {OEM_IBM_STATE_SET_CU_START, "Start"},
+    {OEM_IBM_STATE_SET_CU_END, "End"},
+    {OEM_IBM_STATE_SET_CU_FAIL, "Fail"},
+    {OEM_IBM_STATE_SET_CU_ABORT, "Abort"},
+    {OEM_IBM_STATE_SET_CU_ACCEPT, "Accept"},
+    {OEM_IBM_STATE_SET_CU_REJECT, "Reject"}};
+
+/** @brief Map for PLDM OEM IBM verification state possible state values
+ */
+extern const std::map<uint8_t, std::string> SetOemIBMVerStateValues{
+    {OEM_IBM_STATE_SET_VERFICATION_VALID, "Valid"},
+    {OEM_IBM_STATE_SET_VERFICATION_ENTITLEMENT_FAIL, "Entitlement Fail"},
+    {OEM_IBM_STATE_SET_VERFICATION_BANNED_PLATFORM_FAIL,
+     "Banned Platform Fail"},
+    {OEM_IBM_STATE_SET_VERFICATION_MIN_MIF_FAIL, "Minimum MIF Fail"}};
+
+/** @brief Map for PLDM OEM IBM systerm power state possible state values
+ */
+extern const std::map<uint8_t, std::string> SetOemIBMSysPowerStatesValues{
+    {OEM_IBM_STATE_SET_SYS_PWR_STATE_RECYCLE_HARD, "Power Cycle Hard"}};
+
+/** @brief Map for PLDM OEM IBM boot state possible state values
+ */
+extern const std::map<uint8_t, std::string> SetOemIBMBootStateValues{
+    {OEM_IBM_STATE_SET_BOOT_STATE_P_SIDE, "P Side"},
+    {OEM_IBM_STATE_SET_BOOT_STATE_T_SIDE, "T side"}};
+
+/** @brief Map for populating PLDM OEM IBM state sets with possible state values
+ */
+extern const std::map<uint16_t, const std::map<uint8_t, std::string>>
+    populateOemIBMStateMaps{
+        {PLDM_OEM_IBM_VERIFICATION_STATE, SetOemIBMVerStateValues},
+        {PLDM_OEM_IBM_SYSTEM_POWER_STATE, SetOemIBMSysPowerStatesValues},
+        {PLDM_OEM_IBM_BOOT_STATE, SetOemIBMBootStateValues},
+        {PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE, SetOemIBMFWUpdateStateValues},
+    };
diff --git a/pldmtool/pldm_platform_cmd.cpp b/pldmtool/pldm_platform_cmd.cpp
index 82b2f95..ce9c39f 100644
--- a/pldmtool/pldm_platform_cmd.cpp
+++ b/pldmtool/pldm_platform_cmd.cpp
@@ -4,6 +4,10 @@
 #include "common/types.hpp"
 #include "pldm_cmd_helper.hpp"
 
+#ifdef OEM_IBM
+#include "oem/ibm/oem_ibm_state_set.hpp"
+#endif
+
 namespace pldmtool
 {
 
@@ -218,7 +222,8 @@
         {PLDM_ENTITY_INTERCONNECT, "Interconnect"},
         {PLDM_ENTITY_PLUG, "Plug"},
         {PLDM_ENTITY_SOCKET, "Socket"},
-        {PLDM_ENTITY_SYSTEM_LOGICAL, "System (Logical)"}};
+        {PLDM_ENTITY_SYSTEM_LOGICAL, "System (Logical)"},
+    };
 
     const std::map<uint16_t, std::string> stateSet = {
         {PLDM_STATE_SET_HEALTH_STATE, "Health State"},
@@ -323,7 +328,8 @@
         {PLDM_STATE_SET_STUCK_BIT_STATUS, "Stuck Bit Status"},
         {PLDM_STATE_SET_SCRUB_STATUS, "Scrub Status"},
         {PLDM_STATE_SET_SLOT_OCCUPANCY, "Slot Occupancy"},
-        {PLDM_STATE_SET_SLOT_STATE, "Slot State"}};
+        {PLDM_STATE_SET_SLOT_STATE, "Slot State"},
+    };
 
     const std::array<std::string_view, 4> sensorInit = {
         "noInit", "useInitPDR", "enableSensor", "disableSensor"};
@@ -360,6 +366,62 @@
         {PLDM_OEM_PDR, "OEM PDR"},
     };
 
+    static inline const std::map<uint8_t, std::string> setThermalTrip{
+        {PLDM_STATE_SET_THERMAL_TRIP_STATUS_NORMAL, "Normal"},
+        {PLDM_STATE_SET_THERMAL_TRIP_STATUS_THERMAL_TRIP, "Thermal Trip"}};
+
+    static inline const std::map<uint8_t, std::string> setIdentifyState{
+        {PLDM_STATE_SET_IDENTIFY_STATE_UNASSERTED, "Identify State Unasserted"},
+        {PLDM_STATE_SET_IDENTIFY_STATE_ASSERTED, "Identify State Asserted"}};
+
+    static inline const std::map<uint8_t, std::string> setBootProgressState{
+        {PLDM_STATE_SET_BOOT_PROG_STATE_NOT_ACTIVE, "Boot Not Active"},
+        {PLDM_STATE_SET_BOOT_PROG_STATE_COMPLETED, "Boot Completed"},
+        {PLDM_STATE_SET_BOOT_PROG_STATE_MEM_INITIALIZATION,
+         "Memory Initialization"},
+        {PLDM_STATE_SET_BOOT_PROG_STATE_SEC_PROC_INITIALIZATION,
+         "Secondary Processor(s) Initialization"},
+        {PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG,
+         "PCI Resource Configuration"},
+        {PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS,
+         "Starting Operating System"},
+        {PLDM_STATE_SET_BOOT_PROG_STATE_BASE_BOARD_INITIALIZATION,
+         "Baseboard Initialization"},
+        {PLDM_STATE_SET_BOOT_PROG_STATE_PRIMARY_PROC_INITIALIZATION,
+         "Primary Processor Initialization"}};
+
+    static inline const std::map<uint8_t, std::string> setOpFaultStatus{
+        {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NORMAL, "Normal"},
+        {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_STRESSED, "Stressed"}};
+
+    static inline const std::map<uint8_t, std::string> setSysPowerState{
+        {PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL,
+         "Off-Soft Graceful"}};
+
+    static inline const std::map<uint8_t, std::string> setSWTerminationStatus{
+        {PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED,
+         "Graceful Restart Requested"}};
+
+    static inline const std::map<uint8_t, std::string> setAvailability{
+        {PLDM_STATE_SET_AVAILABILITY_REBOOTING, "Rebooting"}};
+
+    static inline const std::map<uint8_t, std::string> setHealthState{
+        {PLDM_STATE_SET_HEALTH_STATE_NORMAL, "Normal"},
+        {PLDM_STATE_SET_HEALTH_STATE_UPPER_CRITICAL, "Upper Critical"},
+        {PLDM_STATE_SET_HEALTH_STATE_UPPER_FATAL, "Upper Fatal"}};
+
+    static inline const std::map<uint16_t, const std::map<uint8_t, std::string>>
+        populatePStateMaps{
+            {PLDM_STATE_SET_THERMAL_TRIP, setThermalTrip},
+            {PLDM_STATE_SET_IDENTIFY_STATE, setIdentifyState},
+            {PLDM_STATE_SET_BOOT_PROGRESS, setBootProgressState},
+            {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, setOpFaultStatus},
+            {PLDM_STATE_SET_SYSTEM_POWER_STATE, setSysPowerState},
+            {PLDM_STATE_SET_SW_TERMINATION_STATUS, setSWTerminationStatus},
+            {PLDM_STATE_SET_AVAILABILITY, setAvailability},
+            {PLDM_STATE_SET_HEALTH_STATE, setHealthState},
+        };
+
     bool isLogicalBitSet(const uint16_t entity_type)
     {
         return entity_type & 0x8000;
@@ -387,16 +449,21 @@
         }
         catch (const std::out_of_range& e)
         {
+            auto OemString =
+                std::to_string(static_cast<unsigned>(entityNumber));
             if (type >= PLDM_OEM_ENTITY_TYPE_START &&
                 type <= PLDM_OEM_ENTITY_TYPE_END)
             {
-
-                return entityName +
-                       std::to_string(static_cast<unsigned>(entityNumber)) +
-                       "(OEM)";
+#ifdef OEM_IBM
+                if (OemIBMEntityType.contains(entityNumber))
+                {
+                    return entityName + OemIBMEntityType.at(entityNumber) +
+                           "(OEM)";
+                }
+#endif
+                return entityName + OemString + "(OEM)";
             }
-
-            return std::to_string(static_cast<unsigned>(entityNumber));
+            return OemString;
         }
     }
 
@@ -413,6 +480,48 @@
         }
     }
 
+    std::vector<std::string>
+        getStateSetPossibleStateNames(uint16_t stateId,
+                                      const std::vector<uint8_t>& value)
+    {
+        std::vector<std::string> data{};
+        std::map<uint8_t, std::string> stateNameMaps;
+
+        for (auto& s : value)
+        {
+            std::map<uint8_t, std::string> stateNameMaps;
+            auto pstr = std::to_string(s);
+
+#ifdef OEM_IBM
+            if (stateId >= PLDM_OEM_STATE_SET_START &&
+                stateId <= PLDM_OEM_STATE_SET_END)
+            {
+                if (populateOemIBMStateMaps.contains(stateId))
+                {
+                    const std::map<uint8_t, std::string> stateNames =
+                        populateOemIBMStateMaps.at(stateId);
+                    stateNameMaps.insert(stateNames.begin(), stateNames.end());
+                }
+            }
+#endif
+            if (populatePStateMaps.contains(stateId))
+            {
+                const std::map<uint8_t, std::string> stateNames =
+                    populatePStateMaps.at(stateId);
+                stateNameMaps.insert(stateNames.begin(), stateNames.end());
+            }
+            if (stateNameMaps.contains(s))
+            {
+                data.push_back(stateNameMaps.at(s) + "(" + pstr + ")");
+            }
+            else
+            {
+                data.push_back(pstr);
+            }
+        }
+        return data;
+    }
+
     std::string getPDRType(uint8_t type)
     {
         auto typeString = std::to_string(type);
@@ -435,19 +544,20 @@
         output["dataLength"] = hdr->length;
     }
 
-    std::string printPossibleStates(uint8_t possibleStatesSize,
-                                    const bitfield8_t* states)
+    std::vector<uint8_t> printPossibleStates(uint8_t possibleStatesSize,
+                                             const bitfield8_t* states)
     {
         uint8_t possibleStatesPos{};
-        std::string data;
+        std::vector<uint8_t> data{};
         auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) {
             std::stringstream pstates;
             for (int i = 0; i < CHAR_BIT; i++)
             {
                 if (val.byte & (1 << i))
                 {
-                    pstates << " " << (possibleStatesPos * CHAR_BIT + i);
-                    data.append(pstates.str());
+                    pstates << (possibleStatesPos * CHAR_BIT + i);
+                    data.push_back(
+                        static_cast<uint8_t>(std::stoi(pstates.str())));
                     pstates.str("");
                 }
             }
@@ -484,8 +594,10 @@
                 state->possible_states_size);
             output.emplace(
                 ("possibleStates[" + std::to_string(compCount) + "]"),
-                printPossibleStates(state->possible_states_size,
-                                    state->states));
+                getStateSetPossibleStateNames(
+                    state->state_set_id,
+                    printPossibleStates(state->possible_states_size,
+                                        state->states)));
 
             if (compCount)
             {
@@ -733,8 +845,10 @@
                 state->possible_states_size);
             output.emplace(
                 ("possibleStates[" + std::to_string(compEffCount) + "]"),
-                printPossibleStates(state->possible_states_size,
-                                    state->states));
+                getStateSetPossibleStateNames(
+                    state->state_set_id,
+                    printPossibleStates(state->possible_states_size,
+                                        state->states)));
 
             if (compEffCount)
             {