blob: 6eec66ba135796765a3d7f4b24aac83a8bb6725d [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;
Ratan Gupta00659052017-02-23 17:29:08 +0530137
Emily Shaffercc941e12017-06-14 13:06:26 -0700138enum class Mutability
139{
Patrick Venture0b02be92018-08-31 11:55:55 -0700140 Read = 1 << 0,
141 Write = 1 << 1,
Emily Shaffercc941e12017-06-14 13:06:26 -0700142};
143
144inline Mutability operator|(Mutability lhs, Mutability rhs)
145{
Patrick Venture0b02be92018-08-31 11:55:55 -0700146 return static_cast<Mutability>(static_cast<uint8_t>(lhs) |
147 static_cast<uint8_t>(rhs));
Emily Shaffercc941e12017-06-14 13:06:26 -0700148}
149
150inline Mutability operator&(Mutability lhs, Mutability rhs)
151{
Patrick Venture0b02be92018-08-31 11:55:55 -0700152 return static_cast<Mutability>(static_cast<uint8_t>(lhs) &
153 static_cast<uint8_t>(rhs));
Emily Shaffercc941e12017-06-14 13:06:26 -0700154}
155
Ratan Gupta00659052017-02-23 17:29:08 +0530156struct Info
157{
Patrick Venture0b02be92018-08-31 11:55:55 -0700158 EntityType entityType;
159 EntityInst instance;
160 Type sensorType;
161 InstancePath sensorPath;
162 DbusInterface sensorInterface;
163 ReadingType sensorReadingType;
164 Multiplier coefficientM;
165 OffsetB coefficientB;
166 Exponent exponentB;
167 ScaledOffset scaledOffset;
168 Exponent exponentR;
169 bool hasScale;
170 Scale scale;
171 Unit unit;
172 std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
173 std::function<GetSensorResponse(const Info&)> getFunc;
174 Mutability mutability;
Jeremy Kerrbe4ffa82020-08-10 16:17:37 +0800175 SensorName sensorName;
Patrick Venture0b02be92018-08-31 11:55:55 -0700176 std::function<SensorName(const Info&)> sensorNameFunc;
177 DbusInterfaceMap propertyInterfaces;
Ratan Gupta00659052017-02-23 17:29:08 +0530178};
179
180using Id = uint8_t;
Patrick Venture0b02be92018-08-31 11:55:55 -0700181using IdInfoMap = std::map<Id, Info>;
Ratan Gupta00659052017-02-23 17:29:08 +0530182
Ratan Guptadcb10672017-07-10 10:33:50 +0530183using PropertyMap = ipmi::PropertyMap;
Tom Josephbe703f72017-03-09 12:34:35 +0530184
185using InterfaceMap = std::map<DbusInterface, PropertyMap>;
186
187using Object = sdbusplus::message::object_path;
188using ObjectMap = std::map<Object, InterfaceMap>;
189
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500190using IpmiUpdateData = sdbusplus::message::message;
191
Tom Josephdd78a1d2017-05-05 11:04:29 +0530192struct SelData
193{
Patrick Venture0b02be92018-08-31 11:55:55 -0700194 Id sensorID;
195 Type sensorType;
196 ReadingType eventReadingType;
197 Offset eventOffset;
Tom Josephdd78a1d2017-05-05 11:04:29 +0530198};
199
200using InventoryPath = std::string;
201
202using InvObjectIDMap = std::map<InventoryPath, SelData>;
203
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600204enum class ThresholdMask
205{
206 NON_CRITICAL_LOW_MASK = 0x01,
207 CRITICAL_LOW_MASK = 0x02,
208 NON_CRITICAL_HIGH_MASK = 0x08,
209 CRITICAL_HIGH_MASK = 0x10,
210};
211
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -0800212static constexpr uint8_t maxContainedEntities = 4;
213using ContainedEntitiesArray =
214 std::array<std::pair<uint8_t, uint8_t>, maxContainedEntities>;
215
216struct EntityInfo
217{
218 uint8_t containerEntityId;
219 uint8_t containerEntityInstance;
220 bool isList;
221 bool isLinked;
222 ContainedEntitiesArray containedEntities;
223};
224
225using EntityInfoMap = std::map<Id, EntityInfo>;
226
Patrick Venture0b02be92018-08-31 11:55:55 -0700227} // namespace sensor
Ratan Gupta8c31d232017-08-13 05:49:43 +0530228
229namespace network
230{
Ratan Gupta8c31d232017-08-13 05:49:43 +0530231constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
Ratan Gupta8c31d232017-08-13 05:49:43 +0530232
233constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
234constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;
235
236constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
237constexpr auto DEFAULT_ADDRESS = "0.0.0.0";
238
Patrick Venture0b02be92018-08-31 11:55:55 -0700239} // namespace network
William A. Kennington IIIc514d872019-04-06 18:19:38 -0700240
Snehalatha Venkatesh745164c2021-06-25 10:02:25 +0000241template <typename T>
242class SecureAllocator : public std::allocator<T>
243{
244 public:
245 template <typename U>
246 struct rebind
247 {
248 typedef SecureAllocator<U> other;
249 };
250
251 void deallocate(T* p, size_t n)
252 {
253 OPENSSL_cleanse(p, n);
254 return std::allocator<T>::deallocate(p, n);
255 }
256};
257using SecureString =
258 std::basic_string<char, std::char_traits<char>, SecureAllocator<char>>;
259
Patrick Venture0b02be92018-08-31 11:55:55 -0700260} // namespace ipmi
Snehalatha Venkatesh745164c2021-06-25 10:02:25 +0000261namespace std
262{
263
264template <>
265inline ipmi::SecureString::~SecureString()
266{
267 OPENSSL_cleanse(&((*this)[0]), this->size());
268}
269} // namespace std