summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.clang-format99
-rw-r--r--argument.cpp30
-rw-r--r--argument.hpp25
-rw-r--r--fru-area.hpp278
-rw-r--r--frup.cpp1242
-rw-r--r--frup.hpp117
-rw-r--r--readeeprom.cpp20
-rw-r--r--strgfnhandler.cpp44
-rw-r--r--types.hpp22
-rw-r--r--writefrudata.cpp258
-rw-r--r--writefrudata.hpp30
11 files changed, 1086 insertions, 1079 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..ea71ad6
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,99 @@
+---
+Language: Cpp
+# BasedOnStyle: LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: true
+ AfterStruct: true
+ AfterUnion: true
+ BeforeCatch: true
+ BeforeElse: true
+ IndentBraces: false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: AfterColon
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+PointerAlignment: Left
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeBlocks: Regroup
+IncludeCategories:
+ - Regex: '^[<"](gtest|gmock)'
+ Priority: 5
+ - Regex: '^"config.h"'
+ Priority: -1
+ - Regex: '^".*\.hpp"'
+ Priority: 1
+ - Regex: '^<.*\.h>'
+ Priority: 2
+ - Regex: '^<.*'
+ Priority: 3
+ - Regex: '.*'
+ Priority: 4
+IndentCaseLabels: true
+IndentWidth: 4
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+ReflowComments: true
+SortIncludes: true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 4
+UseTab: Never
+...
+
diff --git a/argument.cpp b/argument.cpp
index a988ca5..f46206a 100644
--- a/argument.cpp
+++ b/argument.cpp
@@ -1,13 +1,14 @@
-#include <iostream>
-#include <iterator>
+#include "argument.hpp"
+
#include <algorithm>
#include <cassert>
-#include "argument.hpp"
+#include <iostream>
+#include <iterator>
ArgumentParser::ArgumentParser(int argc, char** argv)
{
int option = 0;
- while(-1 != (option = getopt_long(argc, argv, optionstr, options, NULL)))
+ while (-1 != (option = getopt_long(argc, argv, optionstr, options, NULL)))
{
if ((option == '?') || (option == 'h'))
{
@@ -16,7 +17,8 @@ ArgumentParser::ArgumentParser(int argc, char** argv)
}
auto i = &options[0];
- while ((i->val != option) && (i->val != 0)) ++i;
+ while ((i->val != option) && (i->val != 0))
+ ++i;
if (i->val)
arguments[i->name] = (i->has_arg ? optarg : true_string);
@@ -41,19 +43,17 @@ void ArgumentParser::usage(char** argv)
std::cerr << "Usage: " << argv[0] << " [options]" << std::endl;
std::cerr << "Options:" << std::endl;
std::cerr << " --eeprom=<eeprom file path> Absolute file name of eeprom"
- << std::endl;
+ << std::endl;
std::cerr << " --fruid=<FRU ID> valid fru id in integer"
- << std::endl;
- std::cerr << " --help display help"
- << std::endl;
+ << std::endl;
+ std::cerr << " --help display help" << std::endl;
}
-const option ArgumentParser::options[] =
-{
- { "eeprom", required_argument, NULL, 'e' },
- { "fruid", required_argument, NULL, 'f' },
- { "help", no_argument, NULL, 'h' },
- { 0, 0, 0, 0},
+const option ArgumentParser::options[] = {
+ {"eeprom", required_argument, NULL, 'e'},
+ {"fruid", required_argument, NULL, 'f'},
+ {"help", no_argument, NULL, 'h'},
+ {0, 0, 0, 0},
};
const char* ArgumentParser::optionstr = "e:f:?h";
diff --git a/argument.hpp b/argument.hpp
index bd3b0b2..849ccb5 100644
--- a/argument.hpp
+++ b/argument.hpp
@@ -1,27 +1,28 @@
#ifndef __ARGUMENT_H
#define __ARGUMENT_H
#include <getopt.h>
+
#include <map>
#include <string>
class ArgumentParser
{
- public:
- ArgumentParser(int argc, char** argv);
- const std::string& operator[](const std::string& opt);
+ public:
+ ArgumentParser(int argc, char** argv);
+ const std::string& operator[](const std::string& opt);
- static void usage(char** argv);
+ static void usage(char** argv);
- static const std::string true_string;
- static const std::string empty_string;
+ static const std::string true_string;
+ static const std::string empty_string;
- private:
- std::map<const std::string, std::string> arguments;
+ private:
+ std::map<const std::string, std::string> arguments;
- static const option options[];
- static const char* optionstr;
+ static const option options[];
+ static const char* optionstr;
- private:
- ArgumentParser() {};
+ private:
+ ArgumentParser(){};
};
#endif
diff --git a/fru-area.hpp b/fru-area.hpp
index d040a9c..278b46f 100644
--- a/fru-area.hpp
+++ b/fru-area.hpp
@@ -1,154 +1,156 @@
#ifndef __IPMI_FRU_AREA_H__
#define __IPMI_FRU_AREA_H__
-#include <stdint.h>
+#include "frup.hpp"
+#include "writefrudata.hpp"
+
#include <stddef.h>
+#include <stdint.h>
#include <systemd/sd-bus.h>
+
+#include <memory>
#include <string>
#include <vector>
-#include <memory>
-#include "frup.hpp"
-#include "writefrudata.hpp"
class ipmi_fru;
typedef std::vector<std::unique_ptr<ipmi_fru>> fru_area_vec_t;
class ipmi_fru
{
- private:
- // Unique way of identifying a FRU
- uint8_t iv_fruid = 0;
-
- // Type of the fru matching offsets in common header
- ipmi_fru_area_type iv_type = IPMI_FRU_AREA_INTERNAL_USE;
-
- // Name of the fru area. ( BOARD/CHASSIS/PRODUCT )
- std::string iv_name;
-
- // Length of a specific fru area.
- size_t iv_len = 0;
-
- // Special bit for BMC readable eeprom only.
- bool iv_bmc_fru = false;
-
- // If a FRU is physically present.
- bool iv_present = false;
-
- // Whether a particular area is valid ?
- bool iv_valid = false;
-
- // Actual area data.
- uint8_t *iv_data = nullptr;
-
- // fru inventory dbus name
- std::string iv_bus_name;
-
- // fru inventory dbus object path
- std::string iv_obj_path;
-
- // fru inventory dbus interface name
- std::string iv_intf_name;
-
- // sd_bus handle
- sd_bus *iv_bus_type = nullptr;
-
- // Default constructor disabled.
- ipmi_fru();
-
- public:
- // constructor
- ipmi_fru(const uint8_t fruid, const ipmi_fru_area_type type,
- sd_bus *bus_type, bool bmc_fru = false);
-
- // Destructor
- virtual ~ipmi_fru();
-
- // If a particular area has been marked valid / invalid
- inline bool is_valid() const
- {
- return iv_valid;
- }
-
- // Sets the present bit
- inline void set_present(const bool present)
- {
- iv_present = present;
- }
-
- // Sets the valid bit for a corresponding area.
- inline void set_valid(const bool valid)
- {
- iv_valid = valid;
- }
-
- // If a particular area accessible only by BMC
- inline bool is_bmc_fru() const
- {
- return iv_bmc_fru;
- }
-
- // returns fru id;
- uint8_t get_fruid() const
- {
- return iv_fruid;
- }
-
- // Returns the length.
- size_t get_len() const
- {
- return iv_len;
- }
-
- // Returns the type of the current fru area
- ipmi_fru_area_type get_type() const
- {
- return iv_type;
- }
-
- // Returns the name
- const char *get_name() const
- {
- return iv_name.c_str();
- }
-
- // Returns SD bus name
- const char *get_bus_name() const
- {
- return iv_bus_name.c_str();
- }
-
- // Retrns SD bus object path
- const char *get_obj_path() const
- {
- return iv_obj_path.c_str();
- }
-
- // Returns SD bus interface name
- const char *get_intf_name() const
- {
- return iv_intf_name.c_str();
- }
-
- // Returns the data portion
- inline uint8_t *get_data() const
- {
- return iv_data;
- }
-
- // Returns the bus type.
- inline sd_bus *get_bus_type() const
- {
- return iv_bus_type;
- }
-
- // Sets up the sd_bus variables for the given AREA type
- int setup_sd_bus_paths(void);
-
- // Accepts a pointer to data and sets it in the object.
- void set_data(const uint8_t *, const size_t);
-
- // Sets the dbus parameters
- void update_dbus_paths(const char *, const char *, const char *);
+ private:
+ // Unique way of identifying a FRU
+ uint8_t iv_fruid = 0;
+
+ // Type of the fru matching offsets in common header
+ ipmi_fru_area_type iv_type = IPMI_FRU_AREA_INTERNAL_USE;
+
+ // Name of the fru area. ( BOARD/CHASSIS/PRODUCT )
+ std::string iv_name;
+
+ // Length of a specific fru area.
+ size_t iv_len = 0;
+
+ // Special bit for BMC readable eeprom only.
+ bool iv_bmc_fru = false;
+
+ // If a FRU is physically present.
+ bool iv_present = false;
+
+ // Whether a particular area is valid ?
+ bool iv_valid = false;
+
+ // Actual area data.
+ uint8_t* iv_data = nullptr;
+
+ // fru inventory dbus name
+ std::string iv_bus_name;
+
+ // fru inventory dbus object path
+ std::string iv_obj_path;
+
+ // fru inventory dbus interface name
+ std::string iv_intf_name;
+
+ // sd_bus handle
+ sd_bus* iv_bus_type = nullptr;
+
+ // Default constructor disabled.
+ ipmi_fru();
+
+ public:
+ // constructor
+ ipmi_fru(const uint8_t fruid, const ipmi_fru_area_type type,
+ sd_bus* bus_type, bool bmc_fru = false);
+
+ // Destructor
+ virtual ~ipmi_fru();
+
+ // If a particular area has been marked valid / invalid
+ inline bool is_valid() const
+ {
+ return iv_valid;
+ }
+
+ // Sets the present bit
+ inline void set_present(const bool present)
+ {
+ iv_present = present;
+ }
+
+ // Sets the valid bit for a corresponding area.
+ inline void set_valid(const bool valid)
+ {
+ iv_valid = valid;
+ }
+
+ // If a particular area accessible only by BMC
+ inline bool is_bmc_fru() const
+ {
+ return iv_bmc_fru;
+ }
+
+ // returns fru id;
+ uint8_t get_fruid() const
+ {
+ return iv_fruid;
+ }
+
+ // Returns the length.
+ size_t get_len() const
+ {
+ return iv_len;
+ }
+
+ // Returns the type of the current fru area
+ ipmi_fru_area_type get_type() const
+ {
+ return iv_type;
+ }
+
+ // Returns the name
+ const char* get_name() const
+ {
+ return iv_name.c_str();
+ }
+
+ // Returns SD bus name
+ const char* get_bus_name() const
+ {
+ return iv_bus_name.c_str();
+ }
+
+ // Retrns SD bus object path
+ const char* get_obj_path() const
+ {
+ return iv_obj_path.c_str();
+ }
+
+ // Returns SD bus interface name
+ const char* get_intf_name() const
+ {
+ return iv_intf_name.c_str();
+ }
+
+ // Returns the data portion
+ inline uint8_t* get_data() const
+ {
+ return iv_data;
+ }
+
+ // Returns the bus type.
+ inline sd_bus* get_bus_type() const
+ {
+ return iv_bus_type;
+ }
+
+ // Sets up the sd_bus variables for the given AREA type
+ int setup_sd_bus_paths(void);
+
+ // Accepts a pointer to data and sets it in the object.
+ void set_data(const uint8_t*, const size_t);
+
+ // Sets the dbus parameters
+ void update_dbus_paths(const char*, const char*, const char*);
};
#endif
diff --git a/frup.cpp b/frup.cpp
index 8009b3e..b3b2942 100644
--- a/frup.cpp
+++ b/frup.cpp
@@ -39,52 +39,53 @@
* You should have received a copy of the GNU General Public License along
* with Ipmi-fru. If not, see <http://www.gnu.org/licenses/>.
\*****************************************************************************/
+#include "frup.hpp"
+
+#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#include <string.h>
-#include <time.h>
#include <systemd/sd-bus.h>
-#include <ctype.h>
-#include "frup.hpp"
+#include <time.h>
+#include <unistd.h>
#define TEXTSTR(a) #a
-# define ASSERT(x) \
-do { \
-if (0 == (x)) { \
-fprintf(stderr, \
-"Assertion failed: %s, " \
-"%d at \'%s\'\n", \
-__FILE__, \
-__LINE__, \
-TEXTSTR(a)); \
-return -1; \
-} \
-} while (0)
-
-#define IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX 512
-#define IPMI_FRU_SENTINEL_VALUE 0xC1
-#define IPMI_FRU_TYPE_LENGTH_TYPE_CODE_MASK 0xC0
-#define IPMI_FRU_TYPE_LENGTH_TYPE_CODE_SHIFT 0x06
+#define ASSERT(x) \
+ do \
+ { \
+ if (0 == (x)) \
+ { \
+ fprintf(stderr, \
+ "Assertion failed: %s, " \
+ "%d at \'%s\'\n", \
+ __FILE__, __LINE__, TEXTSTR(a)); \
+ return -1; \
+ } \
+ } while (0)
+
+#define IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX 512
+#define IPMI_FRU_SENTINEL_VALUE 0xC1
+#define IPMI_FRU_TYPE_LENGTH_TYPE_CODE_MASK 0xC0
+#define IPMI_FRU_TYPE_LENGTH_TYPE_CODE_SHIFT 0x06
#define IPMI_FRU_TYPE_LENGTH_NUMBER_OF_DATA_BYTES_MASK 0x3F
-#define IPMI_FRU_TYPE_LENGTH_TYPE_CODE_LANGUAGE_CODE 0x03
+#define IPMI_FRU_TYPE_LENGTH_TYPE_CODE_LANGUAGE_CODE 0x03
/* OpenBMC defines for Parser */
-#define IPMI_FRU_AREA_INTERNAL_USE 0x00
-#define IPMI_FRU_AREA_CHASSIS_INFO 0x01
-#define IPMI_FRU_AREA_BOARD_INFO 0x02
-#define IPMI_FRU_AREA_PRODUCT_INFO 0x03
-#define IPMI_FRU_AREA_MULTI_RECORD 0x04
-#define IPMI_FRU_AREA_TYPE_MAX 0x05
+#define IPMI_FRU_AREA_INTERNAL_USE 0x00
+#define IPMI_FRU_AREA_CHASSIS_INFO 0x01
+#define IPMI_FRU_AREA_BOARD_INFO 0x02
+#define IPMI_FRU_AREA_PRODUCT_INFO 0x03
+#define IPMI_FRU_AREA_MULTI_RECORD 0x04
+#define IPMI_FRU_AREA_TYPE_MAX 0x05
-#define OPENBMC_VPD_KEY_LEN 64
-#define OPENBMC_VPD_VAL_LEN 512
+#define OPENBMC_VPD_KEY_LEN 64
+#define OPENBMC_VPD_VAL_LEN 512
struct ipmi_fru_field
{
- uint8_t type_length_field[IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX];
- /* store length of data stored in buffer */
- unsigned int type_length_field_length;
+ uint8_t type_length_field[IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX];
+ /* store length of data stored in buffer */
+ unsigned int type_length_field_length;
};
typedef struct ipmi_fru_field ipmi_fru_field_t;
@@ -108,622 +109,523 @@ typedef struct ipmi_fru_common_hdr
uint8_t multirec;
} __attribute__((packed)) ipmi_fru_common_hdr_t;
-const char* vpd_key_names [] =
-{
- "Key Names Table Start",
- "Type", /*OPENBMC_VPD_KEY_CHASSIS_TYPE*/
- "Part Number", /*OPENBMC_VPD_KEY_CHASSIS_PART_NUM,*/
- "Serial Number", /*OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM,*/
- "Custom Field 1", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM1,*/
- "Custom Field 2", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM2,*/
- "Custom Field 3", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM3,*/
- "Custom Field 4", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM4,*/
- "Custom Field 5", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM5,*/
- "Custom Field 6", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM6,*/
- "Custom Field 7", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM7,*/
- "Custom Field 8", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM8,*/
-
- "Mfg Date", /* OPENBMC_VPD_KEY_BOARD_MFG_DATE, */ /* not a type/len */
- "Manufacturer", /* OPENBMC_VPD_KEY_BOARD_MFR, */
- "Name", /* OPENBMC_VPD_KEY_BOARD_NAME, */
- "Serial Number", /* OPENBMC_VPD_KEY_BOARD_SERIAL_NUM, */
- "Part Number", /* OPENBMC_VPD_KEY_BOARD_PART_NUM, */
- "FRU File ID", /* OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID, */
- "Custom Field 1", /*OPENBMC_VPD_KEY_BOARD_CUSTOM1,*/
- "Custom Field 2", /*OPENBMC_VPD_KEY_BOARD_CUSTOM2,*/
- "Custom Field 3", /*OPENBMC_VPD_KEY_BOARD_CUSTOM3,*/
- "Custom Field 4", /*OPENBMC_VPD_KEY_BOARD_CUSTOM4,*/
- "Custom Field 5", /*OPENBMC_VPD_KEY_BOARD_CUSTOM5,*/
- "Custom Field 6", /*OPENBMC_VPD_KEY_BOARD_CUSTOM6,*/
- "Custom Field 7", /*OPENBMC_VPD_KEY_BOARD_CUSTOM7,*/
- "Custom Field 8", /*OPENBMC_VPD_KEY_BOARD_CUSTOM8,*/
-
- "Manufacturer", /* OPENBMC_VPD_KEY_PRODUCT_MFR, */
- "Name", /* OPENBMC_VPD_KEY_PRODUCT_NAME, */
- "Model Number", /* OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM, */
- "Version", /* OPENBMC_VPD_KEY_PRODUCT_VER, */
- "Serial Number", /* OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM, */
- "Asset Tag", /* OPENBMC_VPD_KEY_PRODUCT_ASSET_TAG, */
- "FRU File ID", /* OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID, */
- "Custom Field 1", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM1,*/
- "Custom Field 2", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM2,*/
- "Custom Field 3", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM3,*/
- "Custom Field 4", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM4,*/
- "Custom Field 5", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM5,*/
- "Custom Field 6", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM6,*/
- "Custom Field 7", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM7,*/
- "Custom Field 8", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM8,*/
-
- "Key Names Table End" /*OPENBMC_VPD_KEY_MAX,*/
+const char* vpd_key_names[] = {
+ "Key Names Table Start",
+ "Type", /*OPENBMC_VPD_KEY_CHASSIS_TYPE*/
+ "Part Number", /*OPENBMC_VPD_KEY_CHASSIS_PART_NUM,*/
+ "Serial Number", /*OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM,*/
+ "Custom Field 1", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM1,*/
+ "Custom Field 2", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM2,*/
+ "Custom Field 3", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM3,*/
+ "Custom Field 4", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM4,*/
+ "Custom Field 5", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM5,*/
+ "Custom Field 6", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM6,*/
+ "Custom Field 7", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM7,*/
+ "Custom Field 8", /*OPENBMC_VPD_KEY_CHASSIS_CUSTOM8,*/
+
+ "Mfg Date",
+ /* OPENBMC_VPD_KEY_BOARD_MFG_DATE, */ /* not a type/len */
+ "Manufacturer", /* OPENBMC_VPD_KEY_BOARD_MFR, */
+ "Name", /* OPENBMC_VPD_KEY_BOARD_NAME, */
+ "Serial Number", /* OPENBMC_VPD_KEY_BOARD_SERIAL_NUM, */
+ "Part Number", /* OPENBMC_VPD_KEY_BOARD_PART_NUM, */
+ "FRU File ID", /* OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID, */
+ "Custom Field 1", /*OPENBMC_VPD_KEY_BOARD_CUSTOM1,*/
+ "Custom Field 2", /*OPENBMC_VPD_KEY_BOARD_CUSTOM2,*/
+ "Custom Field 3", /*OPENBMC_VPD_KEY_BOARD_CUSTOM3,*/
+ "Custom Field 4", /*OPENBMC_VPD_KEY_BOARD_CUSTOM4,*/
+ "Custom Field 5", /*OPENBMC_VPD_KEY_BOARD_CUSTOM5,*/
+ "Custom Field 6", /*OPENBMC_VPD_KEY_BOARD_CUSTOM6,*/
+ "Custom Field 7", /*OPENBMC_VPD_KEY_BOARD_CUSTOM7,*/
+ "Custom Field 8", /*OPENBMC_VPD_KEY_BOARD_CUSTOM8,*/
+
+ "Manufacturer", /* OPENBMC_VPD_KEY_PRODUCT_MFR, */
+ "Name", /* OPENBMC_VPD_KEY_PRODUCT_NAME, */
+ "Model Number", /* OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM, */
+ "Version", /* OPENBMC_VPD_KEY_PRODUCT_VER, */
+ "Serial Number", /* OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM, */
+ "Asset Tag", /* OPENBMC_VPD_KEY_PRODUCT_ASSET_TAG, */
+ "FRU File ID", /* OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID, */
+ "Custom Field 1", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM1,*/
+ "Custom Field 2", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM2,*/
+ "Custom Field 3", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM3,*/
+ "Custom Field 4", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM4,*/
+ "Custom Field 5", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM5,*/
+ "Custom Field 6", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM6,*/
+ "Custom Field 7", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM7,*/
+ "Custom Field 8", /*OPENBMC_VPD_KEY_PRODUCT_CUSTOM8,*/
+
+ "Key Names Table End" /*OPENBMC_VPD_KEY_MAX,*/
};
-
/*
* --------------------------------------------------------------------
*
* --------------------------------------------------------------------
*/
-static size_t _to_time_str (uint32_t mfg_date_time, char* timestr, uint32_t len)
+static size_t _to_time_str(uint32_t mfg_date_time, char* timestr, uint32_t len)
{
struct tm tm;
time_t t;
size_t s;
- ASSERT (timestr);
- ASSERT (len);
+ ASSERT(timestr);
+ ASSERT(len);
- memset (&tm, '\0', sizeof (struct tm));
+ memset(&tm, '\0', sizeof(struct tm));
t = mfg_date_time;
- gmtime_r (&t, &tm);
- s = strftime (timestr, len, "%F - %H:%M:%S", &tm);
+ gmtime_r(&t, &tm);
+ s = strftime(timestr, len, "%F - %H:%M:%S", &tm);
return s;
}
/* private method to parse type/length */
-static int
-_parse_type_length (const void *areabuf,
- unsigned int areabuflen,
- unsigned int current_area_offset,
- uint8_t *number_of_data_bytes,
- ipmi_fru_field_t *field)
+static int _parse_type_length(const void* areabuf, unsigned int areabuflen,
+ unsigned int current_area_offset,
+ uint8_t* number_of_data_bytes,
+ ipmi_fru_field_t* field)
{
- const uint8_t *areabufptr = (const uint8_t*) areabuf;
- uint8_t type_length;
- uint8_t type_code;
-
- ASSERT (areabuf);
- ASSERT (areabuflen);
- ASSERT (number_of_data_bytes);
-
- type_length = areabufptr[current_area_offset];
-
- /* ipmi workaround
- *
- * dell p weredge r610
- *
- * my reading of the fru spec is that all non-custom fields are
- * required to be listed by the vendor. however, on this
- * motherboard, some areas list this, indicating that there is
- * no more data to be parsed. so now, for "required" fields, i
- * check to see if the type-length field is a sentinel before
- * calling this function.
- */
-
- ASSERT (type_length != IPMI_FRU_SENTINEL_VALUE);
-
- type_code = (type_length & IPMI_FRU_TYPE_LENGTH_TYPE_CODE_MASK) >> IPMI_FRU_TYPE_LENGTH_TYPE_CODE_SHIFT;
- (*number_of_data_bytes) = type_length & IPMI_FRU_TYPE_LENGTH_NUMBER_OF_DATA_BYTES_MASK;
-
- /* special case: this shouldn't be a length of 0x01 (see type/length
- * byte format in fru information storage definition).
- */
- if (type_code == IPMI_FRU_TYPE_LENGTH_TYPE_CODE_LANGUAGE_CODE
- && (*number_of_data_bytes) == 0x01)
+ const uint8_t* areabufptr = (const uint8_t*)areabuf;
+ uint8_t type_length;
+ uint8_t type_code;
+
+ ASSERT(areabuf);
+ ASSERT(areabuflen);
+ ASSERT(number_of_data_bytes);
+
+ type_length = areabufptr[current_area_offset];
+
+ /* ipmi workaround
+ *
+ * dell p weredge r610
+ *
+ * my reading of the fru spec is that all non-custom fields are
+ * required to be listed by the vendor. however, on this
+ * motherboard, some areas list this, indicating that there is
+ * no more data to be parsed. so now, for "required" fields, i
+ * check to see if the type-length field is a sentinel before
+ * calling this function.
+ */
+
+ ASSERT(type_length != IPMI_FRU_SENTINEL_VALUE);
+
+ type_code = (type_length & IPMI_FRU_TYPE_LENGTH_TYPE_CODE_MASK) >>
+ IPMI_FRU_TYPE_LENGTH_TYPE_CODE_SHIFT;
+ (*number_of_data_bytes) =
+ type_length & IPMI_FRU_TYPE_LENGTH_NUMBER_OF_DATA_BYTES_MASK;
+
+ /* special case: this shouldn't be a length of 0x01 (see type/length
+ * byte format in fru information storage definition).
+ */
+ if (type_code == IPMI_FRU_TYPE_LENGTH_TYPE_CODE_LANGUAGE_CODE &&
+ (*number_of_data_bytes) == 0x01)
{
- return (-1);
+ return (-1);
}
- if ((current_area_offset + 1 + (*number_of_data_bytes)) > areabuflen)
+ if ((current_area_offset + 1 + (*number_of_data_bytes)) > areabuflen)
{
- return (-1);
+ return (-1);
}
- if (field)
+ if (field)
{
- memset (field->type_length_field,
- '\0',
- IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX);
- memcpy (field->type_length_field,
- &areabufptr[current_area_offset],
- 1 + (*number_of_data_bytes));
- field->type_length_field_length = 1 + (*number_of_data_bytes);
+ memset(field->type_length_field, '\0',
+ IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX);
+ memcpy(field->type_length_field, &areabufptr[current_area_offset],
+ 1 + (*number_of_data_bytes));
+ field->type_length_field_length = 1 + (*number_of_data_bytes);
}
- return (0);
+ return (0);
}
-int
-ipmi_fru_chassis_info_area (const void *areabuf,
- unsigned int areabuflen,
- uint8_t *chassis_type,
- ipmi_fru_field_t *chassis_part_number,
- ipmi_fru_field_t *chassis_serial_number,
- ipmi_fru_field_t *chassis_custom_fields,
- unsigned int chassis_custom_fields_len)
+int ipmi_fru_chassis_info_area(const void* areabuf, unsigned int areabuflen,
+ uint8_t* chassis_type,
+ ipmi_fru_field_t* chassis_part_number,
+ ipmi_fru_field_t* chassis_serial_number,
+ ipmi_fru_field_t* chassis_custom_fields,
+ unsigned int chassis_custom_fields_len)
{
- const uint8_t *areabufptr = (const uint8_t*) areabuf;
- unsigned int area_offset = 0;
- unsigned int custom_fields_index = 0;
- uint8_t number_of_data_bytes;
- int rv = -1;
+ const uint8_t* areabufptr = (const uint8_t*)areabuf;
+ unsigned int area_offset = 0;
+ unsigned int custom_fields_index = 0;
+ uint8_t number_of_data_bytes;
+ int rv = -1;
- if (!areabuf || !areabuflen)
+ if (!areabuf || !areabuflen)
{
- return (-1);
+ return (-1);
}
- if (chassis_part_number)
- memset (chassis_part_number,
- '\0',
- sizeof (ipmi_fru_field_t));
- if (chassis_serial_number)
- memset (chassis_serial_number,
- '\0',
- sizeof (ipmi_fru_field_t));
- if (chassis_custom_fields && chassis_custom_fields_len)
- memset (chassis_custom_fields,
- '\0',
- sizeof (ipmi_fru_field_t) * chassis_custom_fields_len);
-
- if (chassis_type)
- (*chassis_type) = areabufptr[area_offset];
- area_offset++;
-
- if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
- goto out;
-
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- chassis_part_number) < 0)
- goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
-
- if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
- goto out;
-
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- chassis_serial_number) < 0)
- goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
-
- while (area_offset < areabuflen
- && areabufptr[area_offset] != IPMI_FRU_SENTINEL_VALUE)
+ if (chassis_part_number)
+ memset(chassis_part_number, '\0', sizeof(ipmi_fru_field_t));
+ if (chassis_serial_number)
+ memset(chassis_serial_number, '\0', sizeof(ipmi_fru_field_t));
+ if (chassis_custom_fields && chassis_custom_fields_len)
+ memset(chassis_custom_fields, '\0',
+ sizeof(ipmi_fru_field_t) * chassis_custom_fields_len);
+
+ if (chassis_type)
+ (*chassis_type) = areabufptr[area_offset];
+ area_offset++;
+
+ if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
+ goto out;
+
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, chassis_part_number) < 0)
+ goto cleanup;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+
+ if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
+ goto out;
+
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, chassis_serial_number) < 0)
+ goto cleanup;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+
+ while (area_offset < areabuflen &&
+ areabufptr[area_offset] != IPMI_FRU_SENTINEL_VALUE)
{
- ipmi_fru_field_t *field_ptr = NULL;
+ ipmi_fru_field_t* field_ptr = NULL;
- if (chassis_custom_fields && chassis_custom_fields_len)
+ if (chassis_custom_fields && chassis_custom_fields_len)
{
- if (custom_fields_index < chassis_custom_fields_len)
- field_ptr = &chassis_custom_fields[custom_fields_index];
- else
+ if (custom_fields_index < chassis_custom_fields_len)
+ field_ptr = &chassis_custom_fields[custom_fields_index];
+ else
{
- goto cleanup;
+ goto cleanup;
}
}
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- field_ptr) < 0)
- goto cleanup;
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, field_ptr) < 0)
+ goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
- custom_fields_index++;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+ custom_fields_index++;
}
-
- out:
- rv = 0;
- cleanup:
- return (rv);
+out:
+ rv = 0;
+cleanup:
+ return (rv);
}
-int
-ipmi_fru_board_info_area (const void *areabuf,
- unsigned int areabuflen,
- uint8_t *language_code,
- uint32_t *mfg_date_time,
- ipmi_fru_field_t *board_manufacturer,
- ipmi_fru_field_t *board_product_name,
- ipmi_fru_field_t *board_serial_number,
- ipmi_fru_field_t *board_part_number,
- ipmi_fru_field_t *board_fru_file_id,
- ipmi_fru_field_t *board_custom_fields,
- unsigned int board_custom_fields_len)
+int ipmi_fru_board_info_area(
+ const void* areabuf, unsigned int areabuflen, uint8_t* language_code,
+ uint32_t* mfg_date_time, ipmi_fru_field_t* board_manufacturer,
+ ipmi_fru_field_t* board_product_name, ipmi_fru_field_t* board_serial_number,
+ ipmi_fru_field_t* board_part_number, ipmi_fru_field_t* board_fru_file_id,
+ ipmi_fru_field_t* board_custom_fields, unsigned int board_custom_fields_len)
{
- const uint8_t *areabufptr = (const uint8_t*) areabuf;
- uint32_t mfg_date_time_tmp = 0;
- unsigned int area_offset = 0;
- unsigned int custom_fields_index = 0;
- uint8_t number_of_data_bytes;
- int rv = -1;
-
- if (!areabuf || !areabuflen)
+ const uint8_t* areabufptr = (const uint8_t*)areabuf;
+ uint32_t mfg_date_time_tmp = 0;
+ unsigned int area_offset = 0;
+ unsigned int custom_fields_index = 0;
+ uint8_t number_of_data_bytes;
+ int rv = -1;
+
+ if (!areabuf || !areabuflen)
{
- return (-1);
+ return (-1);
}
- if (board_manufacturer)
- memset (board_manufacturer,
- '\0',
- sizeof (ipmi_fru_field_t));
- if (board_product_name)
- memset (board_product_name,
- '\0',
- sizeof (ipmi_fru_field_t));
- if (board_serial_number)
- memset (board_serial_number,
- '\0',
- sizeof (ipmi_fru_field_t));
- if (board_part_number)
- memset (board_part_number,
- '\0',
- sizeof (ipmi_fru_field_t));
- if (board_fru_file_id)
- memset (board_fru_file_id,
- '\0',
- sizeof (ipmi_fru_field_t));
- if (board_custom_fields && board_custom_fields_len)
- memset (board_custom_fields,
- '\0',
- sizeof (ipmi_fru_field_t) * board_custom_fields_len);
-
- if (language_code)
- (*language_code) = areabufptr[area_offset];
- area_offset++;
-
- if (mfg_date_time)
+ if (board_manufacturer)
+ memset(board_manufacturer, '\0', sizeof(ipmi_fru_field_t));
+ if (board_product_name)
+ memset(board_product_name, '\0', sizeof(ipmi_fru_field_t));
+ if (board_serial_number)
+ memset(board_serial_number, '\0', sizeof(ipmi_fru_field_t));
+ if (board_part_number)
+ memset(board_part_number, '\0', sizeof(ipmi_fru_field_t));
+ if (board_fru_file_id)
+ memset(board_fru_file_id, '\0', sizeof(ipmi_fru_field_t));
+ if (board_custom_fields && board_custom_fields_len)
+ memset(board_custom_fields, '\0',
+ sizeof(ipmi_fru_field_t) * board_custom_fields_len);
+
+ if (language_code)
+ (*language_code) = areabufptr[area_offset];
+ area_offset++;
+
+ if (mfg_date_time)
{
- struct tm tm;
- time_t t;
-
- /* mfg_date_time is little endian - see spec */
- mfg_date_time_tmp |= areabufptr[area_offset];
- area_offset++;
- mfg_date_time_tmp |= (areabufptr[area_offset] << 8);
- area_offset++;
- mfg_date_time_tmp |= (areabufptr[area_offset] << 16);
- area_offset++;
-
- /* mfg_date_time is in minutes, so multiple by 60 to get seconds */
- mfg_date_time_tmp *= 60;
-
- /* posix says individual calls need not clear/set all portions of
- * 'struct tm', thus passing 'struct tm' between functions could
- * have issues. so we need to memset.
- */
- memset (&tm, '\0', sizeof(struct tm));
-
- /* in fru, epoch is 0:00 hrs 1/1/96
- *
- * so convert into ansi epoch
- */
-
- tm.tm_year = 96; /* years since 1900 */
- tm.tm_mon = 0; /* months since january */
- tm.tm_mday = 1; /* 1-31 */
- tm.tm_hour = 0;
- tm.tm_min = 0;
- tm.tm_sec = 0;
- tm.tm_isdst = -1;
-
- if ((t = mktime (&tm)) == (time_t)-1)
+ struct tm tm;
+ time_t t;
+
+ /* mfg_date_time is little endian - see spec */
+ mfg_date_time_tmp |= areabufptr[area_offset];
+ area_offset++;
+ mfg_date_time_tmp |= (areabufptr[area_offset] << 8);
+ area_offset++;
+ mfg_date_time_tmp |= (areabufptr[area_offset] << 16);
+ area_offset++;
+
+ /* mfg_date_time is in minutes, so multiple by 60 to get seconds */
+ mfg_date_time_tmp *= 60;
+
+ /* posix says individual calls need not clear/set all portions of
+ * 'struct tm', thus passing 'struct tm' between functions could
+ * have issues. so we need to memset.
+ */
+ memset(&tm, '\0', sizeof(struct tm));
+
+ /* in fru, epoch is 0:00 hrs 1/1/96
+ *
+ * so convert into ansi epoch
+ */
+
+ tm.tm_year = 96; /* years since 1900 */
+ tm.tm_mon = 0; /* months since january */
+ tm.tm_mday = 1; /* 1-31 */
+ tm.tm_hour = 0;
+ tm.tm_min = 0;
+ tm.tm_sec = 0;
+ tm.tm_isdst = -1;
+
+ if ((t = mktime(&tm)) == (time_t)-1)
{
- goto cleanup;
+ goto cleanup;
}
- mfg_date_time_tmp += (uint32_t)t;
- (*mfg_date_time) = mfg_date_time_tmp;
+ mfg_date_time_tmp += (uint32_t)t;
+ (*mfg_date_time) = mfg_date_time_tmp;
}
- else
- area_offset += 3;
-
- if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
- goto out;
-
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- board_manufacturer) < 0)
- goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
-
- if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
- goto out;
-
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- board_product_name) < 0)
- goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
-
- if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
- goto out;
-
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- board_serial_number) < 0)
- goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
-
- if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
- goto out;
-
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- board_part_number) < 0)
- goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
-
- if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
- goto out;
-
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- board_fru_file_id) < 0)
- goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
-
- while (area_offset < areabuflen
- && areabufptr[area_offset] != IPMI_FRU_SENTINEL_VALUE)
+ else
+ area_offset += 3;
+
+ if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
+ goto out;
+
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, board_manufacturer) < 0)
+ goto cleanup;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+
+ if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
+ goto out;
+
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, board_product_name) < 0)
+ goto cleanup;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+
+ if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
+ goto out;
+
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, board_serial_number) < 0)
+ goto cleanup;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+
+ if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
+ goto out;
+
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, board_part_number) < 0)
+ goto cleanup;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+
+ if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
+ goto out;
+
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, board_fru_file_id) < 0)
+ goto cleanup;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+
+ while (area_offset < areabuflen &&
+ areabufptr[area_offset] != IPMI_FRU_SENTINEL_VALUE)
{
- ipmi_fru_field_t *field_ptr = NULL;
+ ipmi_fru_field_t* field_ptr = NULL;
- if (board_custom_fields && board_custom_fields_len)
+ if (board_custom_fields && board_custom_fields_len)
{
- if (custom_fields_index < board_custom_fields_len)
- field_ptr = &board_custom_fields[custom_fields_index];
- else
+ if (custom_fields_index < board_custom_fields_len)
+ field_ptr = &board_custom_fields[custom_fields_index];
+ else
{
- goto cleanup;
+ goto cleanup;
}
}
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- field_ptr) < 0)
- goto cleanup;
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, field_ptr) < 0)
+ goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
- custom_fields_index++;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+ custom_fields_index++;
}
- out:
- rv = 0;
- cleanup:
- return (rv);
+out:
+ rv = 0;
+cleanup:
+ return (rv);
}
-int
-ipmi_fru_product_info_area (const void *areabuf,
- unsigned int areabuflen,
- uint8_t *language_code,
- ipmi_fru_field_t *product_manufacturer_name,
- ipmi_fru_field_t *product_name,
- ipmi_fru_field_t *product_part_model_number,
- ipmi_fru_field_t *product_version,
- ipmi_fru_field_t *product_serial_number,
- ipmi_fru_field_t *product_asset_tag,
- ipmi_fru_field_t *product_fru_file_id,
- ipmi_fru_field_t *product_custom_fields,
- unsigned int product_custom_fields_len)
+int ipmi_fru_product_info_area(
+ const void* areabuf, unsigned int areabuflen, uint8_t* language_code,
+ ipmi_fru_field_t* product_manufacturer_name, ipmi_fru_field_t* product_name,
+ ipmi_fru_field_t* product_part_model_number,
+ ipmi_fru_field_t* product_version, ipmi_fru_field_t* product_serial_number,
+ ipmi_fru_field_t* product_asset_tag, ipmi_fru_field_t* product_fru_file_id,
+ ipmi_fru_field_t* product_custom_fields,
+ unsigned int product_custom_fields_len)
{
- const uint8_t *areabufptr = (const uint8_t*) areabuf;
- unsigned int area_offset = 0;
- unsigned int custom_fields_index = 0;
- uint8_t number_of_data_bytes;
- int rv = -1;
+ const uint8_t* areabufptr = (const uint8_t*)areabuf;
+ unsigned int area_offset = 0;
+ unsigned int custom_fields_index = 0;
+ uint8_t number_of_data_bytes;
+ int rv = -1;
- if (!areabuf || !areabuflen)
+ if (!areabuf || !areabuflen)
{
- return (-1);
+ return (-1);
}
- if (product_manufacturer_name)
- memset (product_manufacturer_name,
- '\0',
- sizeof (ipmi_fru_field_t));
- if (product_name)
- memset (product_name,
- '\0',
- sizeof (ipmi_fru_field_t));
- if (product_part_model_number)
- memset (product_part_model_number,
- '\0',
- sizeof (ipmi_fru_field_t));
- if (product_version)
- memset (product_version,
- '\0',
- sizeof (ipmi_fru_field_t));
- if (product_serial_number)
- memset (product_serial_number,
- '\0',
- sizeof (ipmi_fru_field_t));
- if (product_asset_tag)
- memset (product_asset_tag,
- '\0',
- sizeof (ipmi_fru_field_t));
- if (product_fru_file_id)
- memset (product_fru_file_id,
- '\0',
- sizeof (ipmi_fru_field_t));
- if (product_custom_fields && product_custom_fields_len)
- memset (product_custom_fields,
- '\0',
- sizeof (ipmi_fru_field_t) * product_custom_fields_len);
-
- if (language_code)
- (*language_code) = areabufptr[area_offset];
- area_offset++;
-
- if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
- goto out;
-
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- product_manufacturer_name) < 0)
- goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
-
- if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
- goto out;
-
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- product_name) < 0)
- goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
-
- if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
- goto out;
-
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- product_part_model_number) < 0)
- goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
-
- if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
- goto out;
-
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- product_version) < 0)
- goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
-
- if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
- goto out;
-
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- product_serial_number) < 0)
- goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
-
- if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
- goto out;
-
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- product_asset_tag) < 0)
- goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
-
- if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
- goto out;
-
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- product_fru_file_id) < 0)
- goto cleanup;
-
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
-
- while (area_offset < areabuflen
- && areabufptr[area_offset] != IPMI_FRU_SENTINEL_VALUE)
+ if (product_manufacturer_name)
+ memset(product_manufacturer_name, '\0', sizeof(ipmi_fru_field_t));
+ if (product_name)
+ memset(product_name, '\0', sizeof(ipmi_fru_field_t));
+ if (product_part_model_number)
+ memset(product_part_model_number, '\0', sizeof(ipmi_fru_field_t));
+ if (product_version)
+ memset(product_version, '\0', sizeof(ipmi_fru_field_t));
+ if (product_serial_number)
+ memset(product_serial_number, '\0', sizeof(ipmi_fru_field_t));
+ if (product_asset_tag)
+ memset(product_asset_tag, '\0', sizeof(ipmi_fru_field_t));
+ if (product_fru_file_id)
+ memset(product_fru_file_id, '\0', sizeof(ipmi_fru_field_t));
+ if (product_custom_fields && product_custom_fields_len)
+ memset(product_custom_fields, '\0',
+ sizeof(ipmi_fru_field_t) * product_custom_fields_len);
+
+ if (language_code)
+ (*language_code) = areabufptr[area_offset];
+ area_offset++;
+
+ if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
+ goto out;
+
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes,
+ product_manufacturer_name) < 0)
+ goto cleanup;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+
+ if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
+ goto out;
+
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, product_name) < 0)
+ goto cleanup;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+
+ if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
+ goto out;
+
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes,
+ product_part_model_number) < 0)
+ goto cleanup;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+
+ if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
+ goto out;
+
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, product_version) < 0)
+ goto cleanup;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+
+ if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
+ goto out;
+
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, product_serial_number) < 0)
+ goto cleanup;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+
+ if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
+ goto out;
+
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, product_asset_tag) < 0)
+ goto cleanup;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+
+ if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
+ goto out;
+
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, product_fru_file_id) < 0)
+ goto cleanup;
+
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+
+ while (area_offset < areabuflen &&
+ areabufptr[area_offset] != IPMI_FRU_SENTINEL_VALUE)
{
- ipmi_fru_field_t *field_ptr = NULL;
+ ipmi_fru_field_t* field_ptr = NULL;
- if (product_custom_fields && product_custom_fields_len)
+ if (product_custom_fields && product_custom_fields_len)
{
- if (custom_fields_index < product_custom_fields_len)
- field_ptr = &product_custom_fields[custom_fields_index];
- else
+ if (custom_fields_index < product_custom_fields_len)
+ field_ptr = &product_custom_fields[custom_fields_index];
+ else
{
- goto cleanup;
+ goto cleanup;
}
}
- if (_parse_type_length (areabufptr,
- areabuflen,
- area_offset,
- &number_of_data_bytes,
- field_ptr) < 0)
- goto cleanup;
+ if (_parse_type_length(areabufptr, areabuflen, area_offset,
+ &number_of_data_bytes, field_ptr) < 0)
+ goto cleanup;
- area_offset += 1; /* type/length byte */
- area_offset += number_of_data_bytes;
- custom_fields_index++;
+ area_offset += 1; /* type/length byte */
+ area_offset += number_of_data_bytes;
+ custom_fields_index++;
}
-
- out:
- rv = 0;
- cleanup:
- return (rv);
+out:
+ rv = 0;
+cleanup:
+ return (rv);
}
-void _append_to_dict (uint8_t vpd_key_id,
- uint8_t* vpd_key_val,
- IPMIFruInfo& info)
+void _append_to_dict(uint8_t vpd_key_id, uint8_t* vpd_key_val,
+ IPMIFruInfo& info)
{
int type_length = vpd_key_val[0];
int type_code = (type_length & IPMI_FRU_TYPE_LENGTH_TYPE_CODE_MASK) >>
IPMI_FRU_TYPE_LENGTH_TYPE_CODE_SHIFT;
int vpd_val_len =
type_length & IPMI_FRU_TYPE_LENGTH_NUMBER_OF_DATA_BYTES_MASK;
- int sdr=0;
+ int sdr = 0;
/* Needed to convert each uint8_t byte to a ascii */
char bin_byte[3] = {0};
@@ -735,12 +637,12 @@ void _append_to_dict (uint8_t vpd_key_id,
char bin_in_ascii_len = vpd_val_len * 2 + 3;
/* Binary converted to ascii in array */
- char *bin_in_ascii = (char *)malloc(bin_in_ascii_len);
+ char* bin_in_ascii = (char*)malloc(bin_in_ascii_len);
/* For reading byte from the area */
int val = 0;
- char *bin_copy = &((char *)bin_in_ascii)[2];
+ char* bin_copy = &((char*)bin_in_ascii)[2];
switch (type_code)
{
@@ -748,7 +650,7 @@ void _append_to_dict (uint8_t vpd_key_id,
memset(bin_in_ascii, 0x0, bin_in_ascii_len);
/* Offset 1 is where actual data starts */
- for(val = 1; val <= vpd_val_len ; val++)
+ for (val = 1; val <= vpd_val_len; val++)
{
/* 2 bytes for data and 1 for terminating '\0' */
snprintf(bin_byte, 3, "%02x", vpd_key_val[val]);
@@ -758,174 +660,168 @@ void _append_to_dict (uint8_t vpd_key_id,
}
/* We need the data represented as 0x...... */
- if(vpd_val_len > 0)
+ if (vpd_val_len > 0)
{
strncpy(bin_in_ascii, "0x", 2);
}
#if IPMI_FRU_PARSER_DEBUG
- printf ("_append_to_dict: VPD Key = [%s] : Type Code = [BINARY] :"
- " Len = [%d] : Val = [%s]\n",
- vpd_key_names [vpd_key_id], vpd_val_len, bin_in_ascii);
+ printf("_append_to_dict: VPD Key = [%s] : Type Code = [BINARY] :"
+ " Len = [%d] : Val = [%s]\n",
+ vpd_key_names[vpd_key_id], vpd_val_len, bin_in_ascii);
#endif
- info[vpd_key_id] = std::make_pair(vpd_key_names[vpd_key_id],
- bin_in_ascii);
+ info[vpd_key_id] =
+ std::make_pair(vpd_key_names[vpd_key_id], bin_in_ascii);
break;
case 3:
#if IPMI_FRU_PARSER_DEBUG
- printf ("_append_to_dict: VPD Key = [%s] : Type Code=[ASCII+Latin]"
- " : Len = [%d] : Val = [%s]\n",
- vpd_key_names [vpd_key_id], vpd_val_len, &vpd_key_val[1]);
+ printf("_append_to_dict: VPD Key = [%s] : Type Code=[ASCII+Latin]"
+ " : Len = [%d] : Val = [%s]\n",
+ vpd_key_names[vpd_key_id], vpd_val_len, &vpd_key_val[1]);
#endif
info[vpd_key_id] = std::make_pair(
- vpd_key_names[vpd_key_id],
- std::string(vpd_key_val + 1,
- vpd_key_val + 1 + type_length));
+ vpd_key_names[vpd_key_id],
+ std::string(vpd_key_val + 1, vpd_key_val + 1 + type_length));
break;
}
- if(bin_in_ascii)
+ if (bin_in_ascii)
{
free(bin_in_ascii);
bin_in_ascii = NULL;
}
-
if (sdr < 0)
{
#if IPMI_FRU_PARSER_DEBUG
- printf ("_append_to_dict : sd_bus_message_append Failed [ %d ] for [%s]\n", sdr, vpd_key_names[vpd_key_id]);
+ printf(
+ "_append_to_dict : sd_bus_message_append Failed [ %d ] for [%s]\n",
+ sdr, vpd_key_names[vpd_key_id]);
#endif
}
}
-int parse_fru_area (const uint8_t area, const void* msgbuf,
- const size_t len, IPMIFruInfo& info)
+int parse_fru_area(const uint8_t area, const void* msgbuf, const size_t len,
+ IPMIFruInfo& info)
{
- int rv = -1;
- int i = 0;
-
- /* Chassis */
- uint8_t chassis_type;
- /* Board */
- uint32_t mfg_date_time;
- /* Product */
- //unsigned int product_custom_fields_len;
-
- //ipmi_fru_area_info_t fru_area_info [ IPMI_FRU_AREA_TYPE_MAX ];
- ipmi_fru_field_t vpd_info [ OPENBMC_VPD_KEY_MAX ];
- char timestr [ OPENBMC_VPD_VAL_LEN ];
-
- //uint8_t* ipmi_fru_field_str=NULL;
- //ipmi_fru_common_hdr_t* chdr = NULL;
- //uint8_t* hdr = NULL;
-
- ASSERT (msgbuf);
-
- for (i=0; i<OPENBMC_VPD_KEY_MAX; i++)
- {
- memset (vpd_info[i].type_length_field, '\0',
- IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX);
- vpd_info[i].type_length_field_length = 0;
- }
-
- switch (area)
- {
- case IPMI_FRU_AREA_CHASSIS_INFO:
+ int rv = -1;
+ int i = 0;
+
+ /* Chassis */
+ uint8_t chassis_type;
+ /* Board */
+ uint32_t mfg_date_time;
+ /* Product */
+ // unsigned int product_custom_fields_len;
+
+ // ipmi_fru_area_info_t fru_area_info [ IPMI_FRU_AREA_TYPE_MAX ];
+ ipmi_fru_field_t vpd_info[OPENBMC_VPD_KEY_MAX];
+ char timestr[OPENBMC_VPD_VAL_LEN];
+
+ // uint8_t* ipmi_fru_field_str=NULL;
+ // ipmi_fru_common_hdr_t* chdr = NULL;
+ // uint8_t* hdr = NULL;
+
+ ASSERT(msgbuf);
+
+ for (i = 0; i < OPENBMC_VPD_KEY_MAX; i++)
+ {
+ memset(vpd_info[i].type_length_field, '\0',
+ IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX);
+ vpd_info[i].type_length_field_length = 0;
+ }
+
+ switch (area)
+ {
+ case IPMI_FRU_AREA_CHASSIS_INFO:
#if IPMI_FRU_PARSER_DEBUG
- printf ("Chassis : Buf len = [%d]\n", len);
+ printf("Chassis : Buf len = [%d]\n", len);
#endif
- ipmi_fru_chassis_info_area ((uint8_t*)msgbuf+2,
- len,
- &chassis_type,
- &vpd_info [OPENBMC_VPD_KEY_CHASSIS_PART_NUM],
- &vpd_info [OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM],
- &vpd_info [OPENBMC_VPD_KEY_CHASSIS_CUSTOM1],
- OPENBMC_VPD_KEY_CUSTOM_FIELDS_MAX);
-
- /* Populate VPD Table */
- for (i=1; i<=OPENBMC_VPD_KEY_CHASSIS_MAX; i++)
- {
- if (i==OPENBMC_VPD_KEY_CHASSIS_TYPE)
+ ipmi_fru_chassis_info_area(
+ (uint8_t*)msgbuf + 2, len, &chassis_type,
+ &vpd_info[OPENBMC_VPD_KEY_CHASSIS_PART_NUM],
+ &vpd_info[OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM],
+ &vpd_info[OPENBMC_VPD_KEY_CHASSIS_CUSTOM1],
+ OPENBMC_VPD_KEY_CUSTOM_FIELDS_MAX);
+
+ /* Populate VPD Table */
+ for (i = 1; i <= OPENBMC_VPD_KEY_CHASSIS_MAX; i++)
{
+ if (i == OPENBMC_VPD_KEY_CHASSIS_TYPE)
+ {
#if IPMI_FRU_PARSER_DEBUG
- printf ("Chassis : Appending [%s] = [%d]\n",
- vpd_key_names[i], chassis_type);
+ printf("Chassis : Appending [%s] = [%d]\n",
+ vpd_key_names[i], chassis_type);
#endif
- info[i] = std::make_pair(vpd_key_names[i],
- std::to_string(chassis_type));
- continue;
+ info[i] = std::make_pair(vpd_key_names[i],
+ std::to_string(chassis_type));
+ continue;
+ }
+ _append_to_dict(i, vpd_info[i].type_length_field, info);
}
- _append_to_dict (i, vpd_info[i].type_length_field, info);
- }
- break;
- case IPMI_FRU_AREA_BOARD_INFO:
+ break;
+ case IPMI_FRU_AREA_BOARD_INFO:
#if IPMI_FRU_PARSER_DEBUG
- printf ("Board : Buf len = [%d]\n", len);
+ printf("Board : Buf len = [%d]\n", len);
#endif
- ipmi_fru_board_info_area ((uint8_t*)msgbuf+2,
- len,
- NULL,
- &mfg_date_time,
- &vpd_info [OPENBMC_VPD_KEY_BOARD_MFR],
- &vpd_info [OPENBMC_VPD_KEY_BOARD_NAME],
- &vpd_info [OPENBMC_VPD_KEY_BOARD_SERIAL_NUM],
- &vpd_info [OPENBMC_VPD_KEY_BOARD_PART_NUM],
- &vpd_info [OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID],
- &vpd_info [OPENBMC_VPD_KEY_BOARD_CUSTOM1],
+ ipmi_fru_board_info_area(
+ (uint8_t*)msgbuf + 2, len, NULL, &mfg_date_time,
+ &vpd_info[OPENBMC_VPD_KEY_BOARD_MFR],
+ &vpd_info[OPENBMC_VPD_KEY_BOARD_NAME],
+ &vpd_info[OPENBMC_VPD_KEY_BOARD_SERIAL_NUM],
+ &vpd_info[OPENBMC_VPD_KEY_BOARD_PART_NUM],
+ &vpd_info[OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID],
+ &vpd_info[OPENBMC_VPD_KEY_BOARD_CUSTOM1],
OPENBMC_VPD_KEY_CUSTOM_FIELDS_MAX);
- /* Populate VPD Table */
- for (i=OPENBMC_VPD_KEY_BOARD_MFG_DATE;
- i<=OPENBMC_VPD_KEY_BOARD_MAX; i++)
+ /* Populate VPD Table */
+ for (i = OPENBMC_VPD_KEY_BOARD_MFG_DATE;
+ i <= OPENBMC_VPD_KEY_BOARD_MAX; i++)
{
- if (i==OPENBMC_VPD_KEY_BOARD_MFG_DATE)
+ if (i == OPENBMC_VPD_KEY_BOARD_MFG_DATE)
{
- _to_time_str (mfg_date_time, timestr, OPENBMC_VPD_VAL_LEN);
+ _to_time_str(mfg_date_time, timestr, OPENBMC_VPD_VAL_LEN);
#if IPMI_FRU_PARSER_DEBUG
- printf ("Board : Appending [%s] = [%s]\n",
- vpd_key_names[i], timestr);
+ printf("Board : Appending [%s] = [%s]\n", vpd_key_names[i],
+ timestr);
#endif
- info[i] = std::make_pair(vpd_key_names[i],
- std::string(timestr));
+ info[i] =
+ std::make_pair(vpd_key_names[i], std::string(timestr));
continue;
}
- _append_to_dict (i, vpd_info[i].type_length_field, info);
-
+ _append_to_dict(i, vpd_info[i].type_length_field, info);
}
break;
- case IPMI_FRU_AREA_PRODUCT_INFO:
+ case IPMI_FRU_AREA_PRODUCT_INFO:
#if IPMI_FRU_PARSER_DEBUG
- printf ("Product : Buf len = [%d]\n", len);
+ printf("Product : Buf len = [%d]\n", len);
#endif
- ipmi_fru_product_info_area ((uint8_t*)msgbuf+2,
- len,
- NULL,
- &vpd_info [OPENBMC_VPD_KEY_PRODUCT_MFR],
- &vpd_info [OPENBMC_VPD_KEY_PRODUCT_NAME],
- &vpd_info [OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM],
- &vpd_info [OPENBMC_VPD_KEY_PRODUCT_VER],
- &vpd_info [OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM],
- &vpd_info [OPENBMC_VPD_KEY_PRODUCT_ASSET_TAG],
- &vpd_info [OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID],
- &vpd_info [OPENBMC_VPD_KEY_PRODUCT_CUSTOM1],
+ ipmi_fru_product_info_area(
+ (uint8_t*)msgbuf + 2, len, NULL,
+ &vpd_info[OPENBMC_VPD_KEY_PRODUCT_MFR],
+ &vpd_info[OPENBMC_VPD_KEY_PRODUCT_NAME],
+ &vpd_info[OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM],
+ &vpd_info[OPENBMC_VPD_KEY_PRODUCT_VER],
+ &vpd_info[OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM],
+ &vpd_info[OPENBMC_VPD_KEY_PRODUCT_ASSET_TAG],
+ &vpd_info[OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID],
+ &vpd_info[OPENBMC_VPD_KEY_PRODUCT_CUSTOM1],
OPENBMC_VPD_KEY_CUSTOM_FIELDS_MAX);
- for (i=OPENBMC_VPD_KEY_PRODUCT_MFR;
- i<=OPENBMC_VPD_KEY_PRODUCT_MAX;
- ++i)
+ for (i = OPENBMC_VPD_KEY_PRODUCT_MFR;
+ i <= OPENBMC_VPD_KEY_PRODUCT_MAX; ++i)
{
- _append_to_dict (i, vpd_info[i].type_length_field, info);
+ _append_to_dict(i, vpd_info[i].type_length_field, info);
}
break;
- default:
- /* TODO: Parse Multi Rec / Internal use area */
- break;
- }
+ default:
+ /* TODO: Parse Multi Rec / Internal use area */
+ break;
+ }
#if IPMI_FRU_PARSER_DEBUG
- printf ("parse_fru_area : Dictionary Packing Complete\n");
+ printf("parse_fru_area : Dictionary Packing Complete\n");
#endif
- rv = 0;
- return (rv);
+ rv = 0;
+ return (rv);
}
diff --git a/frup.hpp b/frup.hpp
index 3f68acd..0a0dd76 100644
--- a/frup.hpp
+++ b/frup.hpp
@@ -2,9 +2,10 @@
#define OPENBMC_IPMI_FRU_PARSER_H
#include <systemd/sd-bus.h>
+
#include <array>
-#include <string>
#include <map>
+#include <string>
#include <vector>
enum ipmi_fru_area_type
@@ -17,64 +18,63 @@ enum ipmi_fru_area_type
IPMI_FRU_AREA_TYPE_MAX
};
-
enum openbmc_vpd_key_id
{
- OPENBMC_VPD_KEY_CHASSIS_TYPE = 1, /* not a type/len */
- OPENBMC_VPD_KEY_CHASSIS_PART_NUM,
- OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM,
- OPENBMC_VPD_KEY_CHASSIS_CUSTOM1,
- OPENBMC_VPD_KEY_CHASSIS_CUSTOM2,
- OPENBMC_VPD_KEY_CHASSIS_CUSTOM3,
- OPENBMC_VPD_KEY_CHASSIS_CUSTOM4,
- OPENBMC_VPD_KEY_CHASSIS_CUSTOM5,
- OPENBMC_VPD_KEY_CHASSIS_CUSTOM6,
- OPENBMC_VPD_KEY_CHASSIS_CUSTOM7,
- OPENBMC_VPD_KEY_CHASSIS_CUSTOM8,
- OPENBMC_VPD_KEY_CHASSIS_MAX = OPENBMC_VPD_KEY_CHASSIS_CUSTOM8,
- /* TODO: chassis_custom_fields */
-
- OPENBMC_VPD_KEY_BOARD_MFG_DATE, /* not a type/len */
- OPENBMC_VPD_KEY_BOARD_MFR,
- OPENBMC_VPD_KEY_BOARD_NAME,
- OPENBMC_VPD_KEY_BOARD_SERIAL_NUM,
- OPENBMC_VPD_KEY_BOARD_PART_NUM,
- OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID,
- OPENBMC_VPD_KEY_BOARD_CUSTOM1,
- OPENBMC_VPD_KEY_BOARD_CUSTOM2,
- OPENBMC_VPD_KEY_BOARD_CUSTOM3,
- OPENBMC_VPD_KEY_BOARD_CUSTOM4,
- OPENBMC_VPD_KEY_BOARD_CUSTOM5,
- OPENBMC_VPD_KEY_BOARD_CUSTOM6,
- OPENBMC_VPD_KEY_BOARD_CUSTOM7,
- OPENBMC_VPD_KEY_BOARD_CUSTOM8,
- OPENBMC_VPD_KEY_BOARD_MAX = OPENBMC_VPD_KEY_BOARD_CUSTOM8,
- /* TODO: board_custom_fields */
-
- OPENBMC_VPD_KEY_PRODUCT_MFR,
- OPENBMC_VPD_KEY_PRODUCT_NAME,
- OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM,
- OPENBMC_VPD_KEY_PRODUCT_VER,
- OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM,
- OPENBMC_VPD_KEY_PRODUCT_ASSET_TAG,
- OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID,
- OPENBMC_VPD_KEY_PRODUCT_CUSTOM1,
- OPENBMC_VPD_KEY_PRODUCT_CUSTOM2,
- OPENBMC_VPD_KEY_PRODUCT_CUSTOM3,
- OPENBMC_VPD_KEY_PRODUCT_CUSTOM4,
- OPENBMC_VPD_KEY_PRODUCT_CUSTOM5,
- OPENBMC_VPD_KEY_PRODUCT_CUSTOM6,
- OPENBMC_VPD_KEY_PRODUCT_CUSTOM7,
- OPENBMC_VPD_KEY_PRODUCT_CUSTOM8,
- OPENBMC_VPD_KEY_PRODUCT_MAX = OPENBMC_VPD_KEY_PRODUCT_CUSTOM8,
-
- OPENBMC_VPD_KEY_MAX,
- OPENBMC_VPD_KEY_CUSTOM_FIELDS_MAX=8,
+ OPENBMC_VPD_KEY_CHASSIS_TYPE = 1, /* not a type/len */
+ OPENBMC_VPD_KEY_CHASSIS_PART_NUM,
+ OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM,
+ OPENBMC_VPD_KEY_CHASSIS_CUSTOM1,
+ OPENBMC_VPD_KEY_CHASSIS_CUSTOM2,
+ OPENBMC_VPD_KEY_CHASSIS_CUSTOM3,
+ OPENBMC_VPD_KEY_CHASSIS_CUSTOM4,
+ OPENBMC_VPD_KEY_CHASSIS_CUSTOM5,
+ OPENBMC_VPD_KEY_CHASSIS_CUSTOM6,
+ OPENBMC_VPD_KEY_CHASSIS_CUSTOM7,
+ OPENBMC_VPD_KEY_CHASSIS_CUSTOM8,
+ OPENBMC_VPD_KEY_CHASSIS_MAX = OPENBMC_VPD_KEY_CHASSIS_CUSTOM8,
+ /* TODO: chassis_custom_fields */
+
+ OPENBMC_VPD_KEY_BOARD_MFG_DATE, /* not a type/len */
+ OPENBMC_VPD_KEY_BOARD_MFR,
+ OPENBMC_VPD_KEY_BOARD_NAME,
+ OPENBMC_VPD_KEY_BOARD_SERIAL_NUM,
+ OPENBMC_VPD_KEY_BOARD_PART_NUM,
+ OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID,
+ OPENBMC_VPD_KEY_BOARD_CUSTOM1,
+ OPENBMC_VPD_KEY_BOARD_CUSTOM2,
+ OPENBMC_VPD_KEY_BOARD_CUSTOM3,
+ OPENBMC_VPD_KEY_BOARD_CUSTOM4,
+ OPENBMC_VPD_KEY_BOARD_CUSTOM5,
+ OPENBMC_VPD_KEY_BOARD_CUSTOM6,
+ OPENBMC_VPD_KEY_BOARD_CUSTOM7,
+ OPENBMC_VPD_KEY_BOARD_CUSTOM8,
+ OPENBMC_VPD_KEY_BOARD_MAX = OPENBMC_VPD_KEY_BOARD_CUSTOM8,
+ /* TODO: board_custom_fields */
+
+ OPENBMC_VPD_KEY_PRODUCT_MFR,
+ OPENBMC_VPD_KEY_PRODUCT_NAME,
+ OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM,
+ OPENBMC_VPD_KEY_PRODUCT_VER,
+ OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM,
+ OPENBMC_VPD_KEY_PRODUCT_ASSET_TAG,
+ OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID,
+ OPENBMC_VPD_KEY_PRODUCT_CUSTOM1,
+ OPENBMC_VPD_KEY_PRODUCT_CUSTOM2,
+ OPENBMC_VPD_KEY_PRODUCT_CUSTOM3,
+ OPENBMC_VPD_KEY_PRODUCT_CUSTOM4,
+ OPENBMC_VPD_KEY_PRODUCT_CUSTOM5,
+ OPENBMC_VPD_KEY_PRODUCT_CUSTOM6,
+ OPENBMC_VPD_KEY_PRODUCT_CUSTOM7,
+ OPENBMC_VPD_KEY_PRODUCT_CUSTOM8,
+ OPENBMC_VPD_KEY_PRODUCT_MAX = OPENBMC_VPD_KEY_PRODUCT_CUSTOM8,
+
+ OPENBMC_VPD_KEY_MAX,
+ OPENBMC_VPD_KEY_CUSTOM_FIELDS_MAX = 8,
};
-using IPMIFruInfo = std::array<std::pair<std::string,std::string>,
- OPENBMC_VPD_KEY_MAX>;
+using IPMIFruInfo =
+ std::array<std::pair<std::string, std::string>, OPENBMC_VPD_KEY_MAX>;
struct IPMIFruData
{
@@ -104,10 +104,11 @@ using FruInstanceVec = std::vector<FruInstance>;
using FruId = uint32_t;
using FruMap = std::map<FruId, FruInstanceVec>;
-/* Parse an IPMI write fru data message into a dictionary containing name value pair of VPD entries.*/
-int parse_fru (const void* msgbuf, sd_bus_message* vpdtbl);
+/* Parse an IPMI write fru data message into a dictionary containing name value
+ * pair of VPD entries.*/
+int parse_fru(const void* msgbuf, sd_bus_message* vpdtbl);
-int parse_fru_area (const uint8_t area, const void* msgbuf,
- const size_t len, IPMIFruInfo& info);
+int parse_fru_area(const uint8_t area, const void* msgbuf, const size_t len,
+ IPMIFruInfo& info);
#endif
diff --git a/readeeprom.cpp b/readeeprom.cpp
index ef7e559..b8b2fd8 100644
--- a/readeeprom.cpp
+++ b/readeeprom.cpp
@@ -1,8 +1,9 @@
-#include <iostream>
-#include <memory>
#include "argument.hpp"
#include "writefrudata.hpp"
+#include <iostream>
+#include <memory>
+
static void exit_with_error(const char* err, char** argv)
{
ArgumentParser::usage(argv);
@@ -14,13 +15,13 @@ static void exit_with_error(const char* err, char** argv)
//--------------------------------------------------------------------------
// This gets called by udev monitor soon after seeing hog plugs for EEPROMS.
//--------------------------------------------------------------------------
-int main(int argc, char **argv)
+int main(int argc, char** argv)
{
int rc = 0;
uint8_t fruid = 0;
// Handle to per process system bus
- sd_bus *bus_type = NULL;
+ sd_bus* bus_type = NULL;
// Read the arguments.
auto cli_options = std::make_unique<ArgumentParser>(argc, argv);
@@ -42,7 +43,7 @@ int main(int argc, char **argv)
// Extract the fruid
fruid = strtol(fruid_str.c_str(), NULL, 16);
- if(fruid == 0)
+ if (fruid == 0)
{
// User has not passed in the appropriate argument value
exit_with_error("Invalid fruid.", argv);
@@ -55,14 +56,15 @@ int main(int argc, char **argv)
rc = sd_bus_open_system(&bus_type);
if (rc < 0)
{
- fprintf(stderr, "Failed to connect to system bus: %s\n",strerror(-rc));
+ fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-rc));
}
else
{
- // Now that we have the file that contains the eeprom data, go read it and
- // update the Inventory DB.
+ // Now that we have the file that contains the eeprom data, go read it
+ // and update the Inventory DB.
bool bmc_fru = true;
- rc = ipmi_validate_fru_area(fruid, eeprom_file.c_str(), bus_type, bmc_fru);
+ rc = ipmi_validate_fru_area(fruid, eeprom_file.c_str(), bus_type,
+ bmc_fru);
}
// Cleanup
diff --git a/strgfnhandler.cpp b/strgfnhandler.cpp
index 2cbbf4d..63e9bd6 100644
--- a/strgfnhandler.cpp
+++ b/strgfnhandler.cpp
@@ -1,8 +1,9 @@
+#include "writefrudata.hpp"
+
#include <host-ipmid/ipmid-api.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include "writefrudata.hpp"
void register_netfn_storage_write_fru() __attribute__((constructor));
@@ -12,18 +13,20 @@ sd_bus* ipmid_get_sd_bus_connection(void);
// Called by IPMI netfn router for write fru data command
//--------------------------------------------------------
ipmi_ret_t ipmi_storage_write_fru_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
- ipmi_request_t request, ipmi_response_t response,
- ipmi_data_len_t data_len, ipmi_context_t context)
+ ipmi_request_t request,
+ ipmi_response_t response,
+ ipmi_data_len_t data_len,
+ ipmi_context_t context)
{
- FILE *fp = NULL;
+ FILE* fp = NULL;
char fru_file_name[16] = {0};
uint8_t offset = 0;
uint16_t len = 0;
ipmi_ret_t rc = IPMI_CC_INVALID;
- const char *mode = NULL;
+ const char* mode = NULL;
// From the payload, extract the header that has fruid and the offsets
- write_fru_data_t *reqptr = (write_fru_data_t*)request;
+ write_fru_data_t* reqptr = (write_fru_data_t*)request;
// Maintaining a temporary file to pump the data
sprintf(fru_file_name, "%s%02x", "/tmp/ipmifru", reqptr->frunum);
@@ -34,33 +37,35 @@ ipmi_ret_t ipmi_storage_write_fru_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
// The header contains an extra byte to indicate the start of
// the data (so didn't need to worry about word/byte boundaries)
// hence the -1...
- len = ((uint16_t)*data_len) - (sizeof(write_fru_data_t)-1);
+ len = ((uint16_t)*data_len) - (sizeof(write_fru_data_t) - 1);
// On error there is no response data for this command.
*data_len = 0;
#ifdef __IPMI__DEBUG__
printf("IPMI WRITE-FRU-DATA for [%s] Offset = [%d] Length = [%d]\n",
- fru_file_name, offset, len);
+ fru_file_name, offset, len);
#endif
-
- if( access( fru_file_name, F_OK ) == -1 ) {
+ if (access(fru_file_name, F_OK) == -1)
+ {
mode = "wb";
- } else {
+ }
+ else
+ {
mode = "rb+";
}
if ((fp = fopen(fru_file_name, mode)) != NULL)
{
- if(fseek(fp, offset, SEEK_SET))
+ if (fseek(fp, offset, SEEK_SET))
{
perror("Error:");
fclose(fp);
return rc;
}
- if(fwrite(&reqptr->data, len, 1, fp) != 1)
+ if (fwrite(&reqptr->data, len, 1, fp) != 1)
{
perror("Error:");
fclose(fp);
@@ -71,11 +76,11 @@ ipmi_ret_t ipmi_storage_write_fru_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
}
else
{
- fprintf(stderr, "Error trying to write to fru file %s\n",fru_file_name);
+ fprintf(stderr, "Error trying to write to fru file %s\n",
+ fru_file_name);
return rc;
}
-
// If we got here then set the resonse byte
// to the number of bytes written
memcpy(response, &len, 1);
@@ -83,7 +88,7 @@ ipmi_ret_t ipmi_storage_write_fru_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
rc = IPMI_CC_OK;
// Get the reference to global sd_bus object
- sd_bus *bus_type = ipmid_get_sd_bus_connection();
+ sd_bus* bus_type = ipmid_get_sd_bus_connection();
// We received some bytes. It may be full or partial. Send a valid
// FRU file to the inventory controller on DBus for the correct number
@@ -98,7 +103,8 @@ ipmi_ret_t ipmi_storage_write_fru_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
//-------------------------------------------------------
void register_netfn_storage_write_fru()
{
- printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_WRITE_FRU_DATA);
- ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WRITE_FRU_DATA, NULL, ipmi_storage_write_fru_data,
- SYSTEM_INTERFACE);
+ printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", NETFUN_STORAGE,
+ IPMI_CMD_WRITE_FRU_DATA);
+ ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WRITE_FRU_DATA, NULL,
+ ipmi_storage_write_fru_data, SYSTEM_INTERFACE);
}
diff --git a/types.hpp b/types.hpp
index 81caad6..e874960 100644
--- a/types.hpp
+++ b/types.hpp
@@ -1,25 +1,25 @@
#pragma once
-#include <string>
#include <map>
#include <sdbusplus/server.hpp>
+#include <string>
namespace ipmi
{
namespace vpd
{
- using Path = std::string;
+using Path = std::string;
- using Property = std::string;
- using Value = sdbusplus::message::variant<bool, int64_t, std::string>;
- using PropertyMap = std::map<Property, Value>;
+using Property = std::string;
+using Value = sdbusplus::message::variant<bool, int64_t, std::string>;
+using PropertyMap = std::map<Property, Value>;
- using Interface = std::string;
- using InterfaceMap = std::map<Interface, PropertyMap>;
+using Interface = std::string;
+using InterfaceMap = std::map<Interface, PropertyMap>;
- using Object = sdbusplus::message::object_path;
- using ObjectMap = std::map<Object, InterfaceMap>;
+using Object = sdbusplus::message::object_path;
+using ObjectMap = std::map<Object, InterfaceMap>;
-} //namespace vpd
-} //namespace ipmi
+} // namespace vpd
+} // namespace ipmi
diff --git a/writefrudata.cpp b/writefrudata.cpp
index 46c7729..371fa6c 100644
--- a/writefrudata.cpp
+++ b/writefrudata.cpp
@@ -1,22 +1,24 @@
-#include <exception>
-#include <vector>
-#include <stdlib.h>
+#include "fru-area.hpp"
+#include "frup.hpp"
+#include "types.hpp"
+
#include <dlfcn.h>
#include <errno.h>
+#include <host-ipmid/ipmid-api.h>
+#include <mapper.h>
#include <stdio.h>
+#include <stdlib.h>
#include <systemd/sd-bus.h>
#include <unistd.h>
-#include <host-ipmid/ipmid-api.h>
-#include <iostream>
-#include <memory>
+
#include <algorithm>
+#include <exception>
#include <fstream>
-#include <sstream>
-#include <mapper.h>
-#include "types.hpp"
-#include "frup.hpp"
-#include "fru-area.hpp"
+#include <iostream>
+#include <memory>
#include <sdbusplus/server.hpp>
+#include <sstream>
+#include <vector>
using namespace ipmi::vpd;
@@ -27,7 +29,7 @@ extern const std::map<Path, InterfaceMap> extras;
// Constructor
//----------------------------------------------------------------
ipmi_fru::ipmi_fru(const uint8_t fruid, const ipmi_fru_area_type type,
- sd_bus *bus_type, bool bmc_fru)
+ sd_bus* bus_type, bool bmc_fru)
{
iv_fruid = fruid;
iv_type = type;
@@ -37,30 +39,30 @@ ipmi_fru::ipmi_fru(const uint8_t fruid, const ipmi_fru_area_type type,
iv_data = NULL;
iv_present = false;
- if(iv_type == IPMI_FRU_AREA_INTERNAL_USE)
+ if (iv_type == IPMI_FRU_AREA_INTERNAL_USE)
{
iv_name = "INTERNAL_";
}
- else if(iv_type == IPMI_FRU_AREA_CHASSIS_INFO)
+ else if (iv_type == IPMI_FRU_AREA_CHASSIS_INFO)
{
iv_name = "CHASSIS_";
}
- else if(iv_type == IPMI_FRU_AREA_BOARD_INFO)
+ else if (iv_type == IPMI_FRU_AREA_BOARD_INFO)
{
iv_name = "BOARD_";
}
- else if(iv_type == IPMI_FRU_AREA_PRODUCT_INFO)
+ else if (iv_type == IPMI_FRU_AREA_PRODUCT_INFO)
{
iv_name = "PRODUCT_";
}
- else if(iv_type == IPMI_FRU_AREA_MULTI_RECORD)
+ else if (iv_type == IPMI_FRU_AREA_MULTI_RECORD)
{
iv_name = "MULTI_";
}
else
{
iv_name = IPMI_FRU_AREA_TYPE_MAX;
- fprintf(stderr, "ERROR: Invalid Area type :[%d]\n",iv_type);
+ fprintf(stderr, "ERROR: Invalid Area type :[%d]\n", iv_type);
}
}
@@ -68,7 +70,7 @@ ipmi_fru::ipmi_fru(const uint8_t fruid, const ipmi_fru_area_type type,
// For a FRU area type, accepts the data and updates
// area specific data.
//-----------------------------------------------------
-void ipmi_fru::set_data(const uint8_t *data, const size_t len)
+void ipmi_fru::set_data(const uint8_t* data, const size_t len)
{
iv_len = len;
iv_data = new uint8_t[len];
@@ -78,8 +80,8 @@ void ipmi_fru::set_data(const uint8_t *data, const size_t len)
//-----------------------------------------------------
// Sets the dbus parameters
//-----------------------------------------------------
-void ipmi_fru::update_dbus_paths(const char *bus_name,
- const char *obj_path, const char *intf_name)
+void ipmi_fru::update_dbus_paths(const char* bus_name, const char* obj_path,
+ const char* intf_name)
{
iv_bus_name = bus_name;
iv_obj_path = obj_path;
@@ -91,9 +93,9 @@ void ipmi_fru::update_dbus_paths(const char *bus_name,
//-------------------
ipmi_fru::~ipmi_fru()
{
- if(iv_data != NULL)
+ if (iv_data != NULL)
{
- delete [] iv_data;
+ delete[] iv_data;
iv_data = NULL;
}
}
@@ -103,17 +105,17 @@ ipmi_fru::~ipmi_fru()
// and returns the 8 bit checksum
// This algo is per IPMI V2.0 spec
//-------------------------------------------------
-unsigned char calculate_crc(const unsigned char *data, size_t len)
+unsigned char calculate_crc(const unsigned char* data, size_t len)
{
char crc = 0;
size_t byte = 0;
- for(byte = 0; byte < len; byte++)
+ for (byte = 0; byte < len; byte++)
{
crc += *data++;
}
- return(-crc);
+ return (-crc);
}
//---------------------------------------------------------------------
@@ -123,7 +125,7 @@ ipmi_fru_area_type get_fru_area_type(uint8_t area_offset)
{
ipmi_fru_area_type type = IPMI_FRU_AREA_TYPE_MAX;
- switch(area_offset)
+ switch (area_offset)
{
case IPMI_FRU_INTERNAL_OFFSET:
type = IPMI_FRU_AREA_INTERNAL_USE;
@@ -155,31 +157,32 @@ ipmi_fru_area_type get_fru_area_type(uint8_t area_offset)
///-----------------------------------------------
// Validates the data for crc and mandatory fields
///-----------------------------------------------
-int verify_fru_data(const uint8_t *data, const size_t len)
+int verify_fru_data(const uint8_t* data, const size_t len)
{
uint8_t checksum = 0;
int rc = -1;
// Validate for first byte to always have a value of [1]
- if(data[0] != IPMI_FRU_HDR_BYTE_ZERO)
+ if (data[0] != IPMI_FRU_HDR_BYTE_ZERO)
{
- fprintf(stderr, "Invalid entry:[%d] in byte-0\n",data[0]);
+ fprintf(stderr, "Invalid entry:[%d] in byte-0\n", data[0]);
return rc;
}
#ifdef __IPMI_DEBUG__
else
{
- printf("SUCCESS: Validated [0x%X] in entry_1 of fru_data\n",data[0]);
+ printf("SUCCESS: Validated [0x%X] in entry_1 of fru_data\n", data[0]);
}
#endif
// See if the calculated CRC matches with the embedded one.
// CRC to be calculated on all except the last one that is CRC itself.
checksum = calculate_crc(data, len - 1);
- if(checksum != data[len-1])
+ if (checksum != data[len - 1])
{
#ifdef __IPMI_DEBUG__
- fprintf(stderr, "Checksum mismatch."
+ fprintf(stderr,
+ "Checksum mismatch."
" Calculated:[0x%X], Embedded:[0x%X]\n",
checksum, data[len]);
#endif
@@ -188,7 +191,7 @@ int verify_fru_data(const uint8_t *data, const size_t len)
#ifdef __IPMI_DEBUG__
else
{
- printf("SUCCESS: Checksum matches:[0x%X]\n",checksum);
+ printf("SUCCESS: Checksum matches:[0x%X]\n", checksum);
}
#endif
@@ -200,10 +203,8 @@ int verify_fru_data(const uint8_t *data, const size_t len)
// FRU dictionary is parsed fru data for all the sections.
//------------------------------------------------------------------------
-std::string getFRUValue(const std::string& section,
- const std::string& key,
- const std::string& delimiter,
- IPMIFruInfo& fruData)
+std::string getFRUValue(const std::string& section, const std::string& key,
+ const std::string& delimiter, IPMIFruInfo& fruData)
{
auto minIndexValue = 0;
@@ -218,7 +219,6 @@ std::string getFRUValue(const std::string& section,
{
minIndexValue = OPENBMC_VPD_KEY_PRODUCT_MFR;
maxIndexValue = OPENBMC_VPD_KEY_PRODUCT_MAX;
-
}
else if (section == "Chassis")
{
@@ -229,42 +229,39 @@ std::string getFRUValue(const std::string& section,
auto first = fruData.cbegin() + minIndexValue;
auto last = first + (maxIndexValue - minIndexValue) + 1;
- auto itr = std::find_if(first, last,
- [&key](auto& e){ return key == e.first; });
+ auto itr =
+ std::find_if(first, last, [&key](auto& e) { return key == e.first; });
if (itr != last)
{
fruValue = itr->second;
}
- //if the key is custom property then the value could be in two formats.
- //1) custom field 2 = "value".
- //2) custom field 2 = "key:value".
- //if delimiter length = 0 i.e custom field 2 = "value"
+ // if the key is custom property then the value could be in two formats.
+ // 1) custom field 2 = "value".
+ // 2) custom field 2 = "key:value".
+ // if delimiter length = 0 i.e custom field 2 = "value"
constexpr auto customProp = "Custom Field";
if (key.find(customProp) != std::string::npos)
{
- if (delimiter.length() > 0)
- {
- size_t delimiterpos = fruValue.find(delimiter);
- if (delimiterpos != std::string::npos)
- fruValue = fruValue.substr(delimiterpos + 1);
- }
+ if (delimiter.length() > 0)
+ {
+ size_t delimiterpos = fruValue.find(delimiter);
+ if (delimiterpos != std::string::npos)
+ fruValue = fruValue.substr(delimiterpos + 1);
+ }
}
return fruValue;
-
}
-//Get the inventory service from the mapper.
-auto getService(sdbusplus::bus::bus& bus,
- const std::string& intf,
- const std::string& path)
+// Get the inventory service from the mapper.
+auto getService(sdbusplus::bus::bus& bus, const std::string& intf,
+ const std::string& path)
{
- auto mapperCall = bus.new_method_call(
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper",
- "GetObject");
+ auto mapperCall =
+ bus.new_method_call("xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetObject");
mapperCall.append(path);
mapperCall.append(std::vector<std::string>({intf}));
@@ -326,7 +323,7 @@ int ipmi_update_inventory(fru_area_vec_t& area_vec, sd_bus* bus_sd)
std::string service;
try
{
- service = getService(bus,intf,path);
+ service = getService(bus, intf, path);
}
catch (const std::runtime_error& e)
{
@@ -357,7 +354,7 @@ int ipmi_update_inventory(fru_area_vec_t& area_vec, sd_bus* bus_sd)
for (auto& interfaceList : instance.interfaces)
{
- PropertyMap props;//store all the properties
+ PropertyMap props; // store all the properties
for (auto& properties : interfaceList.second)
{
std::string value;
@@ -371,13 +368,13 @@ int ipmi_update_inventory(fru_area_vec_t& area_vec, sd_bus* bus_sd)
props.emplace(std::move(properties.first), std::move(value));
}
// Check and update extra properties
- if(extras.end() != extrasIter)
+ if (extras.end() != extrasIter)
{
const auto& propsIter =
(extrasIter->second).find(interfaceList.first);
- if((extrasIter->second).end() != propsIter)
+ if ((extrasIter->second).end() != propsIter)
{
- for(const auto& map : propsIter->second)
+ for (const auto& map : propsIter->second)
{
props.emplace(map.first, map.second);
}
@@ -390,24 +387,21 @@ int ipmi_update_inventory(fru_area_vec_t& area_vec, sd_bus* bus_sd)
// Call the inventory manager
sdbusplus::message::object_path path = instance.path;
// Check and update extra properties
- if(extras.end() != extrasIter)
+ if (extras.end() != extrasIter)
{
- for(const auto& entry : extrasIter->second)
+ for (const auto& entry : extrasIter->second)
{
- if(interfaces.end() == interfaces.find(entry.first))
+ if (interfaces.end() == interfaces.find(entry.first))
{
interfaces.emplace(entry.first, entry.second);
}
}
}
- objects.emplace(path,interfaces);
+ objects.emplace(path, interfaces);
}
- auto pimMsg = bus.new_method_call(
- service.c_str(),
- path.c_str(),
- intf.c_str(),
- "Notify");
+ auto pimMsg = bus.new_method_call(service.c_str(), path.c_str(),
+ intf.c_str(), "Notify");
pimMsg.append(std::move(objects));
auto inventoryMgrResponseMsg = bus.call(pimMsg);
if (inventoryMgrResponseMsg.is_method_error())
@@ -421,10 +415,10 @@ int ipmi_update_inventory(fru_area_vec_t& area_vec, sd_bus* bus_sd)
///----------------------------------------------------
// Checks if a particular fru area is populated or not
///----------------------------------------------------
-bool remove_invalid_area(const std::unique_ptr<ipmi_fru> &fru_area)
+bool remove_invalid_area(const std::unique_ptr<ipmi_fru>& fru_area)
{
// Filter the ones that are empty
- if(!(fru_area->get_len()))
+ if (!(fru_area->get_len()))
{
return true;
}
@@ -435,8 +429,8 @@ bool remove_invalid_area(const std::unique_ptr<ipmi_fru> &fru_area)
// Populates various FRU areas
// @prereq : This must be called only after validating common header.
///----------------------------------------------------------------------------------
-int ipmi_populate_fru_areas(uint8_t *fru_data, const size_t data_len,
- fru_area_vec_t & fru_area_vec)
+int ipmi_populate_fru_areas(uint8_t* fru_data, const size_t data_len,
+ fru_area_vec_t& fru_area_vec)
{
int rc = -1;
@@ -444,72 +438,76 @@ int ipmi_populate_fru_areas(uint8_t *fru_data, const size_t data_len,
// offset mentioned by the common_hdr. If the file size is less than the
// offset of any if the fru areas mentioned in the common header, then we do
// not have a complete file.
- for(uint8_t fru_entry = IPMI_FRU_INTERNAL_OFFSET;
- fru_entry < (sizeof(struct common_header) -2); fru_entry++)
+ for (uint8_t fru_entry = IPMI_FRU_INTERNAL_OFFSET;
+ fru_entry < (sizeof(struct common_header) - 2); fru_entry++)
{
rc = -1;
// Actual offset in the payload is the offset mentioned in common header
// multiplied by 8. Common header is always the first 8 bytes.
size_t area_offset = fru_data[fru_entry] * IPMI_EIGHT_BYTES;
- if(area_offset && (data_len < (area_offset + 2)))
+ if (area_offset && (data_len < (area_offset + 2)))
{
// Our file size is less than what it needs to be. +2 because we are
// using area len that is at 2 byte off area_offset
- fprintf(stderr, "fru file is incomplete. Size:[%zd]\n",data_len);
+ fprintf(stderr, "fru file is incomplete. Size:[%zd]\n", data_len);
return rc;
}
- else if(area_offset)
+ else if (area_offset)
{
// Read 2 bytes to know the actual size of area.
uint8_t area_hdr[2] = {0};
- memcpy(area_hdr, &((uint8_t *)fru_data)[area_offset], sizeof(area_hdr));
+ memcpy(area_hdr, &((uint8_t*)fru_data)[area_offset],
+ sizeof(area_hdr));
// Size of this area will be the 2nd byte in the fru area header.
- size_t area_len = area_hdr[1] * IPMI_EIGHT_BYTES;
+ size_t area_len = area_hdr[1] * IPMI_EIGHT_BYTES;
uint8_t area_data[area_len] = {0};
printf("fru data size:[%zd], area offset:[%zd], area_size:[%zd]\n",
- data_len, area_offset, area_len);
+ data_len, area_offset, area_len);
// See if we really have that much buffer. We have area offset amd
// from there, the actual len.
- if(data_len < (area_len + area_offset))
+ if (data_len < (area_len + area_offset))
{
- fprintf(stderr, "Incomplete Fru file.. Size:[%zd]\n",data_len);
+ fprintf(stderr, "Incomplete Fru file.. Size:[%zd]\n", data_len);
return rc;
}
// Save off the data.
- memcpy(area_data, &((uint8_t *)fru_data)[area_offset], area_len);
+ memcpy(area_data, &((uint8_t*)fru_data)[area_offset], area_len);
// Validate the crc
rc = verify_fru_data(area_data, area_len);
- if(rc < 0)
+ if (rc < 0)
{
- fprintf(stderr, "Error validating fru area. offset:[%zd]\n",area_offset);
+ fprintf(stderr, "Error validating fru area. offset:[%zd]\n",
+ area_offset);
return rc;
}
else
{
- printf("Successfully verified area checksum. offset:[%zd]\n",area_offset);
+ printf("Successfully verified area checksum. offset:[%zd]\n",
+ area_offset);
}
// We already have a vector that is passed to us containing all
// of the fields populated. Update the data portion now.
- for(auto& iter : fru_area_vec)
+ for (auto& iter : fru_area_vec)
{
- if((iter)->get_type() == get_fru_area_type(fru_entry))
+ if ((iter)->get_type() == get_fru_area_type(fru_entry))
{
(iter)->set_data(area_data, area_len);
}
}
} // If we have fru data present
- } // Walk common_hdr
+ } // Walk common_hdr
// Not all the fields will be populated in a fru data. Mostly all cases will
// not have more than 2 or 3.
fru_area_vec.erase(std::remove_if(fru_area_vec.begin(), fru_area_vec.end(),
- remove_invalid_area), fru_area_vec.end());
+ remove_invalid_area),
+ fru_area_vec.end());
return EXIT_SUCCESS;
}
@@ -518,12 +516,12 @@ int ipmi_populate_fru_areas(uint8_t *fru_data, const size_t data_len,
// Validates the fru data per ipmi common header constructs.
// Returns with updated common_hdr and also file_size
//----------------------------------------------------------
-int ipmi_validate_common_hdr(const uint8_t *fru_data, const size_t data_len)
+int ipmi_validate_common_hdr(const uint8_t* fru_data, const size_t data_len)
{
int rc = -1;
uint8_t common_hdr[sizeof(struct common_header)] = {0};
- if(data_len >= sizeof(common_hdr))
+ if (data_len >= sizeof(common_hdr))
{
memcpy(common_hdr, fru_data, sizeof(common_hdr));
}
@@ -535,7 +533,7 @@ int ipmi_validate_common_hdr(const uint8_t *fru_data, const size_t data_len)
// Verify the crc and size
rc = verify_fru_data(common_hdr, sizeof(common_hdr));
- if(rc < 0)
+ if (rc < 0)
{
fprintf(stderr, "Failed to validate common header\n");
return rc;
@@ -547,27 +545,27 @@ int ipmi_validate_common_hdr(const uint8_t *fru_data, const size_t data_len)
//------------------------------------------------------------
// Cleanup routine
//------------------------------------------------------------
-int cleanup_error(FILE *fru_fp, fru_area_vec_t & fru_area_vec)
+int cleanup_error(FILE* fru_fp, fru_area_vec_t& fru_area_vec)
{
- if(fru_fp != NULL)
+ if (fru_fp != NULL)
{
fclose(fru_fp);
fru_fp = NULL;
}
- if(!(fru_area_vec.empty()))
+ if (!(fru_area_vec.empty()))
{
fru_area_vec.clear();
}
- return -1;
+ return -1;
}
///-----------------------------------------------------
// Accepts the filename and validates per IPMI FRU spec
//----------------------------------------------------
-int ipmi_validate_fru_area(const uint8_t fruid, const char *fru_file_name,
- sd_bus *bus_type, const bool bmc_fru)
+int ipmi_validate_fru_area(const uint8_t fruid, const char* fru_file_name,
+ sd_bus* bus_type, const bool bmc_fru)
{
size_t data_len = 0;
size_t bytes_read = 0;
@@ -577,12 +575,12 @@ int ipmi_validate_fru_area(const uint8_t fruid, const char *fru_file_name,
// are not used, keeping it here for completeness.
fru_area_vec_t fru_area_vec;
- for(uint8_t fru_entry = IPMI_FRU_INTERNAL_OFFSET;
- fru_entry < (sizeof(struct common_header) -2); fru_entry++)
+ for (uint8_t fru_entry = IPMI_FRU_INTERNAL_OFFSET;
+ fru_entry < (sizeof(struct common_header) - 2); fru_entry++)
{
// Create an object and push onto a vector.
- std::unique_ptr<ipmi_fru> fru_area = std::make_unique<ipmi_fru>
- (fruid, get_fru_area_type(fru_entry), bus_type, bmc_fru);
+ std::unique_ptr<ipmi_fru> fru_area = std::make_unique<ipmi_fru>(
+ fruid, get_fru_area_type(fru_entry), bus_type, bmc_fru);
// Physically being present
bool present = access(fru_file_name, F_OK) == 0;
@@ -591,16 +589,16 @@ int ipmi_validate_fru_area(const uint8_t fruid, const char *fru_file_name,
fru_area_vec.emplace_back(std::move(fru_area));
}
- FILE *fru_fp = fopen(fru_file_name,"rb");
- if(fru_fp == NULL)
+ FILE* fru_fp = fopen(fru_file_name, "rb");
+ if (fru_fp == NULL)
{
- fprintf(stderr, "ERROR: opening:[%s]\n",fru_file_name);
+ fprintf(stderr, "ERROR: opening:[%s]\n", fru_file_name);
perror("Error:");
return cleanup_error(fru_fp, fru_area_vec);
}
// Get the size of the file to see if it meets minimum requirement
- if(fseek(fru_fp, 0, SEEK_END))
+ if (fseek(fru_fp, 0, SEEK_END))
{
perror("Error:");
return cleanup_error(fru_fp, fru_area_vec);
@@ -612,9 +610,10 @@ int ipmi_validate_fru_area(const uint8_t fruid, const char *fru_file_name,
rewind(fru_fp);
bytes_read = fread(fru_data, data_len, 1, fru_fp);
- if(bytes_read != 1)
+ if (bytes_read != 1)
{
- fprintf(stderr, "Failed reading fru data. Bytes_read=[%zd]\n",bytes_read);
+ fprintf(stderr, "Failed reading fru data. Bytes_read=[%zd]\n",
+ bytes_read);
perror("Error:");
return cleanup_error(fru_fp, fru_area_vec);
}
@@ -624,30 +623,31 @@ int ipmi_validate_fru_area(const uint8_t fruid, const char *fru_file_name,
fru_fp = NULL;
rc = ipmi_validate_common_hdr(fru_data, data_len);
- if(rc < 0)
+ if (rc < 0)
{
return cleanup_error(fru_fp, fru_area_vec);
}
- // Now that we validated the common header, populate various fru sections if we have them here.
+ // Now that we validated the common header, populate various fru sections if
+ // we have them here.
rc = ipmi_populate_fru_areas(fru_data, data_len, fru_area_vec);
- if(rc < 0)
+ if (rc < 0)
{
- fprintf(stderr,"Populating FRU areas failed for:[%d]\n",fruid);
+ fprintf(stderr, "Populating FRU areas failed for:[%d]\n", fruid);
return cleanup_error(fru_fp, fru_area_vec);
}
else
{
- printf("SUCCESS: Populated FRU areas for:[%s]\n",fru_file_name);
+ printf("SUCCESS: Populated FRU areas for:[%s]\n", fru_file_name);
}
#ifdef __IPMI_DEBUG__
- for(auto& iter : fru_area_vec)
+ for (auto& iter : fru_area_vec)
{
- printf("FRU ID : [%d]\n",(iter)->get_fruid());
- printf("AREA NAME : [%s]\n",(iter)->get_name());
- printf("TYPE : [%d]\n",(iter)->get_type());
- printf("LEN : [%d]\n",(iter)->get_len());
+ printf("FRU ID : [%d]\n", (iter)->get_fruid());
+ printf("AREA NAME : [%s]\n", (iter)->get_name());
+ printf("TYPE : [%d]\n", (iter)->get_type());
+ printf("LEN : [%d]\n", (iter)->get_len());
printf("BUS NAME : [%s]\n", (iter)->get_bus_name());
printf("OBJ PATH : [%s]\n", (iter)->get_obj_path());
printf("INTF NAME :[%s]\n", (iter)->get_intf_name());
@@ -656,14 +656,14 @@ int ipmi_validate_fru_area(const uint8_t fruid, const char *fru_file_name,
// If the vector is populated with everything, then go ahead and update the
// inventory.
- if(!(fru_area_vec.empty()))
+ if (!(fru_area_vec.empty()))
{
#ifdef __IPMI_DEBUG__
- printf("\n SIZE of vector is : [%d] \n",fru_area_vec.size());
+ printf("\n SIZE of vector is : [%d] \n", fru_area_vec.size());
#endif
rc = ipmi_update_inventory(fru_area_vec, bus_type);
- if(rc <0)
+ if (rc < 0)
{
fprintf(stderr, "Error updating inventory\n");
}
diff --git a/writefrudata.hpp b/writefrudata.hpp
index c65c21b..6b5ed47 100644
--- a/writefrudata.hpp
+++ b/writefrudata.hpp
@@ -1,8 +1,8 @@
#ifndef __IPMI_WRITE_FRU_DATA_H__
#define __IPMI_WRITE_FRU_DATA_H__
-#include <stdint.h>
#include <stddef.h>
+#include <stdint.h>
#include <systemd/sd-bus.h>
#ifndef __cplusplus
@@ -18,11 +18,11 @@ enum ipmi_netfn_storage_cmds
// Format of write fru data command
struct write_fru_data_t
{
- uint8_t frunum;
- uint8_t offsetls;
- uint8_t offsetms;
- uint8_t data;
-}__attribute__ ((packed));
+ uint8_t frunum;
+ uint8_t offsetls;
+ uint8_t offsetms;
+ uint8_t data;
+} __attribute__((packed));
// Per IPMI v2.0 FRU specification
struct common_header
@@ -35,23 +35,23 @@ struct common_header
uint8_t multi_offset;
uint8_t pad;
uint8_t crc;
-}__attribute__((packed));
+} __attribute__((packed));
// first byte in header is 1h per IPMI V2 spec.
-#define IPMI_FRU_HDR_BYTE_ZERO 1
+#define IPMI_FRU_HDR_BYTE_ZERO 1
#define IPMI_FRU_INTERNAL_OFFSET offsetof(struct common_header, internal_offset)
-#define IPMI_FRU_CHASSIS_OFFSET offsetof(struct common_header, chassis_offset)
-#define IPMI_FRU_BOARD_OFFSET offsetof(struct common_header, board_offset)
-#define IPMI_FRU_PRODUCT_OFFSET offsetof(struct common_header, product_offset)
-#define IPMI_FRU_MULTI_OFFSET offsetof(struct common_header, multi_offset)
-#define IPMI_FRU_HDR_CRC_OFFSET offsetof(struct common_header, crc)
-#define IPMI_EIGHT_BYTES 8
+#define IPMI_FRU_CHASSIS_OFFSET offsetof(struct common_header, chassis_offset)
+#define IPMI_FRU_BOARD_OFFSET offsetof(struct common_header, board_offset)
+#define IPMI_FRU_PRODUCT_OFFSET offsetof(struct common_header, product_offset)
+#define IPMI_FRU_MULTI_OFFSET offsetof(struct common_header, multi_offset)
+#define IPMI_FRU_HDR_CRC_OFFSET offsetof(struct common_header, crc)
+#define IPMI_EIGHT_BYTES 8
#ifdef __cplusplus
extern "C" {
#endif
-int ipmi_validate_fru_area(const uint8_t, const char *, sd_bus *, const bool);
+int ipmi_validate_fru_area(const uint8_t, const char*, sd_bus*, const bool);
#ifdef __cplusplus
} // extern C
OpenPOWER on IntegriCloud