Display pldmtool Base & Bios command output in JSON.
./pldmtool base GetPLDMTypes
[
{
"PLDM Type": "base",
"PLDM Type Code": 0
},
{
"PLDM Type": "platform",
"PLDM Type Code": 2
},
{
"PLDM Type": "bios",
"PLDM Type Code": 3
},
{
"PLDM Type": "fru",
"PLDM Type Code": 4
},
{
"PLDM Type": "oem-ibm",
"PLDM Type Code": 63
}
]
./pldmtool base GetPLDMVersion -t 0
{
"Response": "1.0.0"
}
./pldmtool base GetTID
{
"Response": 1
}
./pldmtool base GetPLDMCommands -t 0
[
{
"PLDM Command Code": 2,
"PLDM Command": "GetTID"
},
{
"PLDM Command Code": 3,
"PLDM Command": "GetPLDMVersion"
},
{
"PLDM Command Code": 4,
"PLDM Command": "GetPLDMTypes"
},
{
"PLDM Command Code": 5,
"PLDM Command": "GetPLDMCommands"
}
]
./pldmtool bios GetDateTime
{
"Response": "2020-10-15 16:33:55"
}
./pldmtool bios GetBIOSTable -t 0
{
"0": "Allowed",
"1": "Disabled",
"2": "Enabled",
"3": "IPv4DHCP",
"4": "IPv4Static",
"5": "Not Allowed",
"6": "OPAL",
"7": "Perm",
"8": "PowerVM",
"9": "Temp",
"10": "hb-hyp-switch",
"11": "pvm-fw-boot-side",
"12": "pvm-inband-code-update",
"13": "pvm-os-boot-side",
"14": "pvm-pcie-error-inject",
"15": "pvm-stop-at-standby",
"16": "pvm-surveillance",
"17": "pvm-system-name",
"18": "vmi-hostname",
"19": "vmi-if-count",
"20": "vmi-if0-ipv4-ipaddr",
"21": "vmi-if0-ipv4-method",
"22": "vmi-if0-ipv4-prefix-length",
"23": "vmi-if1-ipv4-ipaddr",
"24": "vmi-if1-ipv4-method",
"25": "vmi-if1-ipv4-prefix-length",
"26": "vmi-ipv4-gateway"
}
./pldmtool bios GetBIOSTable -t 1
[
{
"AttributeHandle": 0,
"AttributeNameHandle": "17(pvm-system-name)",
"AttributeType": "BIOSString",
"StringType": "0x01",
"MinimumStringLength": 0,
"MaximumStringLength": 100,
"DefaultStringLength": 0,
"DefaultString": ""
},
...
...
{
"AttributeHandle": 16,
"AttributeNameHandle": "15(pvm-stop-at-standby)",
"AttributeType": "BIOSEnumeration",
"NumberOfPossibleValues": 2,
"PossibleValueStringHandle[0]": "1(Disabled)",
"PossibleValueStringHandle[1]": "2(Enabled)",
"NumberOfDefaultValues": 1,
"DefaultValueStringHandleIndex[0]": 1,
"StringHandle": "2(Enabled)"
}
]
./pldmtool bios GetBIOSTable -t 2
[
{
"AttributeHandle": 0,
"AttributeType": "BIOSString",
"CurrentStringLength": 0,
"CurrentString": ""
},
...
...
{
"AttributeHandle": 16,
"AttributeType": "BIOSEnumeration",
"NumberOfCurrentValues": 1,
"CurrentValueStringHandleIndex[0]": "Enabled"
}
]
./pldmtool bios GetBIOSAttributeCurrentValueByHandle -a pvm-pcie-error-inject
{
"CurrentValue": "Enabled"
}
./pldmtool bios SetBIOSAttributeCurrentValue -a vmi-if0-ipv4-method -d IPv4Static
{
"Response": "SUCCESS"
}
Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
Change-Id: If58e2ce380efcad228e4440316cd2653eada9e73
diff --git a/pldmtool/pldm_base_cmd.cpp b/pldmtool/pldm_base_cmd.cpp
index bfcb38a..475932f 100644
--- a/pldmtool/pldm_base_cmd.cpp
+++ b/pldmtool/pldm_base_cmd.cpp
@@ -9,6 +9,8 @@
#include "libpldm/host.h"
#endif
+#include <string>
+
namespace pldmtool
{
@@ -112,25 +114,25 @@
private:
void printPldmTypes(std::vector<bitfield8_t>& types)
{
- std::cout << "Supported types:";
+ ordered_json data;
+ ordered_json jarray;
for (int i = 0; i < PLDM_MAX_TYPES; i++)
{
bitfield8_t b = types[i / 8];
if (b.byte & (1 << i % 8))
{
- std::cout << " " << i;
auto it = std::find_if(
pldmTypes.begin(), pldmTypes.end(),
[i](const auto& typePair) { return typePair.second == i; });
if (it != pldmTypes.end())
{
-
- std::cout << "(" << it->first << ")";
+ jarray["PLDM Type"] = it->first;
+ jarray["PLDM Type Code"] = i;
+ data.emplace_back(jarray);
}
}
}
-
- std::cout << std::endl;
+ pldmtool::helper::DisplayInJson(data);
}
};
@@ -178,16 +180,16 @@
}
char buffer[16] = {0};
ver2str(&version, buffer, sizeof(buffer));
- std::cout << "Type " << pldmType;
+ ordered_json data;
auto it = std::find_if(
pldmTypes.begin(), pldmTypes.end(),
[&](const auto& typePair) { return typePair.second == pldmType; });
if (it != pldmTypes.end())
{
- std::cout << "(" << it->first << ")";
+ data["Response"] = buffer;
}
- std::cout << ": " << buffer << std::endl;
+ pldmtool::helper::DisplayInJson(data);
}
private:
@@ -226,7 +228,9 @@
<< "rc=" << rc << ",cc=" << (int)cc << "\n";
return;
}
- std::cout << "TID : " << static_cast<uint32_t>(tid) << std::endl;
+ ordered_json data;
+ data["Response"] = static_cast<uint32_t>(tid);
+ pldmtool::helper::DisplayInJson(data);
}
};
@@ -279,53 +283,56 @@
pldm_supported_types pldmType;
template <typename CommandMap>
- void printCommand(CommandMap& commandMap, int i)
+ void printCommand(CommandMap& commandMap, int i, ordered_json& jarray)
{
auto it = std::find_if(
commandMap.begin(), commandMap.end(),
[i](const auto& typePair) { return typePair.second == i; });
if (it != commandMap.end())
{
- std::cout << "(" << it->first << ")";
+ jarray["PLDM Command Code"] = i;
+ jarray["PLDM Command"] = it->first;
}
}
void printPldmCommands(std::vector<bitfield8_t>& cmdTypes,
pldm_supported_types pldmType)
{
- std::cout << "Supported Commands :";
+ ordered_json output;
for (int i = 0; i < PLDM_MAX_CMDS_PER_TYPE; i++)
{
+
+ ordered_json cmdinfo;
bitfield8_t b = cmdTypes[i / 8];
if (b.byte & (1 << i % 8))
{
- std::cout << " " << i;
switch (pldmType)
{
case PLDM_BASE:
- printCommand(pldmBaseCmds, i);
+ printCommand(pldmBaseCmds, i, cmdinfo);
break;
case PLDM_PLATFORM:
- printCommand(pldmPlatformCmds, i);
+ printCommand(pldmPlatformCmds, i, cmdinfo);
break;
case PLDM_BIOS:
- printCommand(pldmBiosCmds, i);
+ printCommand(pldmBiosCmds, i, cmdinfo);
break;
case PLDM_FRU:
- printCommand(pldmFruCmds, i);
+ printCommand(pldmFruCmds, i, cmdinfo);
break;
case PLDM_OEM:
#ifdef OEM_IBM
- printCommand(pldmIBMHostCmds, i);
- printCommand(pldmIBMFileIOCmds, i);
+ printCommand(pldmIBMHostCmds, i, cmdinfo);
+ printCommand(pldmIBMFileIOCmds, i, cmdinfo);
#endif
break;
default:
break;
}
+ output.emplace_back(cmdinfo);
}
}
- std::cout << std::endl;
+ pldmtool::helper::DisplayInJson(output);
}
};