blob: e62c8192032fbc80040907635f114526734a2e52 [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
Willy Tude54f482021-01-26 15:59:09 -080019using Association = std::tuple<std::string, std::string, std::string>;
20
21using Value =
22 std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t,
23 uint64_t, double, std::string, std::vector<Association>>;
Ratan Guptacc8feb42017-07-25 21:52:10 +053024
Ratan Guptadcb10672017-07-10 10:33:50 +053025using PropertyMap = std::map<DbusProperty, Value>;
Ratan Guptab8e99552017-07-27 07:07:48 +053026
Patrick Venture0b02be92018-08-31 11:55:55 -070027using ObjectTree =
28 std::map<DbusObjectPath, std::map<DbusService, std::vector<DbusInterface>>>;
Ratan Gupta8c31d232017-08-13 05:49:43 +053029
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053030using InterfaceList = std::vector<std::string>;
31
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -060032using DbusInterfaceMap = std::map<DbusInterface, PropertyMap>;
33
34using ObjectValueTree =
35 std::map<sdbusplus::message::object_path, DbusInterfaceMap>;
36
Ratan Gupta00659052017-02-23 17:29:08 +053037namespace sensor
38{
39
40using Offset = uint8_t;
Ratan Gupta00659052017-02-23 17:29:08 +053041
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -050042/**
43 * @enum SkipAssertion
44 * Matching value for skipping the update
45 */
46enum class SkipAssertion
47{
Patrick Venture0b02be92018-08-31 11:55:55 -070048 NONE, // No skip defined
49 ASSERT, // Skip on Assert
50 DEASSERT, // Skip on Deassert
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -050051};
52
Ratan Gupta00659052017-02-23 17:29:08 +053053struct Values
54{
Patrick Venture0b02be92018-08-31 11:55:55 -070055 SkipAssertion skip;
56 Value assert;
57 Value deassert;
Ratan Gupta00659052017-02-23 17:29:08 +053058};
59
Tom Joseph816e92b2017-09-06 19:23:00 +053060/**
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -050061 * @enum PreReqValues
62 * Pre-req conditions for a property.
63 */
64struct PreReqValues
65{
Patrick Venture0b02be92018-08-31 11:55:55 -070066 Value assert; // Value in case of assert.
67 Value deassert; // Value in case of deassert.
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -050068};
69
70using PreReqOffsetValueMap = std::map<Offset, PreReqValues>;
71
72/**
Tom Joseph816e92b2017-09-06 19:23:00 +053073 * @struct SetSensorReadingReq
74 *
75 * IPMI Request data for Set Sensor Reading and Event Status Command
76 */
77struct SetSensorReadingReq
78{
79 uint8_t number;
80 uint8_t operation;
81 uint8_t reading;
82 uint8_t assertOffset0_7;
83 uint8_t assertOffset8_14;
84 uint8_t deassertOffset0_7;
85 uint8_t deassertOffset8_14;
86 uint8_t eventData1;
87 uint8_t eventData2;
88 uint8_t eventData3;
89} __attribute__((packed));
90
91/**
92 * @struct GetReadingResponse
93 *
94 * IPMI response data for Get Sensor Reading command.
95 */
96struct GetReadingResponse
97{
Patrick Venture0b02be92018-08-31 11:55:55 -070098 uint8_t reading; //!< Sensor reading.
99 uint8_t operation; //!< Sensor scanning status / reading state.
100 uint8_t assertOffset0_7; //!< Discrete assertion states(0-7).
101 uint8_t assertOffset8_14; //!< Discrete assertion states(8-14).
Tom Joseph816e92b2017-09-06 19:23:00 +0530102} __attribute__((packed));
103
104constexpr auto inventoryRoot = "/xyz/openbmc_project/inventory";
105
Sui Chen4cc42552019-09-11 10:28:35 -0700106struct GetSensorResponse
107{
108 uint8_t reading; // sensor reading
109 bool readingOrStateUnavailable; // 1 = reading/state unavailable
110 bool scanningEnabled; // 0 = sensor scanning disabled
111 bool allEventMessagesEnabled; // 0 = All Event Messages disabled
112 uint8_t thresholdLevelsStates; // threshold/discrete sensor states
113 uint8_t discreteReadingSensorStates; // discrete-only, optional states
114};
Tom Joseph816e92b2017-09-06 19:23:00 +0530115
Patrick Venture0b02be92018-08-31 11:55:55 -0700116using OffsetValueMap = std::map<Offset, Values>;
Ratan Gupta00659052017-02-23 17:29:08 +0530117
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500118using DbusPropertyValues = std::pair<PreReqOffsetValueMap, OffsetValueMap>;
Ratan Gupta00659052017-02-23 17:29:08 +0530119
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500120using DbusPropertyMap = std::map<DbusProperty, DbusPropertyValues>;
121
122using DbusInterfaceMap = std::map<DbusInterface, DbusPropertyMap>;
Ratan Gupta00659052017-02-23 17:29:08 +0530123
124using InstancePath = std::string;
125using Type = uint8_t;
126using ReadingType = uint8_t;
Emily Shaffer10f49592017-05-10 12:01:10 -0700127using Multiplier = uint16_t;
Tom Joseph0a1301c2018-02-16 08:27:00 +0530128using OffsetB = int16_t;
129using Exponent = int8_t;
Emily Shaffer40011912018-10-09 12:06:04 -0700130using ScaledOffset = double;
Emily Shaffer62235612017-06-14 13:06:26 -0700131using Scale = int16_t;
132using Unit = std::string;
Tom Josephb0adbcd2018-01-24 11:51:29 +0530133using EntityType = uint8_t;
134using EntityInst = uint8_t;
135using SensorName = std::string;
Ratan Gupta00659052017-02-23 17:29:08 +0530136
Emily Shaffercc941e12017-06-14 13:06:26 -0700137enum class Mutability
138{
Patrick Venture0b02be92018-08-31 11:55:55 -0700139 Read = 1 << 0,
140 Write = 1 << 1,
Emily Shaffercc941e12017-06-14 13:06:26 -0700141};
142
143inline Mutability operator|(Mutability lhs, Mutability rhs)
144{
Patrick Venture0b02be92018-08-31 11:55:55 -0700145 return static_cast<Mutability>(static_cast<uint8_t>(lhs) |
146 static_cast<uint8_t>(rhs));
Emily Shaffercc941e12017-06-14 13:06:26 -0700147}
148
149inline Mutability operator&(Mutability lhs, Mutability rhs)
150{
Patrick Venture0b02be92018-08-31 11:55:55 -0700151 return static_cast<Mutability>(static_cast<uint8_t>(lhs) &
152 static_cast<uint8_t>(rhs));
Emily Shaffercc941e12017-06-14 13:06:26 -0700153}
154
Ratan Gupta00659052017-02-23 17:29:08 +0530155struct Info
156{
Patrick Venture0b02be92018-08-31 11:55:55 -0700157 EntityType entityType;
158 EntityInst instance;
159 Type sensorType;
160 InstancePath sensorPath;
161 DbusInterface sensorInterface;
162 ReadingType sensorReadingType;
163 Multiplier coefficientM;
164 OffsetB coefficientB;
165 Exponent exponentB;
166 ScaledOffset scaledOffset;
167 Exponent exponentR;
168 bool hasScale;
169 Scale scale;
170 Unit unit;
171 std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
172 std::function<GetSensorResponse(const Info&)> getFunc;
173 Mutability mutability;
Jeremy Kerrbe4ffa82020-08-10 16:17:37 +0800174 SensorName sensorName;
Patrick Venture0b02be92018-08-31 11:55:55 -0700175 std::function<SensorName(const Info&)> sensorNameFunc;
176 DbusInterfaceMap propertyInterfaces;
Ratan Gupta00659052017-02-23 17:29:08 +0530177};
178
179using Id = uint8_t;
Patrick Venture0b02be92018-08-31 11:55:55 -0700180using IdInfoMap = std::map<Id, Info>;
Ratan Gupta00659052017-02-23 17:29:08 +0530181
Ratan Guptadcb10672017-07-10 10:33:50 +0530182using PropertyMap = ipmi::PropertyMap;
Tom Josephbe703f72017-03-09 12:34:35 +0530183
184using InterfaceMap = std::map<DbusInterface, PropertyMap>;
185
186using Object = sdbusplus::message::object_path;
187using ObjectMap = std::map<Object, InterfaceMap>;
188
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500189using IpmiUpdateData = sdbusplus::message::message;
190
Tom Josephdd78a1d2017-05-05 11:04:29 +0530191struct SelData
192{
Patrick Venture0b02be92018-08-31 11:55:55 -0700193 Id sensorID;
194 Type sensorType;
195 ReadingType eventReadingType;
196 Offset eventOffset;
Tom Josephdd78a1d2017-05-05 11:04:29 +0530197};
198
199using InventoryPath = std::string;
200
201using InvObjectIDMap = std::map<InventoryPath, SelData>;
202
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600203enum class ThresholdMask
204{
205 NON_CRITICAL_LOW_MASK = 0x01,
206 CRITICAL_LOW_MASK = 0x02,
207 NON_CRITICAL_HIGH_MASK = 0x08,
208 CRITICAL_HIGH_MASK = 0x10,
209};
210
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -0800211static constexpr uint8_t maxContainedEntities = 4;
212using ContainedEntitiesArray =
213 std::array<std::pair<uint8_t, uint8_t>, maxContainedEntities>;
214
215struct EntityInfo
216{
217 uint8_t containerEntityId;
218 uint8_t containerEntityInstance;
219 bool isList;
220 bool isLinked;
221 ContainedEntitiesArray containedEntities;
222};
223
224using EntityInfoMap = std::map<Id, EntityInfo>;
225
Patrick Venture0b02be92018-08-31 11:55:55 -0700226} // namespace sensor
Ratan Gupta8c31d232017-08-13 05:49:43 +0530227
228namespace network
229{
Ratan Gupta8c31d232017-08-13 05:49:43 +0530230constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
Ratan Gupta8c31d232017-08-13 05:49:43 +0530231
232constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
233constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;
234
235constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
236constexpr auto DEFAULT_ADDRESS = "0.0.0.0";
237
Patrick Venture0b02be92018-08-31 11:55:55 -0700238} // namespace network
William A. Kennington IIIc514d872019-04-06 18:19:38 -0700239
Patrick Venture0b02be92018-08-31 11:55:55 -0700240} // namespace ipmi