Write payload to OCC and read it back

This will utilize the OCC driver to send Amester payload to OCC and
does a read to get the contents of OCC-SRAM and passes it back.

Change-Id: I68627b21665256df6fabad7768bb139dd6d1b99b
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/occ_pass_through.cpp b/occ_pass_through.cpp
index 88a0d29..1b3bffa 100644
--- a/occ_pass_through.cpp
+++ b/occ_pass_through.cpp
@@ -1,6 +1,7 @@
 #include <memory>
 #include <algorithm>
 #include <fcntl.h>
+#include <errno.h>
 #include <phosphor-logging/log.hpp>
 #include "occ_pass_through.hpp"
 #include "occ_finder.hpp"
@@ -62,9 +63,53 @@
 
 std::vector<int32_t> PassThrough::send(std::vector<int32_t> command)
 {
-    return {};
+    using namespace phosphor::logging;
+
+    std::vector<int32_t> response {};
+
+    // Amester packs data in 4 bytes
+    ssize_t size = command.size() * sizeof(int32_t);
+    auto rc = write((fd)(), command.data(), size);
+    if (rc < 0 || (rc != size))
+    {
+        log<level::ERR>("Error writing to OCC");
+
+        // In the next commit, it will have exceptions.
+        return response;
+    }
+
+    // Now read the response. This would be the content of occ-sram
+    while(1)
+    {
+        errno = 0;
+        int32_t data {};
+        auto len = read((fd)(), &data, sizeof(data));
+        if (len > 0)
+        {
+            response.emplace_back(data);
+        }
+        else if (len < 0 && errno == EAGAIN)
+        {
+            // We may have data coming still
+            continue;
+        }
+        else if (len == 0)
+        {
+            // We have read all that we can.
+            break;
+        }
+        else
+        {
+            // Will have exception in the next commit.
+            log<level::ERR>("Error reading from OCC");
+            break;
+        }
+    }
+
+    return response;
 }
 
+
 } // namespace pass_through
 } // namespace occ
 } // namespace open_power