xref: /openbmc/ipmi-fru-parser/fru_area.hpp (revision 1816ff30)
1 #ifndef __IPMI_FRU_AREA_H__
2 #define __IPMI_FRU_AREA_H__
3 
4 #include "frup.hpp"
5 #include "writefrudata.hpp"
6 
7 #include <cstdint>
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 using std::uint8_t;
13 
14 /**
15  * IPMIFruArea represents a piece of a FRU that is accessible over IPMI.
16  */
17 class IPMIFruArea
18 {
19   public:
20     IPMIFruArea() = delete;
21     ~IPMIFruArea() = default;
22 
23     /**
24      * Construct an IPMIFruArea.
25      *
26      * @param[in] fruID - FRU identifier value
27      * @param[in] type - the type of FRU area.
28      * @param[in] bmcOnlyFru - Is this FRU only accessible via the BMC
29      */
30     IPMIFruArea(const uint8_t fruID, const ipmi_fru_area_type type,
31                 bool bmcOnlyFru = false);
32 
33     /**
34      * Set whether the FRU is present.
35      *
36      * @param[in] present - True if present.
37      */
setPresent(const bool present)38     inline void setPresent(const bool present)
39     {
40         isPresent = present;
41     }
42 
43     /**
44      * Retrieves the FRU's ID.
45      *
46      * @return the FRU ID.
47      */
getFruID() const48     uint8_t getFruID() const
49     {
50         return fruID;
51     }
52 
53     /**
54      *  Returns the length of the FRU data.
55      *
56      * @return the number of bytes.
57      */
getLength() const58     size_t getLength() const
59     {
60         return data.size();
61     }
62 
63     /**
64      * Returns the type of the current FRU area.
65      *
66      * @return the type of FRU area
67      */
getType() const68     ipmi_fru_area_type getType() const
69     {
70         return type;
71     }
72 
73     /**
74      * Returns the FRU area name.
75      *
76      * @return the FRU area name
77      */
getName() const78     const char* getName() const
79     {
80         return name.c_str();
81     }
82 
83     /**
84      * Returns the data portion.
85      *
86      * @return pointer to data
87      */
getData() const88     inline const uint8_t* getData() const
89     {
90         return data.data();
91     }
92 
93     /**
94      * Accepts a pointer to data and sets it in the object.
95      *
96      * @param[in] value - The data to copy into the FRU area
97      * @param[in] length - the number of bytes value points to
98      */
99     void setData(const uint8_t* value, const size_t length);
100 
101   private:
102     // Unique way of identifying a FRU
103     uint8_t fruID = 0;
104 
105     // Type of the FRU matching offsets in common header
106     ipmi_fru_area_type type = IPMI_FRU_AREA_INTERNAL_USE;
107 
108     // Name of the FRU area. ( BOARD/CHASSIS/PRODUCT )
109     std::string name;
110 
111     // Special bit for BMC readable eeprom only.
112     bool bmcOnlyFru = false;
113 
114     // If a FRU is physically present.
115     bool isPresent = false;
116 
117     // Whether a particular area is valid ?
118     bool isValid = false;
119 
120     // Actual area data.
121     std::vector<uint8_t> data;
122 };
123 
124 #endif
125