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