Add tracing when the BMC PLDM daemon issues GetPDR to host

After PDR trace enabled

Sending Msg:
80 02 51 18 00 00 00 00 00 00 00 01 ff ff 00 00
Receiving Msg:
00 02 51 00 19 00 00 00 00 00 00 00 05 14 00 18 00 00 00 01 14 00 00 0a 00 02 00 40 01 43 00 01 00 01 00
Sending Msg:
80 02 51 19 00 00 00 00 00 00 00 01 ff ff 00 00
Receiving Msg:
00 02 51 00 1a 00 00 00 00 00 00 00 05 14 00 19 00 00 00 01 14 00 00 0a 00 02 00 41 01 43 00 02 00 01 00
Sending Msg:
80 02 51 1a 00 00 00 00 00 00 00 01 ff ff 00 00
Receiving Msg:
00 02 51 00 1b 00 00 00 00 00 00 00 05 14 00 1a 00 00 00 01 14 00 00 0a 00 02 00 c0 20 42 00 01 00 01 00
Sending Msg:
80 02 51 1b 00 00 00 00 00 00 00 01 ff ff 00 00
Receiving Msg:
00 02 51 00 1c 00 00 00 00 00 00 00 05 14 00 1b 00 00 00 01 14 00 00 0a 00 02 00 c2 20 42 00 02 00 01 00

Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
Change-Id: I464de3c128054b381dbba6199f2525ed2b327195
diff --git a/common/utils.cpp b/common/utils.cpp
index ceac7b2..964c04f 100644
--- a/common/utils.cpp
+++ b/common/utils.cpp
@@ -489,5 +489,19 @@
     return PLDM_INVALID_EFFECTER_ID;
 }
 
+void printBuffer(const std::vector<uint8_t>& buffer, bool pldmVerbose)
+{
+    if (pldmVerbose && !buffer.empty())
+    {
+        std::ostringstream tempStream;
+        for (int byte : buffer)
+        {
+            tempStream << std::setfill('0') << std::setw(2) << std::hex << byte
+                       << " ";
+        }
+        std::cout << tempStream.str() << std::endl;
+    }
+}
+
 } // namespace utils
 } // namespace pldm
diff --git a/common/utils.hpp b/common/utils.hpp
index 79a2ba1..710282c 100644
--- a/common/utils.hpp
+++ b/common/utils.hpp
@@ -341,5 +341,14 @@
                                uint8_t sensorOffset, uint8_t eventState,
                                uint8_t previousEventState);
 
+/** @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, bool pldmVerbose);
+
 } // namespace utils
 } // namespace pldm
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index 2e8a0a3..e6bf7d7 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -25,11 +25,11 @@
                                sdeventplus::Event& event, pldm_pdr* repo,
                                const std::string& eventsJsonsDir,
                                pldm_entity_association_tree* entityTree,
-                               Requester& requester) :
+                               Requester& requester, bool verbose) :
     mctp_fd(mctp_fd),
     mctp_eid(mctp_eid), event(event), repo(repo),
     stateSensorHandler(eventsJsonsDir), entityTree(entityTree),
-    requester(requester)
+    requester(requester), verbose(verbose)
 {
     fs::path hostFruJson(fs::path(HOST_JSONS_DIR) / fruJson);
     if (fs::exists(hostFruJson))
@@ -135,6 +135,11 @@
                       << std::endl;
             return;
         }
+        if (verbose)
+        {
+            std::cout << "Sending Msg:" << std::endl;
+            printBuffer(requestMsg, verbose);
+        }
 
         uint8_t* responseMsg = nullptr;
         size_t responseMsgSize{};
@@ -162,6 +167,15 @@
             responsePtr, responseMsgSize - sizeof(pldm_msg_hdr),
             &completionCode, &nextRecordHandle, &nextDataTransferHandle,
             &transferFlag, &respCount, nullptr, 0, &transferCRC);
+
+        std::vector<uint8_t> responsePDRMsg;
+        responsePDRMsg.resize(responseMsgSize);
+        memcpy(responsePDRMsg.data(), responsePtr, responsePDRMsg.size());
+        if (verbose)
+        {
+            std::cout << "Receiving Msg:" << std::endl;
+            printBuffer(responsePDRMsg, verbose);
+        }
         if (rc != PLDM_SUCCESS)
         {
             std::cerr << "Failed to decode_get_pdr_resp, rc = " << rc
diff --git a/host-bmc/host_pdr_handler.hpp b/host-bmc/host_pdr_handler.hpp
index 3c998a2..a8866a2 100644
--- a/host-bmc/host_pdr_handler.hpp
+++ b/host-bmc/host_pdr_handler.hpp
@@ -89,7 +89,7 @@
                             sdeventplus::Event& event, pldm_pdr* repo,
                             const std::string& eventsJsonsDir,
                             pldm_entity_association_tree* entityTree,
-                            Requester& requester);
+                            Requester& requester, bool verbose = false);
 
     /** @brief fetch PDRs from host firmware. See @class.
      *  @param[in] recordHandles - list of record handles pointing to host's
@@ -195,6 +195,7 @@
      *         PlatformEventMessage command request.
      */
     HostStateSensorMap sensorMap;
+    bool verbose;
 };
 
 } // namespace pldm
diff --git a/pldmd/pldmd.cpp b/pldmd/pldmd.cpp
index c1c864c..86171c8 100644
--- a/pldmd/pldmd.cpp
+++ b/pldmd/pldmd.cpp
@@ -103,21 +103,6 @@
     return response;
 }
 
-void printBuffer(const std::vector<uint8_t>& buffer)
-{
-    std::ostringstream tempStream;
-    tempStream << "Buffer Data: ";
-    if (!buffer.empty())
-    {
-        for (int byte : buffer)
-        {
-            tempStream << std::setfill('0') << std::setw(2) << std::hex << byte
-                       << " ";
-        }
-    }
-    std::cout << tempStream.str().c_str() << std::endl;
-}
-
 void optionUsage(void)
 {
     std::cerr << "Usage: pldmd [options]\n";
@@ -185,7 +170,7 @@
     {
         hostPDRHandler = std::make_unique<HostPDRHandler>(
             sockfd, hostEID, event, pdrRepo.get(), EVENTS_JSONS_DIR,
-            entityTree.get(), dbusImplReq);
+            entityTree.get(), dbusImplReq, verbose);
         hostEffecterParser =
             std::make_unique<pldm::host_effecters::HostEffecterParser>(
                 &dbusImplReq, sockfd, pdrRepo.get(), dbusHandler.get(),
@@ -300,7 +285,7 @@
                 if (verbose)
                 {
                     std::cout << "Received Msg" << std::endl;
-                    printBuffer(requestMsg);
+                    printBuffer(requestMsg, verbose);
                 }
                 if (MCTP_MSG_TYPE_PLDM != requestMsg[1])
                 {
@@ -318,7 +303,7 @@
                         if (verbose)
                         {
                             std::cout << "Sending Msg" << std::endl;
-                            printBuffer(response);
+                            printBuffer(response, verbose);
                         }
 
                         iov[0].iov_base = &requestMsg[0];
diff --git a/pldmtool/pldm_cmd_helper.cpp b/pldmtool/pldm_cmd_helper.cpp
index 7002c79..10e051f 100644
--- a/pldmtool/pldm_cmd_helper.cpp
+++ b/pldmtool/pldm_cmd_helper.cpp
@@ -17,23 +17,6 @@
 namespace helper
 {
 /*
- * print the input buffer if pldm verbosity is enabled.
- *
- */
-void printBuffer(const std::vector<uint8_t>& buffer, bool pldmVerbose)
-{
-    if (pldmVerbose && !buffer.empty())
-    {
-        std::ostringstream tempStream;
-        for (int byte : buffer)
-        {
-            tempStream << std::setfill('0') << std::setw(2) << std::hex << byte
-                       << " ";
-        }
-        std::cout << tempStream.str() << std::endl;
-    }
-}
-/*
  * Initialize the socket, send pldm command & recieve response from socket
  *
  */
diff --git a/pldmtool/pldm_cmd_helper.hpp b/pldmtool/pldm_cmd_helper.hpp
index d71d0d3..bd890d9 100644
--- a/pldmtool/pldm_cmd_helper.hpp
+++ b/pldmtool/pldm_cmd_helper.hpp
@@ -31,15 +31,6 @@
 constexpr uint8_t MCTP_MSG_TYPE_PLDM = 1;
 using ordered_json = nlohmann::ordered_json;
 
-/** @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, bool pldmVerbose);
-
 /** @brief print the input message if pldmverbose is enabled
  *
  *  @param[in]  pldmVerbose - verbosity flag - true/false