FRU: Fix the area offset calculation of Read FRU Data response

Common header contains the offset of areas
This commit fixes the offset calculation.

Change-Id: Iba002d1832063a329df43834d4e30d359ecaf7b0
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/ipmi_fru_info_area.cpp b/ipmi_fru_info_area.cpp
index 3472f42..24b8f0b 100644
--- a/ipmi_fru_info_area.cpp
+++ b/ipmi_fru_info_area.cpp
@@ -95,7 +95,7 @@
     data.at(areaSizeOffset) = (data.size() + checksumSize) /
         (recordUnitOfMeasurment);
 
-    //Finally add board info checksum
+    //Finally add area checksum
     appendDataChecksum(data);
 }
 
@@ -165,7 +165,7 @@
  * @param[in/out] data Common Header section data container
  */
 void buildCommonHeaderSection(
-    const uint32_t& infoAreaSize, uint32_t& offset, FruAreaData& data)
+    const uint32_t& infoAreaSize, uint16_t& offset, FruAreaData& data)
 {
     //Check if data for internal use section populated
     if (infoAreaSize == 0)
@@ -175,9 +175,14 @@
     }
     else
     {
+        // offset should be multiple of 8.
+        auto remainder = offset % recordUnitOfMeasurment;
+        // add the padding bytes in the offset so that offset
+        // will be multiple of 8 byte.
+        offset += (remainder > 0) ? recordUnitOfMeasurment - remainder : 0;
         //Place data to define offset to area data section
-        data.emplace_back((offset + commonHeaderFormatSize)
-            / recordUnitOfMeasurment);
+        data.emplace_back(offset / recordUnitOfMeasurment);
+
         offset += infoAreaSize;
     }
 }
@@ -304,12 +309,11 @@
 
 FruAreaData buildFruAreaData(const FruInventoryData& inventory)
 {
-    FruAreaData combFruArea;
+    FruAreaData combFruArea{};
     //Now build common header with data for this FRU Inv Record
     //Use this variable to increment size of header as we go along to determine
     //offset for the subsequent area offsets
-    uint32_t curDataOffset = 0;
-
+    uint16_t curDataOffset = commonHeaderFormatSize;
     //First byte is id for version of FRU Info Storage Spec used
     combFruArea.emplace_back(specVersion);
 
@@ -323,6 +327,7 @@
     {
         chassisArea = std::move(buildChassisInfoArea(chassisIt->second));
     }
+    // update the offset to chassis data.
     buildCommonHeaderSection(chassisArea.size(), curDataOffset, combFruArea);
 
     //4th byte is offset to board data
@@ -332,6 +337,8 @@
     {
         boardArea = std::move(buildBoardInfoArea(boardIt->second));
     }
+    // update the offset to the board data.
+    buildCommonHeaderSection(boardArea.size(), curDataOffset, combFruArea);
 
     //5th byte is offset to product data
     FruAreaData prodArea;
@@ -340,13 +347,14 @@
     {
         prodArea = std::move(buildProductInfoArea(prodIt->second));
     }
+    // update the offset to the product data.
     buildCommonHeaderSection(prodArea.size(), curDataOffset, combFruArea);
 
     //6th byte is offset to multirecord data
     combFruArea.emplace_back(recordNotPresent);
 
     //7th byte is PAD
-    padData(combFruArea);
+    combFruArea.emplace_back(recordNotPresent);
 
     //8th (Final byte of Header Format) is the checksum
     appendDataChecksum(combFruArea);