diff options
Diffstat (limited to 'ipmi_fru_info_area.cpp')
-rw-r--r-- | ipmi_fru_info_area.cpp | 195 |
1 files changed, 97 insertions, 98 deletions
diff --git a/ipmi_fru_info_area.cpp b/ipmi_fru_info_area.cpp index ca3fa64..47979e9 100644 --- a/ipmi_fru_info_area.cpp +++ b/ipmi_fru_info_area.cpp @@ -1,10 +1,9 @@ +#include "ipmi_fru_info_area.hpp" + #include <algorithm> +#include <ctime> #include <map> #include <numeric> - -#include <ctime> - -#include "ipmi_fru_info_area.hpp" #include <phosphor-logging/elog.hpp> namespace ipmi { @@ -12,38 +11,38 @@ namespace fru { using namespace phosphor::logging; -//Property variables -static constexpr auto partNumber = "PartNumber"; -static constexpr auto serialNumber = "SerialNumber"; -static constexpr auto manufacturer = "Manufacturer"; -static constexpr auto buildDate = "BuildDate"; -static constexpr auto model = "Model"; -static constexpr auto prettyName = "PrettyName"; -static constexpr auto version = "Version"; - -//Board info areas -static constexpr auto board = "Board"; -static constexpr auto chassis = "Chassis"; -static constexpr auto product = "Product"; - -static constexpr auto specVersion = 0x1; -static constexpr auto recordUnitOfMeasurement = 0x8; //size in bytes -static constexpr auto checksumSize = 0x1; //size in bytes -static constexpr auto recordNotPresent = 0x0; -static constexpr auto englishLanguageCode = 0x0; -static constexpr auto typeLengthByteNull = 0x0; -static constexpr auto endOfCustomFields = 0xC1; -static constexpr auto commonHeaderFormatSize = 0x8; //size in bytes -static constexpr auto manufacturingDateSize = 0x3; -static constexpr auto areaSizeOffset = 0x1; -static constexpr uint8_t typeASCII = 0xC0; -static constexpr auto maxRecordAttributeValue = 0x1F; +// Property variables +static constexpr auto partNumber = "PartNumber"; +static constexpr auto serialNumber = "SerialNumber"; +static constexpr auto manufacturer = "Manufacturer"; +static constexpr auto buildDate = "BuildDate"; +static constexpr auto model = "Model"; +static constexpr auto prettyName = "PrettyName"; +static constexpr auto version = "Version"; + +// Board info areas +static constexpr auto board = "Board"; +static constexpr auto chassis = "Chassis"; +static constexpr auto product = "Product"; + +static constexpr auto specVersion = 0x1; +static constexpr auto recordUnitOfMeasurement = 0x8; // size in bytes +static constexpr auto checksumSize = 0x1; // size in bytes +static constexpr auto recordNotPresent = 0x0; +static constexpr auto englishLanguageCode = 0x0; +static constexpr auto typeLengthByteNull = 0x0; +static constexpr auto endOfCustomFields = 0xC1; +static constexpr auto commonHeaderFormatSize = 0x8; // size in bytes +static constexpr auto manufacturingDateSize = 0x3; +static constexpr auto areaSizeOffset = 0x1; +static constexpr uint8_t typeASCII = 0xC0; +static constexpr auto maxRecordAttributeValue = 0x1F; static constexpr auto secs_from_1970_1996 = 820454400; -static constexpr auto maxMfgDateValue = 0xFFFFFF; //3 Byte length +static constexpr auto maxMfgDateValue = 0xFFFFFF; // 3 Byte length static constexpr auto secs_per_min = 60; -static constexpr auto - secsToMaxMfgdate = secs_from_1970_1996 + secs_per_min * maxMfgDateValue; +static constexpr auto secsToMaxMfgdate = + secs_from_1970_1996 + secs_per_min * maxMfgDateValue; /** * @brief Format Beginning of Individual IPMI FRU Data Section @@ -53,10 +52,10 @@ static constexpr auto */ void preFormatProcessing(bool langCode, FruAreaData& data) { - //Add id for version of FRU Info Storage Spec used + // Add id for version of FRU Info Storage Spec used data.emplace_back(specVersion); - //Add Data Size - 0 as a placeholder, can edit after the data is finalized + // Add Data Size - 0 as a placeholder, can edit after the data is finalized data.emplace_back(typeLengthByteNull); if (langCode) @@ -99,14 +98,14 @@ void padData(FruAreaData& data) */ void postFormatProcessing(FruAreaData& data) { - //This area needs to be padded to a multiple of 8 bytes (after checksum) + // This area needs to be padded to a multiple of 8 bytes (after checksum) padData(data); - //Set size of data info area - data.at(areaSizeOffset) = (data.size() + checksumSize) / - (recordUnitOfMeasurement); + // Set size of data info area + data.at(areaSizeOffset) = + (data.size() + checksumSize) / (recordUnitOfMeasurement); - //Finally add area checksum + // Finally add area checksum appendDataChecksum(data); } @@ -124,35 +123,35 @@ void appendData(const Property& key, const PropertyMap& propMap, if (iter != propMap.end()) { auto value = iter->second; - //If starts with 0x or 0X remove them - //ex: 0x123a just take 123a + // If starts with 0x or 0X remove them + // ex: 0x123a just take 123a if ((value.compare(0, 2, "0x")) == 0 || - (value.compare(0, 2, "0X") == 0)) + (value.compare(0, 2, "0X") == 0)) { value.erase(0, 2); } // 5 bits for length - // if length is greater then 31(2^5) bytes then trim the data to 31 bytess. - auto valueLength = (value.length() > maxRecordAttributeValue) ? - maxRecordAttributeValue : value.length(); + // if length is greater then 31(2^5) bytes then trim the data to 31 + // bytess. + auto valueLength = (value.length() > maxRecordAttributeValue) + ? maxRecordAttributeValue + : value.length(); // 2 bits for type // Set the type to ascii uint8_t typeLength = valueLength | ipmi::fru::typeASCII; data.emplace_back(typeLength); - std::copy(value.begin(), - value.begin() + valueLength, + std::copy(value.begin(), value.begin() + valueLength, std::back_inserter(data)); } else { - //set 0 size + // set 0 size data.emplace_back(typeLengthByteNull); } } - /** * @brief Appends Build Date * @@ -161,7 +160,7 @@ void appendData(const Property& key, const PropertyMap& propMap, */ void appendMfgDate(const PropertyMap& propMap, FruAreaData& data) { - //MFG Date/Time + // MFG Date/Time auto iter = propMap.find(buildDate); if ((iter != propMap.end()) && (iter->second.size() > 0)) { @@ -188,7 +187,7 @@ void appendMfgDate(const PropertyMap& propMap, FruAreaData& data) fprintf(stderr, "MgfDate invalid date: %u secs since UNIX epoch\n", static_cast<unsigned int>(raw)); } - //Blank date + // Blank date data.emplace_back(0); data.emplace_back(0); data.emplace_back(0); @@ -201,13 +200,13 @@ void appendMfgDate(const PropertyMap& propMap, FruAreaData& data) * @param[in] offset Current offset for data in overall record * @param[in/out] data Common Header section data container */ -void buildCommonHeaderSection( - const uint32_t& infoAreaSize, uint16_t& offset, FruAreaData& data) +void buildCommonHeaderSection(const uint32_t& infoAreaSize, uint16_t& offset, + FruAreaData& data) { - //Check if data for internal use section populated + // Check if data for internal use section populated if (infoAreaSize == 0) { - //Indicate record not present + // Indicate record not present data.emplace_back(recordNotPresent); } else @@ -217,7 +216,7 @@ void buildCommonHeaderSection( // add the padding bytes in the offset so that offset // will be multiple of 8 byte. offset += (remainder > 0) ? recordUnitOfMeasurement - remainder : 0; - //Place data to define offset to area data section + // Place data to define offset to area data section data.emplace_back(offset / recordUnitOfMeasurement); offset += infoAreaSize; @@ -235,22 +234,22 @@ FruAreaData buildChassisInfoArea(const PropertyMap& propMap) FruAreaData fruAreaData; if (!propMap.empty()) { - //Set formatting data that goes at the beginning of the record + // Set formatting data that goes at the beginning of the record preFormatProcessing(false, fruAreaData); - //chassis type + // chassis type fruAreaData.emplace_back(0); - //Chasiss part number, in config.yaml it is configured as model + // Chasiss part number, in config.yaml it is configured as model appendData(model, propMap, fruAreaData); - //Board serial number + // Board serial number appendData(serialNumber, propMap, fruAreaData); - //Indicate End of Custom Fields + // Indicate End of Custom Fields fruAreaData.emplace_back(endOfCustomFields); - //Complete record data formatting + // Complete record data formatting postFormatProcessing(fruAreaData); } return fruAreaData; @@ -269,28 +268,28 @@ FruAreaData buildBoardInfoArea(const PropertyMap& propMap) { preFormatProcessing(true, fruAreaData); - //Manufacturing date + // Manufacturing date appendMfgDate(propMap, fruAreaData); - //manufacturer + // manufacturer appendData(manufacturer, propMap, fruAreaData); - //Product name/Pretty name + // Product name/Pretty name appendData(prettyName, propMap, fruAreaData); - //Board serial number + // Board serial number appendData(serialNumber, propMap, fruAreaData); - //Board part number + // Board part number appendData(partNumber, propMap, fruAreaData); - //FRU File ID - Empty + // FRU File ID - Empty fruAreaData.emplace_back(typeLengthByteNull); // Empty FRU File ID bytes fruAreaData.emplace_back(recordNotPresent); - //End of custom fields + // End of custom fields fruAreaData.emplace_back(endOfCustomFields); postFormatProcessing(fruAreaData); @@ -309,34 +308,34 @@ FruAreaData buildProductInfoArea(const PropertyMap& propMap) FruAreaData fruAreaData; if (!propMap.empty()) { - //Set formatting data that goes at the beginning of the record + // Set formatting data that goes at the beginning of the record preFormatProcessing(true, fruAreaData); - //manufacturer + // manufacturer appendData(manufacturer, propMap, fruAreaData); - //Product name/Pretty name + // Product name/Pretty name appendData(prettyName, propMap, fruAreaData); - //Product part/model number + // Product part/model number appendData(model, propMap, fruAreaData); - //Product version + // Product version appendData(version, propMap, fruAreaData); - //Serial Number + // Serial Number appendData(serialNumber, propMap, fruAreaData); - //Add Asset Tag + // Add Asset Tag fruAreaData.emplace_back(recordNotPresent); - //FRU File ID - Empty + // FRU File ID - Empty fruAreaData.emplace_back(typeLengthByteNull); // Empty FRU File ID bytes fruAreaData.emplace_back(recordNotPresent); - //End of custom fields + // End of custom fields fruAreaData.emplace_back(endOfCustomFields); postFormatProcessing(fruAreaData); @@ -347,17 +346,17 @@ FruAreaData buildProductInfoArea(const PropertyMap& propMap) FruAreaData buildFruAreaData(const FruInventoryData& inventory) { 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 + // 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 uint16_t curDataOffset = commonHeaderFormatSize; - //First byte is id for version of FRU Info Storage Spec used + // First byte is id for version of FRU Info Storage Spec used combFruArea.emplace_back(specVersion); - //2nd byte is offset to internal use data + // 2nd byte is offset to internal use data combFruArea.emplace_back(recordNotPresent); - //3rd byte is offset to chassis data + // 3rd byte is offset to chassis data FruAreaData chassisArea; auto chassisIt = inventory.find(chassis); if (chassisIt != inventory.end()) @@ -367,7 +366,7 @@ FruAreaData buildFruAreaData(const FruInventoryData& inventory) // update the offset to chassis data. buildCommonHeaderSection(chassisArea.size(), curDataOffset, combFruArea); - //4th byte is offset to board data + // 4th byte is offset to board data FruAreaData boardArea; auto boardIt = inventory.find(board); if (boardIt != inventory.end()) @@ -377,7 +376,7 @@ FruAreaData buildFruAreaData(const FruInventoryData& inventory) // update the offset to the board data. buildCommonHeaderSection(boardArea.size(), curDataOffset, combFruArea); - //5th byte is offset to product data + // 5th byte is offset to product data FruAreaData prodArea; auto prodIt = inventory.find(product); if (prodIt != inventory.end()) @@ -387,28 +386,28 @@ FruAreaData buildFruAreaData(const FruInventoryData& inventory) // update the offset to the product data. buildCommonHeaderSection(prodArea.size(), curDataOffset, combFruArea); - //6th byte is offset to multirecord data + // 6th byte is offset to multirecord data combFruArea.emplace_back(recordNotPresent); - //7th byte is PAD + // 7th byte is PAD combFruArea.emplace_back(recordNotPresent); - //8th (Final byte of Header Format) is the checksum + // 8th (Final byte of Header Format) is the checksum appendDataChecksum(combFruArea); - //Combine everything into one full IPMI FRU specification Record - //add chassis use area data - combFruArea.insert( - combFruArea.end(), chassisArea.begin(), chassisArea.end()); + // Combine everything into one full IPMI FRU specification Record + // add chassis use area data + combFruArea.insert(combFruArea.end(), chassisArea.begin(), + chassisArea.end()); - //add board area data + // add board area data combFruArea.insert(combFruArea.end(), boardArea.begin(), boardArea.end()); - //add product use area data + // add product use area data combFruArea.insert(combFruArea.end(), prodArea.begin(), prodArea.end()); return combFruArea; } -} //fru -} //ipmi +} // namespace fru +} // namespace ipmi |