blob: 0bee9afb58a5a5c938a04d612f91ec2483557300 [file] [log] [blame]
vishwac93d6d42015-12-16 11:55:16 -06001#ifndef __IPMI_FRU_AREA_H__
2#define __IPMI_FRU_AREA_H__
3
Ratan Gupta19c617b2017-02-10 15:39:40 +05304#include "frup.hpp"
Matthew Barth155c34f2016-10-18 14:33:17 -05005#include "writefrudata.hpp"
vishwac93d6d42015-12-16 11:55:16 -06006
Patrick Ventureb4c333f2018-10-20 20:16:39 -07007#include <cstdint>
Patrick Venturec9508db2018-10-16 17:18:43 -07008#include <memory>
9#include <string>
10#include <vector>
11
Patrick Ventureb4c333f2018-10-20 20:16:39 -070012using std::uint8_t;
13
Patrick Venture1816ff32018-10-21 13:32:06 -070014/**
15 * IPMIFruArea represents a piece of a FRU that is accessible over IPMI.
16 */
Patrick Venture9eb82cf2018-10-20 19:36:01 -070017class IPMIFruArea
vishwac93d6d42015-12-16 11:55:16 -060018{
Patrick Venturec9508db2018-10-16 17:18:43 -070019 public:
Patrick Ventureac988992018-10-21 08:37:18 -070020 IPMIFruArea() = delete;
Patrick Venture1d001782018-10-21 13:11:08 -070021 ~IPMIFruArea() = default;
Patrick Ventureac988992018-10-21 08:37:18 -070022
Patrick Venture1816ff32018-10-21 13:32:06 -070023 /**
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 */
Patrick Venture9f65a082018-10-21 13:18:17 -070030 IPMIFruArea(const uint8_t fruID, const ipmi_fru_area_type type,
31 bool bmcOnlyFru = false);
vishwac93d6d42015-12-16 11:55:16 -060032
Patrick Venture1816ff32018-10-21 13:32:06 -070033 /**
34 * Set whether the FRU is present.
35 *
36 * @param[in] present - True if present.
37 */
Patrick Venturef22b36a2018-10-20 20:59:07 -070038 inline void setPresent(const bool present)
Patrick Venturec9508db2018-10-16 17:18:43 -070039 {
Patrick Ventureb9d33732018-10-20 20:41:57 -070040 isPresent = present;
Patrick Venturec9508db2018-10-16 17:18:43 -070041 }
vishwac93d6d42015-12-16 11:55:16 -060042
Patrick Venture1816ff32018-10-21 13:32:06 -070043 /**
44 * Retrieves the FRU's ID.
45 *
46 * @return the FRU ID.
47 */
Patrick Venturef22b36a2018-10-20 20:59:07 -070048 uint8_t getFruID() const
Patrick Venturec9508db2018-10-16 17:18:43 -070049 {
Patrick Venture9f65a082018-10-21 13:18:17 -070050 return fruID;
Patrick Venturec9508db2018-10-16 17:18:43 -070051 }
vishwac93d6d42015-12-16 11:55:16 -060052
Patrick Venture1816ff32018-10-21 13:32:06 -070053 /**
54 * Returns the length of the FRU data.
55 *
56 * @return the number of bytes.
57 */
Patrick Venturef22b36a2018-10-20 20:59:07 -070058 size_t getLength() const
Patrick Venturec9508db2018-10-16 17:18:43 -070059 {
Patrick Venturef0f1ab92018-10-21 13:03:01 -070060 return data.size();
Patrick Venturec9508db2018-10-16 17:18:43 -070061 }
vishwac93d6d42015-12-16 11:55:16 -060062
Patrick Venture1816ff32018-10-21 13:32:06 -070063 /**
64 * Returns the type of the current FRU area.
65 *
66 * @return the type of FRU area
67 */
Patrick Venturef22b36a2018-10-20 20:59:07 -070068 ipmi_fru_area_type getType() const
Patrick Venturec9508db2018-10-16 17:18:43 -070069 {
Patrick Ventureb9d33732018-10-20 20:41:57 -070070 return type;
Patrick Venturec9508db2018-10-16 17:18:43 -070071 }
vishwac93d6d42015-12-16 11:55:16 -060072
Patrick Venture1816ff32018-10-21 13:32:06 -070073 /**
74 * Returns the FRU area name.
75 *
76 * @return the FRU area name
77 */
Patrick Venturef22b36a2018-10-20 20:59:07 -070078 const char* getName() const
Patrick Venturec9508db2018-10-16 17:18:43 -070079 {
Patrick Ventureb9d33732018-10-20 20:41:57 -070080 return name.c_str();
Patrick Venturec9508db2018-10-16 17:18:43 -070081 }
vishwac93d6d42015-12-16 11:55:16 -060082
Patrick Venture1816ff32018-10-21 13:32:06 -070083 /**
84 * Returns the data portion.
85 *
86 * @return pointer to data
87 */
Patrick Venturef0f1ab92018-10-21 13:03:01 -070088 inline const uint8_t* getData() const
Patrick Venturec9508db2018-10-16 17:18:43 -070089 {
Patrick Venturef0f1ab92018-10-21 13:03:01 -070090 return data.data();
Patrick Venturec9508db2018-10-16 17:18:43 -070091 }
vishwac93d6d42015-12-16 11:55:16 -060092
Patrick Venture1816ff32018-10-21 13:32:06 -070093 /**
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);
vishwac93d6d42015-12-16 11:55:16 -0600100
Patrick Venture524ba9c2018-10-20 20:52:27 -0700101 private:
102 // Unique way of identifying a FRU
Patrick Venture9f65a082018-10-21 13:18:17 -0700103 uint8_t fruID = 0;
Patrick Venture524ba9c2018-10-20 20:52:27 -0700104
Patrick Venture1816ff32018-10-21 13:32:06 -0700105 // Type of the FRU matching offsets in common header
Patrick Venture524ba9c2018-10-20 20:52:27 -0700106 ipmi_fru_area_type type = IPMI_FRU_AREA_INTERNAL_USE;
107
Patrick Venture1816ff32018-10-21 13:32:06 -0700108 // Name of the FRU area. ( BOARD/CHASSIS/PRODUCT )
Patrick Venture524ba9c2018-10-20 20:52:27 -0700109 std::string name;
110
Patrick Venture524ba9c2018-10-20 20:52:27 -0700111 // Special bit for BMC readable eeprom only.
Patrick Venture9f65a082018-10-21 13:18:17 -0700112 bool bmcOnlyFru = false;
Patrick Venture524ba9c2018-10-20 20:52:27 -0700113
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.
Patrick Venturef0f1ab92018-10-21 13:03:01 -0700121 std::vector<uint8_t> data;
vishwac93d6d42015-12-16 11:55:16 -0600122};
123
124#endif