ncsi: return command response from sendOemCommand

Rather than expecting the response to be handled from the command
callback, return it as the return value from sendOemCommand().

This addresses the todo in the sendOemCommand implementation.

Change-Id: I144128f50341d4ff7d8e248cb4dfa1427ead515b
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
diff --git a/src/ncsi_netlink_main.cpp b/src/ncsi_netlink_main.cpp
index d5c6fc5..3089b7c 100644
--- a/src/ncsi_netlink_main.cpp
+++ b/src/ncsi_netlink_main.cpp
@@ -17,6 +17,8 @@
 #include "ncsi_util.hpp"
 
 #include <phosphor-logging/lg2.hpp>
+#include <stdplus/numeric/str.hpp>
+#include <stdplus/str/buf.hpp>
 
 #include <string>
 #include <vector>
@@ -72,6 +74,26 @@
     }
 }
 
+static stdplus::StrBuf toHexStr(std::span<const uint8_t> c) noexcept
+{
+    stdplus::StrBuf ret;
+    if (c.empty())
+    {
+        return ret;
+    }
+    stdplus::IntToStr<16, uint8_t> its;
+    auto oit = ret.append(c.size() * 3);
+    auto cit = c.begin();
+    oit = its(oit, *cit++, 2);
+    for (; cit != c.end(); ++cit)
+    {
+        *oit++ = ' ';
+        oit = its(oit, *cit, 2);
+    }
+    *oit = 0;
+    return ret;
+}
+
 int main(int argc, char** argv)
 {
     using namespace phosphor::network;
@@ -182,9 +204,21 @@
             exitWithError("Package not specified.", argv);
         }
 
-        return interface.sendOemCommand(
-            packageInt, channelInt, operationInt,
-            std::span<const unsigned char>(payload.begin(), payload.end()));
+        if (!payload.empty())
+        {
+            lg2::debug("Payload: {PAYLOAD}", "PAYLOAD", toHexStr(payload));
+        }
+
+        auto cmd =
+            std::span<const unsigned char>(payload.begin(), payload.end());
+        auto resp =
+            interface.sendOemCommand(packageInt, channelInt, operationInt, cmd);
+        if (!resp)
+        {
+            return EXIT_FAILURE;
+        }
+        lg2::debug("Response {DATA_LEN} bytes: {DATA}", "DATA_LEN",
+                   resp->size(), "DATA", toHexStr(*resp));
     }
     else if ((options)["set"] == "true")
     {