Moved the common code and functions between
fru deamons in entitymanager.

Store the common functions/variable declarations
between multiple fru related deamons in the
FruUtils.cpp and FruUtils.hpp files in entitymanager.

TESTED : Built Facebook YosemiteV2 images and loaded
on the target hardware. Verified all the fru's read and write.

Signed-off-by: Kumar Thangavel <thangavel.k@hcl.com>
Change-Id: I42129998603915af7a81f2bb8dff39dc198e8264
diff --git a/include/FruUtils.hpp b/include/FruUtils.hpp
index 5e96696..45fea07 100644
--- a/include/FruUtils.hpp
+++ b/include/FruUtils.hpp
@@ -16,18 +16,36 @@
 /// \file FruUtils.hpp
 
 #pragma once
+#include <boost/container/flat_map.hpp>
 
 #include <cstdint>
 #include <functional>
+#include <regex>
 #include <string>
+#include <utility>
 #include <vector>
-
 extern "C"
 {
 // Include for I2C_SMBUS_BLOCK_MAX
 #include <linux/i2c.h>
 }
 
+constexpr size_t fruBlockSize = 8;
+
+enum class DecodeState
+{
+    ok,
+    end,
+    err,
+};
+
+enum class resCodes
+{
+    resOK,
+    resWarn,
+    resErr
+};
+
 enum class fruAreas
 {
     fruAreaInternal = 0,
@@ -36,19 +54,78 @@
     fruAreaProduct,
     fruAreaMultirecord
 };
+
+const std::vector<std::string> FRU_AREA_NAMES = {"INTERNAL", "CHASSIS", "BOARD",
+                                                 "PRODUCT", "MULTIRECORD"};
+const std::regex NON_ASCII_REGEX("[^\x01-\x7f]");
+
+const std::vector<std::string> CHASSIS_FRU_AREAS = {"PART_NUMBER",
+                                                    "SERIAL_NUMBER"};
+
+const std::vector<std::string> BOARD_FRU_AREAS = {
+    "MANUFACTURER", "PRODUCT_NAME", "SERIAL_NUMBER", "PART_NUMBER",
+    "FRU_VERSION_ID"};
+
+const std::vector<std::string> PRODUCT_FRU_AREAS = {
+    "MANUFACTURER",  "PRODUCT_NAME", "PART_NUMBER",   "VERSION",
+    "SERIAL_NUMBER", "ASSET_TAG",    "FRU_VERSION_ID"};
+
+const std::string FRU_CUSTOM_FIELD_NAME = "INFO_AM";
+
 inline fruAreas operator++(fruAreas& x)
 {
     return x = static_cast<fruAreas>(std::underlying_type<fruAreas>::type(x) +
                                      1);
 }
 
-inline constexpr size_t fruBlockSize =
-    8; // FRU areas are measured in 8-byte blocks
-
 using ReadBlockFunc =
     std::function<int64_t(int flag, int file, uint16_t address, uint16_t offset,
                           uint8_t length, uint8_t* outBuf)>;
 
+inline const std::string& getFruAreaName(fruAreas area)
+{
+    return FRU_AREA_NAMES[static_cast<unsigned int>(area)];
+}
+
+const std::tm intelEpoch(void);
+
+char sixBitToChar(uint8_t val);
+
+/* 0xd - 0xf are reserved values, but not fatal; use a placeholder char. */
+const char bcdHighChars[] = {
+    ' ', '-', '.', 'X', 'X', 'X',
+};
+
+char bcdPlusToChar(uint8_t val);
+
+bool verifyOffset(const std::vector<uint8_t>& fruBytes, fruAreas currentArea,
+                  uint8_t len);
+
+std::pair<DecodeState, std::string>
+    decodeFRUData(std::vector<uint8_t>::const_iterator& iter,
+                  const std::vector<uint8_t>::const_iterator& end,
+                  bool isLangEng);
+
+bool checkLangEng(uint8_t lang);
+
+resCodes
+    formatFRU(const std::vector<uint8_t>& fruBytes,
+              boost::container::flat_map<std::string, std::string>& result);
+
+std::vector<uint8_t>& getFRUInfo(const uint8_t& bus, const uint8_t& address);
+
+uint8_t calculateChecksum(std::vector<uint8_t>::const_iterator iter,
+                          std::vector<uint8_t>::const_iterator end);
+
+uint8_t calculateChecksum(std::vector<uint8_t>& fruAreaData);
+
+unsigned int updateFRUAreaLenAndChecksum(std::vector<uint8_t>& fruData,
+                                         size_t fruAreaStart,
+                                         size_t fruAreaEndOfFieldsOffset,
+                                         size_t fruAreaEndOffset);
+
+ssize_t getFieldLength(uint8_t fruFieldTypeLenValue);
+
 /// \brief Read and validate FRU contents.
 /// \param flag the flag required for raw i2c
 /// \param file the open file handle
@@ -69,16 +146,3 @@
 /// \param area - the area
 /// \return the field offset
 unsigned int getHeaderAreaFieldOffset(fruAreas area);
-
-/// \brief Get name of FRU areas
-/// \param area - the area
-/// \return the name of Fru areas
-std::string getFruAreaName(fruAreas area);
-
-/// \brief verifies overlapping of other offsets against given offset area
-/// \param fruBytes Start of Fru data
-/// \param currentArea Index of current area offset to be compared
-/// \param len Length of current area space
-/// \return true on success
-bool verifyOffset(const std::vector<uint8_t>& fruBytes, fruAreas currentArea,
-                  uint8_t len);