blob: 9c59ea0d35a272da77b540dd92357878f4f20c5f [file] [log] [blame]
Ratan Gupta00659052017-02-23 17:29:08 +05301#pragma once
2
Snehalatha Venkatesh745164c2021-06-25 10:02:25 +00003#include <openssl/crypto.h>
Ratan Gupta00659052017-02-23 17:29:08 +05304#include <stdint.h>
5
6#include <map>
Ratan Gupta00659052017-02-23 17:29:08 +05307#include <sdbusplus/server.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -07008#include <string>
Vernon Mauery16b86932019-05-01 08:36:11 -07009#include <variant>
Ratan Gupta00659052017-02-23 17:29:08 +053010
11namespace ipmi
12{
Ratan Guptadcb10672017-07-10 10:33:50 +053013
14using DbusObjectPath = std::string;
15using DbusService = std::string;
16using DbusInterface = std::string;
17using DbusObjectInfo = std::pair<DbusObjectPath, DbusService>;
18using DbusProperty = std::string;
Ratan Guptacc8feb42017-07-25 21:52:10 +053019
Willy Tude54f482021-01-26 15:59:09 -080020using Association = std::tuple<std::string, std::string, std::string>;
21
Hao Jiangd2afd052020-12-10 15:09:32 -080022using Value = std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
23 int64_t, uint64_t, double, std::string,
24 std::vector<std::string>, std::vector<Association>>;
Ratan Guptacc8feb42017-07-25 21:52:10 +053025
Ratan Guptadcb10672017-07-10 10:33:50 +053026using PropertyMap = std::map<DbusProperty, Value>;
Ratan Guptab8e99552017-07-27 07:07:48 +053027
Patrick Venture0b02be92018-08-31 11:55:55 -070028using ObjectTree =
29 std::map<DbusObjectPath, std::map<DbusService, std::vector<DbusInterface>>>;
Ratan Gupta8c31d232017-08-13 05:49:43 +053030
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053031using InterfaceList = std::vector<std::string>;
32
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -060033using DbusInterfaceMap = std::map<DbusInterface, PropertyMap>;
34
35using ObjectValueTree =
36 std::map<sdbusplus::message::object_path, DbusInterfaceMap>;
37
Ratan Gupta00659052017-02-23 17:29:08 +053038namespace sensor
39{
40
41using Offset = uint8_t;
Ratan Gupta00659052017-02-23 17:29:08 +053042
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -050043/**
44 * @enum SkipAssertion
45 * Matching value for skipping the update
46 */
47enum class SkipAssertion
48{
Patrick Venture0b02be92018-08-31 11:55:55 -070049 NONE, // No skip defined
50 ASSERT, // Skip on Assert
51 DEASSERT, // Skip on Deassert
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -050052};
53
Ratan Gupta00659052017-02-23 17:29:08 +053054struct Values
55{
Patrick Venture0b02be92018-08-31 11:55:55 -070056 SkipAssertion skip;
57 Value assert;
58 Value deassert;
Ratan Gupta00659052017-02-23 17:29:08 +053059};
60
Tom Joseph816e92b2017-09-06 19:23:00 +053061/**
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -050062 * @enum PreReqValues
63 * Pre-req conditions for a property.
64 */
65struct PreReqValues
66{
Patrick Venture0b02be92018-08-31 11:55:55 -070067 Value assert; // Value in case of assert.
68 Value deassert; // Value in case of deassert.
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -050069};
70
71using PreReqOffsetValueMap = std::map<Offset, PreReqValues>;
72
73/**
Tom Joseph816e92b2017-09-06 19:23:00 +053074 * @struct SetSensorReadingReq
75 *
76 * IPMI Request data for Set Sensor Reading and Event Status Command
77 */
78struct SetSensorReadingReq
79{
80 uint8_t number;
81 uint8_t operation;
82 uint8_t reading;
83 uint8_t assertOffset0_7;
84 uint8_t assertOffset8_14;
85 uint8_t deassertOffset0_7;
86 uint8_t deassertOffset8_14;
87 uint8_t eventData1;
88 uint8_t eventData2;
89 uint8_t eventData3;
90} __attribute__((packed));
91
92/**
93 * @struct GetReadingResponse
94 *
95 * IPMI response data for Get Sensor Reading command.
96 */
97struct GetReadingResponse
98{
Patrick Venture0b02be92018-08-31 11:55:55 -070099 uint8_t reading; //!< Sensor reading.
100 uint8_t operation; //!< Sensor scanning status / reading state.
101 uint8_t assertOffset0_7; //!< Discrete assertion states(0-7).
102 uint8_t assertOffset8_14; //!< Discrete assertion states(8-14).
Tom Joseph816e92b2017-09-06 19:23:00 +0530103} __attribute__((packed));
104
105constexpr auto inventoryRoot = "/xyz/openbmc_project/inventory";
106
Sui Chen4cc42552019-09-11 10:28:35 -0700107struct GetSensorResponse
108{
109 uint8_t reading; // sensor reading
110 bool readingOrStateUnavailable; // 1 = reading/state unavailable
111 bool scanningEnabled; // 0 = sensor scanning disabled
112 bool allEventMessagesEnabled; // 0 = All Event Messages disabled
113 uint8_t thresholdLevelsStates; // threshold/discrete sensor states
114 uint8_t discreteReadingSensorStates; // discrete-only, optional states
115};
Tom Joseph816e92b2017-09-06 19:23:00 +0530116
Patrick Venture0b02be92018-08-31 11:55:55 -0700117using OffsetValueMap = std::map<Offset, Values>;
Ratan Gupta00659052017-02-23 17:29:08 +0530118
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500119using DbusPropertyValues = std::pair<PreReqOffsetValueMap, OffsetValueMap>;
Ratan Gupta00659052017-02-23 17:29:08 +0530120
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500121using DbusPropertyMap = std::map<DbusProperty, DbusPropertyValues>;
122
123using DbusInterfaceMap = std::map<DbusInterface, DbusPropertyMap>;
Ratan Gupta00659052017-02-23 17:29:08 +0530124
125using InstancePath = std::string;
126using Type = uint8_t;
127using ReadingType = uint8_t;
Emily Shaffer10f49592017-05-10 12:01:10 -0700128using Multiplier = uint16_t;
Tom Joseph0a1301c2018-02-16 08:27:00 +0530129using OffsetB = int16_t;
130using Exponent = int8_t;
Emily Shaffer40011912018-10-09 12:06:04 -0700131using ScaledOffset = double;
Emily Shaffer62235612017-06-14 13:06:26 -0700132using Scale = int16_t;
133using Unit = std::string;
Tom Josephb0adbcd2018-01-24 11:51:29 +0530134using EntityType = uint8_t;
135using EntityInst = uint8_t;
136using SensorName = std::string;
Tony Leec5324252019-10-31 17:24:16 +0800137using SensorUnits1 = uint8_t;
Ratan Gupta00659052017-02-23 17:29:08 +0530138
Emily Shaffercc941e12017-06-14 13:06:26 -0700139enum class Mutability
140{
Patrick Venture0b02be92018-08-31 11:55:55 -0700141 Read = 1 << 0,
142 Write = 1 << 1,
Emily Shaffercc941e12017-06-14 13:06:26 -0700143};
144
145inline Mutability operator|(Mutability lhs, Mutability rhs)
146{
Patrick Venture0b02be92018-08-31 11:55:55 -0700147 return static_cast<Mutability>(static_cast<uint8_t>(lhs) |
148 static_cast<uint8_t>(rhs));
Emily Shaffercc941e12017-06-14 13:06:26 -0700149}
150
151inline Mutability operator&(Mutability lhs, Mutability rhs)
152{
Patrick Venture0b02be92018-08-31 11:55:55 -0700153 return static_cast<Mutability>(static_cast<uint8_t>(lhs) &
154 static_cast<uint8_t>(rhs));
Emily Shaffercc941e12017-06-14 13:06:26 -0700155}
156
Ratan Gupta00659052017-02-23 17:29:08 +0530157struct Info
158{
Patrick Venture0b02be92018-08-31 11:55:55 -0700159 EntityType entityType;
160 EntityInst instance;
161 Type sensorType;
162 InstancePath sensorPath;
163 DbusInterface sensorInterface;
164 ReadingType sensorReadingType;
165 Multiplier coefficientM;
166 OffsetB coefficientB;
167 Exponent exponentB;
168 ScaledOffset scaledOffset;
169 Exponent exponentR;
170 bool hasScale;
171 Scale scale;
Tony Leec5324252019-10-31 17:24:16 +0800172 SensorUnits1 sensorUnits1;
Patrick Venture0b02be92018-08-31 11:55:55 -0700173 Unit unit;
174 std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
175 std::function<GetSensorResponse(const Info&)> getFunc;
176 Mutability mutability;
Jeremy Kerrbe4ffa82020-08-10 16:17:37 +0800177 SensorName sensorName;
Patrick Venture0b02be92018-08-31 11:55:55 -0700178 std::function<SensorName(const Info&)> sensorNameFunc;
179 DbusInterfaceMap propertyInterfaces;
Ratan Gupta00659052017-02-23 17:29:08 +0530180};
181
182using Id = uint8_t;
Patrick Venture0b02be92018-08-31 11:55:55 -0700183using IdInfoMap = std::map<Id, Info>;
Ratan Gupta00659052017-02-23 17:29:08 +0530184
Ratan Guptadcb10672017-07-10 10:33:50 +0530185using PropertyMap = ipmi::PropertyMap;
Tom Josephbe703f72017-03-09 12:34:35 +0530186
187using InterfaceMap = std::map<DbusInterface, PropertyMap>;
188
189using Object = sdbusplus::message::object_path;
190using ObjectMap = std::map<Object, InterfaceMap>;
191
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500192using IpmiUpdateData = sdbusplus::message::message;
193
Tom Josephdd78a1d2017-05-05 11:04:29 +0530194struct SelData
195{
Patrick Venture0b02be92018-08-31 11:55:55 -0700196 Id sensorID;
197 Type sensorType;
198 ReadingType eventReadingType;
199 Offset eventOffset;
Tom Josephdd78a1d2017-05-05 11:04:29 +0530200};
201
202using InventoryPath = std::string;
203
204using InvObjectIDMap = std::map<InventoryPath, SelData>;
205
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600206enum class ThresholdMask
207{
208 NON_CRITICAL_LOW_MASK = 0x01,
209 CRITICAL_LOW_MASK = 0x02,
210 NON_CRITICAL_HIGH_MASK = 0x08,
211 CRITICAL_HIGH_MASK = 0x10,
212};
213
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -0800214static constexpr uint8_t maxContainedEntities = 4;
215using ContainedEntitiesArray =
216 std::array<std::pair<uint8_t, uint8_t>, maxContainedEntities>;
217
218struct EntityInfo
219{
220 uint8_t containerEntityId;
221 uint8_t containerEntityInstance;
222 bool isList;
223 bool isLinked;
224 ContainedEntitiesArray containedEntities;
225};
226
227using EntityInfoMap = std::map<Id, EntityInfo>;
228
Patrick Venture0b02be92018-08-31 11:55:55 -0700229} // namespace sensor
Ratan Gupta8c31d232017-08-13 05:49:43 +0530230
231namespace network
232{
Ratan Gupta8c31d232017-08-13 05:49:43 +0530233constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
Ratan Gupta8c31d232017-08-13 05:49:43 +0530234
235constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
236constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;
237
238constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
239constexpr auto DEFAULT_ADDRESS = "0.0.0.0";
240
Patrick Venture0b02be92018-08-31 11:55:55 -0700241} // namespace network
William A. Kennington IIIc514d872019-04-06 18:19:38 -0700242
Snehalatha Venkatesh745164c2021-06-25 10:02:25 +0000243template <typename T>
244class SecureAllocator : public std::allocator<T>
245{
246 public:
247 template <typename U>
248 struct rebind
249 {
250 typedef SecureAllocator<U> other;
251 };
252
253 void deallocate(T* p, size_t n)
254 {
255 OPENSSL_cleanse(p, n);
256 return std::allocator<T>::deallocate(p, n);
257 }
258};
259using SecureString =
260 std::basic_string<char, std::char_traits<char>, SecureAllocator<char>>;
261
Vernon Mauery997952a2021-07-30 14:06:14 -0700262using SecureBuffer = std::vector<uint8_t, SecureAllocator<uint8_t>>;
263
Patrick Venture0b02be92018-08-31 11:55:55 -0700264} // namespace ipmi
Vernon Mauery997952a2021-07-30 14:06:14 -0700265
Snehalatha Venkatesh745164c2021-06-25 10:02:25 +0000266namespace std
267{
Snehalatha Venkatesh745164c2021-06-25 10:02:25 +0000268template <>
269inline ipmi::SecureString::~SecureString()
270{
271 OPENSSL_cleanse(&((*this)[0]), this->size());
272}
Vernon Mauery997952a2021-07-30 14:06:14 -0700273
274template <>
275inline ipmi::SecureBuffer::~SecureBuffer()
276{
277 OPENSSL_cleanse(&((*this)[0]), this->size());
278}
Snehalatha Venkatesh745164c2021-06-25 10:02:25 +0000279} // namespace std