blob: 9a39f90907976d1cd9967838bc2c0d7d3dc353e3 [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.
Patrick Venture1816ff32018-10-21 13:32:06 -070028 */
Jayanth Othayoth70cb0672025-06-07 02:13:23 -050029 IPMIFruArea(const uint8_t fruID, const ipmi_fru_area_type type);
vishwac93d6d42015-12-16 11:55:16 -060030
Patrick Venture1816ff32018-10-21 13:32:06 -070031 /**
32 * Set whether the FRU is present.
33 *
34 * @param[in] present - True if present.
35 */
Patrick Venturef22b36a2018-10-20 20:59:07 -070036 inline void setPresent(const bool present)
Patrick Venturec9508db2018-10-16 17:18:43 -070037 {
Patrick Ventureb9d33732018-10-20 20:41:57 -070038 isPresent = present;
Patrick Venturec9508db2018-10-16 17:18:43 -070039 }
vishwac93d6d42015-12-16 11:55:16 -060040
Patrick Venture1816ff32018-10-21 13:32:06 -070041 /**
42 * Retrieves the FRU's ID.
43 *
44 * @return the FRU ID.
45 */
Patrick Venturef22b36a2018-10-20 20:59:07 -070046 uint8_t getFruID() const
Patrick Venturec9508db2018-10-16 17:18:43 -070047 {
Patrick Venture9f65a082018-10-21 13:18:17 -070048 return fruID;
Patrick Venturec9508db2018-10-16 17:18:43 -070049 }
vishwac93d6d42015-12-16 11:55:16 -060050
Patrick Venture1816ff32018-10-21 13:32:06 -070051 /**
52 * Returns the length of the FRU data.
53 *
54 * @return the number of bytes.
55 */
Patrick Venturef22b36a2018-10-20 20:59:07 -070056 size_t getLength() const
Patrick Venturec9508db2018-10-16 17:18:43 -070057 {
Patrick Venturef0f1ab92018-10-21 13:03:01 -070058 return data.size();
Patrick Venturec9508db2018-10-16 17:18:43 -070059 }
vishwac93d6d42015-12-16 11:55:16 -060060
Patrick Venture1816ff32018-10-21 13:32:06 -070061 /**
62 * Returns the type of the current FRU area.
63 *
64 * @return the type of FRU area
65 */
Patrick Venturef22b36a2018-10-20 20:59:07 -070066 ipmi_fru_area_type getType() const
Patrick Venturec9508db2018-10-16 17:18:43 -070067 {
Patrick Ventureb9d33732018-10-20 20:41:57 -070068 return type;
Patrick Venturec9508db2018-10-16 17:18:43 -070069 }
vishwac93d6d42015-12-16 11:55:16 -060070
Patrick Venture1816ff32018-10-21 13:32:06 -070071 /**
72 * Returns the FRU area name.
73 *
74 * @return the FRU area name
75 */
Patrick Venturef22b36a2018-10-20 20:59:07 -070076 const char* getName() const
Patrick Venturec9508db2018-10-16 17:18:43 -070077 {
Patrick Ventureb9d33732018-10-20 20:41:57 -070078 return name.c_str();
Patrick Venturec9508db2018-10-16 17:18:43 -070079 }
vishwac93d6d42015-12-16 11:55:16 -060080
Patrick Venture1816ff32018-10-21 13:32:06 -070081 /**
82 * Returns the data portion.
83 *
84 * @return pointer to data
85 */
Patrick Venturef0f1ab92018-10-21 13:03:01 -070086 inline const uint8_t* getData() const
Patrick Venturec9508db2018-10-16 17:18:43 -070087 {
Patrick Venturef0f1ab92018-10-21 13:03:01 -070088 return data.data();
Patrick Venturec9508db2018-10-16 17:18:43 -070089 }
vishwac93d6d42015-12-16 11:55:16 -060090
Patrick Venture1816ff32018-10-21 13:32:06 -070091 /**
92 * Accepts a pointer to data and sets it in the object.
93 *
94 * @param[in] value - The data to copy into the FRU area
95 * @param[in] length - the number of bytes value points to
96 */
97 void setData(const uint8_t* value, const size_t length);
vishwac93d6d42015-12-16 11:55:16 -060098
Patrick Venture524ba9c2018-10-20 20:52:27 -070099 private:
100 // Unique way of identifying a FRU
Patrick Venture9f65a082018-10-21 13:18:17 -0700101 uint8_t fruID = 0;
Patrick Venture524ba9c2018-10-20 20:52:27 -0700102
Patrick Venture1816ff32018-10-21 13:32:06 -0700103 // Type of the FRU matching offsets in common header
Patrick Venture524ba9c2018-10-20 20:52:27 -0700104 ipmi_fru_area_type type = IPMI_FRU_AREA_INTERNAL_USE;
105
Patrick Venture1816ff32018-10-21 13:32:06 -0700106 // Name of the FRU area. ( BOARD/CHASSIS/PRODUCT )
Patrick Venture524ba9c2018-10-20 20:52:27 -0700107 std::string name;
108
Patrick Venture524ba9c2018-10-20 20:52:27 -0700109 // If a FRU is physically present.
110 bool isPresent = false;
111
Patrick Venture524ba9c2018-10-20 20:52:27 -0700112 // Actual area data.
Patrick Venturef0f1ab92018-10-21 13:03:01 -0700113 std::vector<uint8_t> data;
vishwac93d6d42015-12-16 11:55:16 -0600114};
115
116#endif