Enable verbose flag '-v' in pldmtool
Resolves ibm-openbmc/dev/issues/#1753
With verbose support as shown below
pldmtool base GetPLDMTypes
Supported types: 0(base) 2(platform) 3(bios) 4(fru)
pldmtool base GetPLDMTypes -v
Request Message:
08 01 80 00 04
Success in creating the socket : RC = 3
Success in connecting to socket : RC = 0
Success in sending message type as pldm to mctp : RC = 0
Write to socket successful : RC = 5
Total length:5
Loopback response message:
08 01 80 00 04
On first recv(),response == request : RC = 0
Total length:14
Shutdown Socket successful : RC = 0
Response Message:
08 01 00 00 04 00 1d 00 00 00 00 00 00 00
Supported types: 0(base) 2(platform) 3(bios) 4(fru)
./pldmtool bios GetBIOSTable -t 0
PLDM StringTable:
BIOSStringHandle : BIOSString
0 : Allowed
1 : Disabled
2 : Enabled
3 : Not Allowed
4 : Perm
5 : Temp
6 : pvm-fw-boot-side
7 : pvm-inband-code-update
8 : pvm-os-boot-side
9 : pvm-pcie-error-inject
10 : pvm-surveillance
11 : pvm-system-name
12 : vmi-if-count
./pldmtool fru GetFruRecordTableMetadata
FRUDATAMajorVersion : 1
FRUDATAMinorVersion : 0
FRUTableMaximumSize : 4294967295
FRUTableLength : 60
Total number of Record Set Identifiers in table : 1
Total number of records in table : 1
FRU DATAStructureTableIntegrityChecksum : 2516700077
./pldmtool raw -d 0x80 0x00 0x04 0x00 0x00
Request Message:
08 01 80 00 04 00 00
Response Message:
08 01 00 00 04 00 1d 00 00 00 00 00 00 00
./pldmtool raw -d 0x80 0x00 0x04 0x00 0x00 -v
Request Message:
08 01 80 00 04 00 00
Success in creating the socket : RC = 4
Success in connecting to socket : RC = 0
Success in sending message type as pldm to mctp : RC = 0
Write to socket successful : RC = 7
Total length:14
Shutdown Socket successful : RC = 0
Response Message:
08 01 00 00 04 00 0d 00 00 00 00 00 00 00
Change-Id: I476c4492d2ab7e35565e028e201739fd8dafbc82
Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
diff --git a/tool/pldm_cmd_helper.hpp b/tool/pldm_cmd_helper.hpp
index bea01bd..978da83 100644
--- a/tool/pldm_cmd_helper.hpp
+++ b/tool/pldm_cmd_helper.hpp
@@ -31,22 +31,43 @@
/** @brief Print the buffer
*
* @param[in] buffer - Buffer to print
+ * @param[in] pldmVerbose -verbosity flag - true/false
*
* @return - None
*/
-void printBuffer(const std::vector<uint8_t>& buffer);
+void printBuffer(const std::vector<uint8_t>& buffer, bool pldmVerbose);
+/** @brief print the input message if pldmverbose is enabled
+ *
+ * @param[in] pldmVerbose - verbosity flag - true/false
+ * @param[in] msg - message to print
+ * @param[in] data - data to print
+ *
+ * @return - None
+ */
+
+template <class T>
+void Logger(bool pldmverbose, const char* msg, const T& data)
+{
+ if (pldmverbose)
+ {
+ std::stringstream s;
+ s << data;
+ std::cout << msg << s.str() << std::endl;
+ }
+}
/** @brief MCTP socket read/recieve
*
* @param[in] requestMsg - Request message to compare against loopback
* message recieved from mctp socket
* @param[out] responseMsg - Response buffer recieved from mctp socket
+ * @param[in] pldmVerbose - verbosity flag - true/false
*
* @return - 0 on success.
* -1 or -errno on failure.
*/
int mctpSockSendRecv(const std::vector<uint8_t>& requestMsg,
- std::vector<uint8_t>& responseMsg);
+ std::vector<uint8_t>& responseMsg, bool pldmVerbose);
class CommandInterface
{
@@ -58,8 +79,10 @@
commandName(name), mctp_eid(PLDM_ENTITY_ID), instanceId(0)
{
app->add_option("-m,--mctp_eid", mctp_eid, "MCTP endpoint ID");
+ app->add_flag("-v, --verbose", pldmVerbose);
app->callback([&]() { exec(); });
}
+
virtual ~CommandInterface() = default;
virtual std::pair<int, std::vector<uint8_t>> createRequestMsg() = 0;
@@ -76,6 +99,7 @@
const std::string pldmType;
const std::string commandName;
uint8_t mctp_eid;
+ bool pldmVerbose;
protected:
uint8_t instanceId;