blob: 3332f813c4f1ca753e382a404a9b8820f77dbae1 [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;
Lei YU8c2c0482021-09-16 17:28:28 +0800175#ifndef FEATURE_SENSORS_CACHE
Patrick Venture0b02be92018-08-31 11:55:55 -0700176 std::function<GetSensorResponse(const Info&)> getFunc;
Lei YU8c2c0482021-09-16 17:28:28 +0800177#else
178 std::function<std::optional<GetSensorResponse>(
179 uint8_t, const Info&, sdbusplus::message::message&)>
180 getFunc;
181#endif
Patrick Venture0b02be92018-08-31 11:55:55 -0700182 Mutability mutability;
Jeremy Kerrbe4ffa82020-08-10 16:17:37 +0800183 SensorName sensorName;
Patrick Venture0b02be92018-08-31 11:55:55 -0700184 std::function<SensorName(const Info&)> sensorNameFunc;
185 DbusInterfaceMap propertyInterfaces;
Ratan Gupta00659052017-02-23 17:29:08 +0530186};
187
188using Id = uint8_t;
Patrick Venture0b02be92018-08-31 11:55:55 -0700189using IdInfoMap = std::map<Id, Info>;
Ratan Gupta00659052017-02-23 17:29:08 +0530190
Ratan Guptadcb10672017-07-10 10:33:50 +0530191using PropertyMap = ipmi::PropertyMap;
Tom Josephbe703f72017-03-09 12:34:35 +0530192
193using InterfaceMap = std::map<DbusInterface, PropertyMap>;
194
195using Object = sdbusplus::message::object_path;
196using ObjectMap = std::map<Object, InterfaceMap>;
197
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500198using IpmiUpdateData = sdbusplus::message::message;
199
Tom Josephdd78a1d2017-05-05 11:04:29 +0530200struct SelData
201{
Patrick Venture0b02be92018-08-31 11:55:55 -0700202 Id sensorID;
203 Type sensorType;
204 ReadingType eventReadingType;
205 Offset eventOffset;
Tom Josephdd78a1d2017-05-05 11:04:29 +0530206};
207
208using InventoryPath = std::string;
209
210using InvObjectIDMap = std::map<InventoryPath, SelData>;
211
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600212enum class ThresholdMask
213{
214 NON_CRITICAL_LOW_MASK = 0x01,
215 CRITICAL_LOW_MASK = 0x02,
216 NON_CRITICAL_HIGH_MASK = 0x08,
217 CRITICAL_HIGH_MASK = 0x10,
218};
219
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -0800220static constexpr uint8_t maxContainedEntities = 4;
221using ContainedEntitiesArray =
222 std::array<std::pair<uint8_t, uint8_t>, maxContainedEntities>;
223
224struct EntityInfo
225{
226 uint8_t containerEntityId;
227 uint8_t containerEntityInstance;
228 bool isList;
229 bool isLinked;
230 ContainedEntitiesArray containedEntities;
231};
232
233using EntityInfoMap = std::map<Id, EntityInfo>;
234
Patrick Venture0b02be92018-08-31 11:55:55 -0700235} // namespace sensor
Ratan Gupta8c31d232017-08-13 05:49:43 +0530236
237namespace network
238{
Ratan Gupta8c31d232017-08-13 05:49:43 +0530239constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
Ratan Gupta8c31d232017-08-13 05:49:43 +0530240
241constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
242constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;
243
244constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
245constexpr auto DEFAULT_ADDRESS = "0.0.0.0";
246
Patrick Venture0b02be92018-08-31 11:55:55 -0700247} // namespace network
William A. Kennington IIIc514d872019-04-06 18:19:38 -0700248
Snehalatha Venkatesh745164c2021-06-25 10:02:25 +0000249template <typename T>
250class SecureAllocator : public std::allocator<T>
251{
252 public:
253 template <typename U>
254 struct rebind
255 {
256 typedef SecureAllocator<U> other;
257 };
258
259 void deallocate(T* p, size_t n)
260 {
261 OPENSSL_cleanse(p, n);
262 return std::allocator<T>::deallocate(p, n);
263 }
264};
265using SecureString =
266 std::basic_string<char, std::char_traits<char>, SecureAllocator<char>>;
267
Vernon Mauery997952a2021-07-30 14:06:14 -0700268using SecureBuffer = std::vector<uint8_t, SecureAllocator<uint8_t>>;
269
Patrick Venture0b02be92018-08-31 11:55:55 -0700270} // namespace ipmi
Vernon Mauery997952a2021-07-30 14:06:14 -0700271
Snehalatha Venkatesh745164c2021-06-25 10:02:25 +0000272namespace std
273{
Snehalatha Venkatesh745164c2021-06-25 10:02:25 +0000274template <>
275inline ipmi::SecureString::~SecureString()
276{
277 OPENSSL_cleanse(&((*this)[0]), this->size());
278}
Vernon Mauery997952a2021-07-30 14:06:14 -0700279
280template <>
281inline ipmi::SecureBuffer::~SecureBuffer()
282{
283 OPENSSL_cleanse(&((*this)[0]), this->size());
284}
Snehalatha Venkatesh745164c2021-06-25 10:02:25 +0000285} // namespace std