xref: /openbmc/ipmi-fru-parser/fru_area.hpp (revision 5c2bd5ed)
1 #ifndef __IPMI_FRU_AREA_H__
2 #define __IPMI_FRU_AREA_H__
3 
4 #include "frup.hpp"
5 #include "writefrudata.hpp"
6 
7 #include <stddef.h>
8 #include <stdint.h>
9 #include <systemd/sd-bus.h>
10 
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 class IPMIFruArea;
16 typedef std::vector<std::unique_ptr<IPMIFruArea>> fru_area_vec_t;
17 
18 class IPMIFruArea
19 {
20   private:
21     // Unique way of identifying a FRU
22     uint8_t iv_fruid = 0;
23 
24     // Type of the fru matching offsets in common header
25     ipmi_fru_area_type iv_type = IPMI_FRU_AREA_INTERNAL_USE;
26 
27     // Name of the fru area. ( BOARD/CHASSIS/PRODUCT )
28     std::string iv_name;
29 
30     // Length of a specific fru area.
31     size_t iv_len = 0;
32 
33     // Special bit for BMC readable eeprom only.
34     bool iv_bmc_fru = false;
35 
36     // If a FRU is physically present.
37     bool iv_present = false;
38 
39     // Whether a particular area is valid ?
40     bool iv_valid = false;
41 
42     // Actual area data.
43     uint8_t* iv_data = nullptr;
44 
45     // fru inventory dbus name
46     std::string iv_bus_name;
47 
48     // fru inventory dbus object path
49     std::string iv_obj_path;
50 
51     // fru inventory dbus interface name
52     std::string iv_intf_name;
53 
54     // Default constructor disabled.
55     IPMIFruArea();
56 
57   public:
58     // constructor
59     IPMIFruArea(const uint8_t fruid, const ipmi_fru_area_type type,
60                 bool bmc_fru = false);
61 
62     // Destructor
63     virtual ~IPMIFruArea();
64 
65     // If a particular area has been marked valid / invalid
66     inline bool is_valid() const
67     {
68         return iv_valid;
69     }
70 
71     // Sets the present bit
72     inline void set_present(const bool present)
73     {
74         iv_present = present;
75     }
76 
77     // Sets the valid bit for a corresponding area.
78     inline void set_valid(const bool valid)
79     {
80         iv_valid = valid;
81     }
82 
83     // If a particular area accessible only by BMC
84     inline bool is_bmc_fru() const
85     {
86         return iv_bmc_fru;
87     }
88 
89     // returns fru id;
90     uint8_t get_fruid() const
91     {
92         return iv_fruid;
93     }
94 
95     // Returns the length.
96     size_t get_len() const
97     {
98         return iv_len;
99     }
100 
101     // Returns the type of the current fru area
102     ipmi_fru_area_type get_type() const
103     {
104         return iv_type;
105     }
106 
107     // Returns the name
108     const char* get_name() const
109     {
110         return iv_name.c_str();
111     }
112 
113     // Returns SD bus name
114     const char* get_bus_name() const
115     {
116         return iv_bus_name.c_str();
117     }
118 
119     // Retrns SD bus object path
120     const char* get_obj_path() const
121     {
122         return iv_obj_path.c_str();
123     }
124 
125     // Returns SD bus interface name
126     const char* get_intf_name() const
127     {
128         return iv_intf_name.c_str();
129     }
130 
131     // Returns the data portion
132     inline uint8_t* get_data() const
133     {
134         return iv_data;
135     }
136 
137     // Accepts a pointer to data and sets it in the object.
138     void set_data(const uint8_t*, const size_t);
139 
140     // Sets the dbus parameters
141     void update_dbus_paths(const char*, const char*, const char*);
142 };
143 
144 #endif
145