blob: 3e64cb44ad68ef614ef400feb7893fc9763bb7f2 [file] [log] [blame]
Ratan Gupta00659052017-02-23 17:29:08 +05301#pragma once
2
3#include <stdint.h>
4
5#include <map>
Ratan Gupta00659052017-02-23 17:29:08 +05306#include <sdbusplus/server.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -07007#include <string>
Vernon Mauery16b86932019-05-01 08:36:11 -07008#include <variant>
Ratan Gupta00659052017-02-23 17:29:08 +05309
10namespace ipmi
11{
Ratan Guptadcb10672017-07-10 10:33:50 +053012
13using DbusObjectPath = std::string;
14using DbusService = std::string;
15using DbusInterface = std::string;
16using DbusObjectInfo = std::pair<DbusObjectPath, DbusService>;
17using DbusProperty = std::string;
Ratan Guptacc8feb42017-07-25 21:52:10 +053018
Vernon Mauery16b86932019-05-01 08:36:11 -070019using Value = std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
20 int64_t, uint64_t, double, std::string>;
Ratan Guptacc8feb42017-07-25 21:52:10 +053021
Ratan Guptadcb10672017-07-10 10:33:50 +053022using PropertyMap = std::map<DbusProperty, Value>;
Ratan Guptab8e99552017-07-27 07:07:48 +053023
Patrick Venture0b02be92018-08-31 11:55:55 -070024using ObjectTree =
25 std::map<DbusObjectPath, std::map<DbusService, std::vector<DbusInterface>>>;
Ratan Gupta8c31d232017-08-13 05:49:43 +053026
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053027using InterfaceList = std::vector<std::string>;
28
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -060029using DbusInterfaceMap = std::map<DbusInterface, PropertyMap>;
30
31using ObjectValueTree =
32 std::map<sdbusplus::message::object_path, DbusInterfaceMap>;
33
Ratan Gupta00659052017-02-23 17:29:08 +053034namespace sensor
35{
36
37using Offset = uint8_t;
Ratan Gupta00659052017-02-23 17:29:08 +053038
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -050039/**
40 * @enum SkipAssertion
41 * Matching value for skipping the update
42 */
43enum class SkipAssertion
44{
Patrick Venture0b02be92018-08-31 11:55:55 -070045 NONE, // No skip defined
46 ASSERT, // Skip on Assert
47 DEASSERT, // Skip on Deassert
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -050048};
49
Ratan Gupta00659052017-02-23 17:29:08 +053050struct Values
51{
Patrick Venture0b02be92018-08-31 11:55:55 -070052 SkipAssertion skip;
53 Value assert;
54 Value deassert;
Ratan Gupta00659052017-02-23 17:29:08 +053055};
56
Tom Joseph816e92b2017-09-06 19:23:00 +053057/**
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -050058 * @enum PreReqValues
59 * Pre-req conditions for a property.
60 */
61struct PreReqValues
62{
Patrick Venture0b02be92018-08-31 11:55:55 -070063 Value assert; // Value in case of assert.
64 Value deassert; // Value in case of deassert.
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -050065};
66
67using PreReqOffsetValueMap = std::map<Offset, PreReqValues>;
68
69/**
Tom Joseph816e92b2017-09-06 19:23:00 +053070 * @struct SetSensorReadingReq
71 *
72 * IPMI Request data for Set Sensor Reading and Event Status Command
73 */
74struct SetSensorReadingReq
75{
76 uint8_t number;
77 uint8_t operation;
78 uint8_t reading;
79 uint8_t assertOffset0_7;
80 uint8_t assertOffset8_14;
81 uint8_t deassertOffset0_7;
82 uint8_t deassertOffset8_14;
83 uint8_t eventData1;
84 uint8_t eventData2;
85 uint8_t eventData3;
86} __attribute__((packed));
87
88/**
89 * @struct GetReadingResponse
90 *
91 * IPMI response data for Get Sensor Reading command.
92 */
93struct GetReadingResponse
94{
Patrick Venture0b02be92018-08-31 11:55:55 -070095 uint8_t reading; //!< Sensor reading.
96 uint8_t operation; //!< Sensor scanning status / reading state.
97 uint8_t assertOffset0_7; //!< Discrete assertion states(0-7).
98 uint8_t assertOffset8_14; //!< Discrete assertion states(8-14).
Tom Joseph816e92b2017-09-06 19:23:00 +053099} __attribute__((packed));
100
101constexpr auto inventoryRoot = "/xyz/openbmc_project/inventory";
102
Sui Chen4cc42552019-09-11 10:28:35 -0700103struct GetSensorResponse
104{
105 uint8_t reading; // sensor reading
106 bool readingOrStateUnavailable; // 1 = reading/state unavailable
107 bool scanningEnabled; // 0 = sensor scanning disabled
108 bool allEventMessagesEnabled; // 0 = All Event Messages disabled
109 uint8_t thresholdLevelsStates; // threshold/discrete sensor states
110 uint8_t discreteReadingSensorStates; // discrete-only, optional states
111};
Tom Joseph816e92b2017-09-06 19:23:00 +0530112
Patrick Venture0b02be92018-08-31 11:55:55 -0700113using OffsetValueMap = std::map<Offset, Values>;
Ratan Gupta00659052017-02-23 17:29:08 +0530114
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500115using DbusPropertyValues = std::pair<PreReqOffsetValueMap, OffsetValueMap>;
Ratan Gupta00659052017-02-23 17:29:08 +0530116
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500117using DbusPropertyMap = std::map<DbusProperty, DbusPropertyValues>;
118
119using DbusInterfaceMap = std::map<DbusInterface, DbusPropertyMap>;
Ratan Gupta00659052017-02-23 17:29:08 +0530120
121using InstancePath = std::string;
122using Type = uint8_t;
123using ReadingType = uint8_t;
Emily Shaffer10f49592017-05-10 12:01:10 -0700124using Multiplier = uint16_t;
Tom Joseph0a1301c2018-02-16 08:27:00 +0530125using OffsetB = int16_t;
126using Exponent = int8_t;
Emily Shaffer40011912018-10-09 12:06:04 -0700127using ScaledOffset = double;
Emily Shaffer62235612017-06-14 13:06:26 -0700128using Scale = int16_t;
129using Unit = std::string;
Tom Josephb0adbcd2018-01-24 11:51:29 +0530130using EntityType = uint8_t;
131using EntityInst = uint8_t;
132using SensorName = std::string;
Ratan Gupta00659052017-02-23 17:29:08 +0530133
Emily Shaffercc941e12017-06-14 13:06:26 -0700134enum class Mutability
135{
Patrick Venture0b02be92018-08-31 11:55:55 -0700136 Read = 1 << 0,
137 Write = 1 << 1,
Emily Shaffercc941e12017-06-14 13:06:26 -0700138};
139
140inline Mutability operator|(Mutability lhs, Mutability rhs)
141{
Patrick Venture0b02be92018-08-31 11:55:55 -0700142 return static_cast<Mutability>(static_cast<uint8_t>(lhs) |
143 static_cast<uint8_t>(rhs));
Emily Shaffercc941e12017-06-14 13:06:26 -0700144}
145
146inline Mutability operator&(Mutability lhs, Mutability rhs)
147{
Patrick Venture0b02be92018-08-31 11:55:55 -0700148 return static_cast<Mutability>(static_cast<uint8_t>(lhs) &
149 static_cast<uint8_t>(rhs));
Emily Shaffercc941e12017-06-14 13:06:26 -0700150}
151
Ratan Gupta00659052017-02-23 17:29:08 +0530152struct Info
153{
Patrick Venture0b02be92018-08-31 11:55:55 -0700154 EntityType entityType;
155 EntityInst instance;
156 Type sensorType;
157 InstancePath sensorPath;
158 DbusInterface sensorInterface;
159 ReadingType sensorReadingType;
160 Multiplier coefficientM;
161 OffsetB coefficientB;
162 Exponent exponentB;
163 ScaledOffset scaledOffset;
164 Exponent exponentR;
165 bool hasScale;
166 Scale scale;
167 Unit unit;
168 std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
169 std::function<GetSensorResponse(const Info&)> getFunc;
170 Mutability mutability;
171 std::function<SensorName(const Info&)> sensorNameFunc;
172 DbusInterfaceMap propertyInterfaces;
Ratan Gupta00659052017-02-23 17:29:08 +0530173};
174
175using Id = uint8_t;
Patrick Venture0b02be92018-08-31 11:55:55 -0700176using IdInfoMap = std::map<Id, Info>;
Ratan Gupta00659052017-02-23 17:29:08 +0530177
Ratan Guptadcb10672017-07-10 10:33:50 +0530178using PropertyMap = ipmi::PropertyMap;
Tom Josephbe703f72017-03-09 12:34:35 +0530179
180using InterfaceMap = std::map<DbusInterface, PropertyMap>;
181
182using Object = sdbusplus::message::object_path;
183using ObjectMap = std::map<Object, InterfaceMap>;
184
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500185using IpmiUpdateData = sdbusplus::message::message;
186
Tom Josephdd78a1d2017-05-05 11:04:29 +0530187struct SelData
188{
Patrick Venture0b02be92018-08-31 11:55:55 -0700189 Id sensorID;
190 Type sensorType;
191 ReadingType eventReadingType;
192 Offset eventOffset;
Tom Josephdd78a1d2017-05-05 11:04:29 +0530193};
194
195using InventoryPath = std::string;
196
197using InvObjectIDMap = std::map<InventoryPath, SelData>;
198
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600199enum class ThresholdMask
200{
201 NON_CRITICAL_LOW_MASK = 0x01,
202 CRITICAL_LOW_MASK = 0x02,
203 NON_CRITICAL_HIGH_MASK = 0x08,
204 CRITICAL_HIGH_MASK = 0x10,
205};
206
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -0800207static constexpr uint8_t maxContainedEntities = 4;
208using ContainedEntitiesArray =
209 std::array<std::pair<uint8_t, uint8_t>, maxContainedEntities>;
210
211struct EntityInfo
212{
213 uint8_t containerEntityId;
214 uint8_t containerEntityInstance;
215 bool isList;
216 bool isLinked;
217 ContainedEntitiesArray containedEntities;
218};
219
220using EntityInfoMap = std::map<Id, EntityInfo>;
221
Patrick Venture0b02be92018-08-31 11:55:55 -0700222} // namespace sensor
Ratan Gupta8c31d232017-08-13 05:49:43 +0530223
224namespace network
225{
Ratan Gupta8c31d232017-08-13 05:49:43 +0530226constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
Ratan Gupta8c31d232017-08-13 05:49:43 +0530227
228constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
229constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;
230
231constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
232constexpr auto DEFAULT_ADDRESS = "0.0.0.0";
233
Patrick Venture0b02be92018-08-31 11:55:55 -0700234} // namespace network
William A. Kennington IIIc514d872019-04-06 18:19:38 -0700235
Patrick Venture0b02be92018-08-31 11:55:55 -0700236} // namespace ipmi