blob: 431d5b6adfdf114f5eb3b9afa920405c9992d923 [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>
Ratan Gupta00659052017-02-23 17:29:08 +05308
9namespace ipmi
10{
Ratan Guptadcb10672017-07-10 10:33:50 +053011
12using DbusObjectPath = std::string;
13using DbusService = std::string;
14using DbusInterface = std::string;
15using DbusObjectInfo = std::pair<DbusObjectPath, DbusService>;
16using DbusProperty = std::string;
Ratan Guptacc8feb42017-07-25 21:52:10 +053017
James Feist006d33c2018-06-15 11:36:27 -070018using Value = sdbusplus::message::variant<bool, uint8_t, int16_t, uint16_t,
19 int32_t, uint32_t, int64_t, uint64_t,
20 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
103using GetSensorResponse = std::array<uint8_t, sizeof(GetReadingResponse)>;
104
Patrick Venture0b02be92018-08-31 11:55:55 -0700105using OffsetValueMap = std::map<Offset, Values>;
Ratan Gupta00659052017-02-23 17:29:08 +0530106
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500107using DbusPropertyValues = std::pair<PreReqOffsetValueMap, OffsetValueMap>;
Ratan Gupta00659052017-02-23 17:29:08 +0530108
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500109using DbusPropertyMap = std::map<DbusProperty, DbusPropertyValues>;
110
111using DbusInterfaceMap = std::map<DbusInterface, DbusPropertyMap>;
Ratan Gupta00659052017-02-23 17:29:08 +0530112
113using InstancePath = std::string;
114using Type = uint8_t;
115using ReadingType = uint8_t;
Emily Shaffer10f49592017-05-10 12:01:10 -0700116using Multiplier = uint16_t;
Tom Joseph0a1301c2018-02-16 08:27:00 +0530117using OffsetB = int16_t;
118using Exponent = int8_t;
Emily Shaffer10f49592017-05-10 12:01:10 -0700119using ScaledOffset = int64_t;
Emily Shaffer62235612017-06-14 13:06:26 -0700120using Scale = int16_t;
121using Unit = std::string;
Tom Josephb0adbcd2018-01-24 11:51:29 +0530122using EntityType = uint8_t;
123using EntityInst = uint8_t;
124using SensorName = std::string;
Ratan Gupta00659052017-02-23 17:29:08 +0530125
Emily Shaffercc941e12017-06-14 13:06:26 -0700126enum class Mutability
127{
Patrick Venture0b02be92018-08-31 11:55:55 -0700128 Read = 1 << 0,
129 Write = 1 << 1,
Emily Shaffercc941e12017-06-14 13:06:26 -0700130};
131
132inline Mutability operator|(Mutability lhs, Mutability rhs)
133{
Patrick Venture0b02be92018-08-31 11:55:55 -0700134 return static_cast<Mutability>(static_cast<uint8_t>(lhs) |
135 static_cast<uint8_t>(rhs));
Emily Shaffercc941e12017-06-14 13:06:26 -0700136}
137
138inline Mutability operator&(Mutability lhs, Mutability rhs)
139{
Patrick Venture0b02be92018-08-31 11:55:55 -0700140 return static_cast<Mutability>(static_cast<uint8_t>(lhs) &
141 static_cast<uint8_t>(rhs));
Emily Shaffercc941e12017-06-14 13:06:26 -0700142}
143
Ratan Gupta00659052017-02-23 17:29:08 +0530144struct Info
145{
Patrick Venture0b02be92018-08-31 11:55:55 -0700146 EntityType entityType;
147 EntityInst instance;
148 Type sensorType;
149 InstancePath sensorPath;
150 DbusInterface sensorInterface;
151 ReadingType sensorReadingType;
152 Multiplier coefficientM;
153 OffsetB coefficientB;
154 Exponent exponentB;
155 ScaledOffset scaledOffset;
156 Exponent exponentR;
157 bool hasScale;
158 Scale scale;
159 Unit unit;
160 std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
161 std::function<GetSensorResponse(const Info&)> getFunc;
162 Mutability mutability;
163 std::function<SensorName(const Info&)> sensorNameFunc;
164 DbusInterfaceMap propertyInterfaces;
Ratan Gupta00659052017-02-23 17:29:08 +0530165};
166
167using Id = uint8_t;
Patrick Venture0b02be92018-08-31 11:55:55 -0700168using IdInfoMap = std::map<Id, Info>;
Ratan Gupta00659052017-02-23 17:29:08 +0530169
Ratan Guptadcb10672017-07-10 10:33:50 +0530170using PropertyMap = ipmi::PropertyMap;
Tom Josephbe703f72017-03-09 12:34:35 +0530171
172using InterfaceMap = std::map<DbusInterface, PropertyMap>;
173
174using Object = sdbusplus::message::object_path;
175using ObjectMap = std::map<Object, InterfaceMap>;
176
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500177using IpmiUpdateData = sdbusplus::message::message;
178
Tom Josephdd78a1d2017-05-05 11:04:29 +0530179struct SelData
180{
Patrick Venture0b02be92018-08-31 11:55:55 -0700181 Id sensorID;
182 Type sensorType;
183 ReadingType eventReadingType;
184 Offset eventOffset;
Tom Josephdd78a1d2017-05-05 11:04:29 +0530185};
186
187using InventoryPath = std::string;
188
189using InvObjectIDMap = std::map<InventoryPath, SelData>;
190
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600191enum class ThresholdMask
192{
193 NON_CRITICAL_LOW_MASK = 0x01,
194 CRITICAL_LOW_MASK = 0x02,
195 NON_CRITICAL_HIGH_MASK = 0x08,
196 CRITICAL_HIGH_MASK = 0x10,
197};
198
Patrick Venture0b02be92018-08-31 11:55:55 -0700199} // namespace sensor
Ratan Gupta8c31d232017-08-13 05:49:43 +0530200
201namespace network
202{
Patrick Venturec01edf22017-12-22 14:03:06 -0800203using ChannelEthMap = std::map<int, std::string>;
Ratan Gupta8c31d232017-08-13 05:49:43 +0530204
205constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
206constexpr auto IP_ADDRESS_FORMAT = "%u.%u.%u.%u";
207constexpr auto PREFIX_FORMAT = "%hhd";
208constexpr auto ADDR_TYPE_FORMAT = "%hhx";
209
210constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
211constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;
212
213constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
214constexpr auto DEFAULT_ADDRESS = "0.0.0.0";
215
Ratan Guptab8e99552017-07-27 07:07:48 +0530216constexpr auto MAC_ADDRESS_SIZE_BYTE = 6;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530217constexpr auto VLAN_SIZE_BYTE = 2;
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530218constexpr auto IPSRC_SIZE_BYTE = 1;
Ratan Guptab8e99552017-07-27 07:07:48 +0530219constexpr auto BITS_32 = 32;
220constexpr auto MASK_32_BIT = 0xFFFFFFFF;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530221constexpr auto VLAN_ID_MASK = 0x00000FFF;
222constexpr auto VLAN_ENABLE_MASK = 0x8000;
Ratan Guptab8e99552017-07-27 07:07:48 +0530223
Patrick Venture0b02be92018-08-31 11:55:55 -0700224enum class IPOrigin : uint8_t
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530225{
226 UNSPECIFIED = 0,
227 STATIC = 1,
228 DHCP = 2,
229};
230
Patrick Venture0b02be92018-08-31 11:55:55 -0700231} // namespace network
232} // namespace ipmi