blob: 61f3d6857c69398aec5d44f7792d5b98ba98f962 [file] [log] [blame]
Ratan Gupta00659052017-02-23 17:29:08 +05301#pragma once
2
3#include <stdint.h>
4
5#include <map>
6#include <string>
7
8#include <sdbusplus/server.hpp>
9
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
19using Value = sdbusplus::message::variant<bool, uint8_t, int16_t,
20 uint16_t, int32_t, uint32_t,
21 int64_t, uint64_t, std::string>;
22
Ratan Guptadcb10672017-07-10 10:33:50 +053023using PropertyMap = std::map<DbusProperty, Value>;
Ratan Guptab8e99552017-07-27 07:07:48 +053024
Ratan Guptadcb10672017-07-10 10:33:50 +053025using ObjectTree = std::map<DbusObjectPath,
26 std::map<DbusService, std::vector<DbusInterface>>>;
Ratan Gupta8c31d232017-08-13 05:49:43 +053027
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053028using InterfaceList = std::vector<std::string>;
29
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -060030using DbusInterfaceMap = std::map<DbusInterface, PropertyMap>;
31
32using ObjectValueTree =
33 std::map<sdbusplus::message::object_path, DbusInterfaceMap>;
34
Ratan Gupta00659052017-02-23 17:29:08 +053035namespace sensor
36{
37
38using Offset = uint8_t;
Ratan Gupta00659052017-02-23 17:29:08 +053039
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -050040/**
41 * @enum SkipAssertion
42 * Matching value for skipping the update
43 */
44enum class SkipAssertion
45{
46 NONE, //No skip defined
47 ASSERT, //Skip on Assert
48 DEASSERT, //Skip on Deassert
49};
50
Ratan Gupta00659052017-02-23 17:29:08 +053051struct Values
52{
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -050053 SkipAssertion skip;
Ratan Gupta00659052017-02-23 17:29:08 +053054 Value assert;
55 Value deassert;
56};
57
Tom Joseph816e92b2017-09-06 19:23:00 +053058/**
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -050059 * @enum PreReqValues
60 * Pre-req conditions for a property.
61 */
62struct PreReqValues
63{
64 Value assert; //Value in case of assert.
65 Value deassert; //Value in case of deassert.
66};
67
68using PreReqOffsetValueMap = std::map<Offset, PreReqValues>;
69
70/**
Tom Joseph816e92b2017-09-06 19:23:00 +053071 * @struct SetSensorReadingReq
72 *
73 * IPMI Request data for Set Sensor Reading and Event Status Command
74 */
75struct SetSensorReadingReq
76{
77 uint8_t number;
78 uint8_t operation;
79 uint8_t reading;
80 uint8_t assertOffset0_7;
81 uint8_t assertOffset8_14;
82 uint8_t deassertOffset0_7;
83 uint8_t deassertOffset8_14;
84 uint8_t eventData1;
85 uint8_t eventData2;
86 uint8_t eventData3;
87} __attribute__((packed));
88
89/**
90 * @struct GetReadingResponse
91 *
92 * IPMI response data for Get Sensor Reading command.
93 */
94struct GetReadingResponse
95{
96 uint8_t reading; //!< Sensor reading.
97 uint8_t operation; //!< Sensor scanning status / reading state.
98 uint8_t assertOffset0_7; //!< Discrete assertion states(0-7).
99 uint8_t assertOffset8_14; //!< Discrete assertion states(8-14).
100} __attribute__((packed));
101
102constexpr auto inventoryRoot = "/xyz/openbmc_project/inventory";
103
104using GetSensorResponse = std::array<uint8_t, sizeof(GetReadingResponse)>;
105
Ratan Gupta00659052017-02-23 17:29:08 +0530106using OffsetValueMap = std::map<Offset,Values>;
107
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500108using DbusPropertyValues = std::pair<PreReqOffsetValueMap, OffsetValueMap>;
Ratan Gupta00659052017-02-23 17:29:08 +0530109
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500110using DbusPropertyMap = std::map<DbusProperty, DbusPropertyValues>;
111
112using DbusInterfaceMap = std::map<DbusInterface, DbusPropertyMap>;
Ratan Gupta00659052017-02-23 17:29:08 +0530113
114using InstancePath = std::string;
115using Type = uint8_t;
116using ReadingType = uint8_t;
Emily Shaffer10f49592017-05-10 12:01:10 -0700117using Multiplier = uint16_t;
118using OffsetB = uint16_t;
119using Exponent = uint8_t;
120using ScaledOffset = int64_t;
Emily Shaffer62235612017-06-14 13:06:26 -0700121using Scale = int16_t;
122using Unit = std::string;
Tom Josephb0adbcd2018-01-24 11:51:29 +0530123using EntityType = uint8_t;
124using EntityInst = uint8_t;
125using SensorName = std::string;
Ratan Gupta00659052017-02-23 17:29:08 +0530126
Emily Shaffercc941e12017-06-14 13:06:26 -0700127enum class Mutability
128{
129 Read = 1 << 0,
130 Write = 1 << 1,
131};
132
133inline Mutability operator|(Mutability lhs, Mutability rhs)
134{
135 return static_cast<Mutability>(
136 static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
137}
138
139inline Mutability operator&(Mutability lhs, Mutability rhs)
140{
141 return static_cast<Mutability>(
142 static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
143}
144
Ratan Gupta00659052017-02-23 17:29:08 +0530145struct Info
146{
Tom Joseph31ff6e62018-01-24 16:10:09 +0530147 EntityType entityType;
148 EntityInst instance;
Ratan Gupta00659052017-02-23 17:29:08 +0530149 Type sensorType;
150 InstancePath sensorPath;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500151 DbusInterface sensorInterface;
Ratan Gupta00659052017-02-23 17:29:08 +0530152 ReadingType sensorReadingType;
Emily Shaffer10f49592017-05-10 12:01:10 -0700153 Multiplier coefficientM;
154 OffsetB coefficientB;
155 Exponent exponentB;
156 ScaledOffset scaledOffset;
Emily Shaffer62235612017-06-14 13:06:26 -0700157 bool hasScale;
158 Scale scale;
159 Unit unit;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500160 std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
Tom Joseph9f9a9a42017-09-07 01:17:28 +0530161 std::function<GetSensorResponse(const Info&)> getFunc;
Emily Shaffercc941e12017-06-14 13:06:26 -0700162 Mutability mutability;
Tom Joseph31ff6e62018-01-24 16:10:09 +0530163 std::function<SensorName(const Info&)> sensorNameFunc;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500164 DbusInterfaceMap propertyInterfaces;
Ratan Gupta00659052017-02-23 17:29:08 +0530165};
166
167using Id = uint8_t;
168using IdInfoMap = std::map<Id,Info>;
169
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{
181 Id sensorID;
182 Type sensorType;
183 ReadingType eventReadingType;
184 Offset eventOffset;
185};
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
199enum class ThresholdIndex
200{
201 NON_CRITICAL_LOW_IDX = 0,
202 CRITICAL_LOW_IDX = 1,
203 NON_RECOVERABLE_LOW_IDX = 2,
204 NON_CRITICAL_HIGH_IDX = 3,
205 CRITICAL_HIGH_IDX = 4,
206 NON_RECOVERABLE_HIGH_IDX = 5,
207};
208
209struct ThresholdLevel
210{
211 std::string property;
212 ThresholdMask maskValue;
213 ThresholdIndex idx;
214};
215
216using SensorThresholds = std::vector<ThresholdLevel>;
217using Thresholds = std::map<std::string, SensorThresholds>;
218
Ratan Gupta8c31d232017-08-13 05:49:43 +0530219}// namespace sensor
220
221namespace network
222{
Patrick Venturec01edf22017-12-22 14:03:06 -0800223using ChannelEthMap = std::map<int, std::string>;
Ratan Gupta8c31d232017-08-13 05:49:43 +0530224
225constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
226constexpr auto IP_ADDRESS_FORMAT = "%u.%u.%u.%u";
227constexpr auto PREFIX_FORMAT = "%hhd";
228constexpr auto ADDR_TYPE_FORMAT = "%hhx";
229
230constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
231constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;
232
233constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
234constexpr auto DEFAULT_ADDRESS = "0.0.0.0";
235
Ratan Guptab8e99552017-07-27 07:07:48 +0530236constexpr auto MAC_ADDRESS_SIZE_BYTE = 6;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530237constexpr auto VLAN_SIZE_BYTE = 2;
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530238constexpr auto IPSRC_SIZE_BYTE = 1;
Ratan Guptab8e99552017-07-27 07:07:48 +0530239constexpr auto BITS_32 = 32;
240constexpr auto MASK_32_BIT = 0xFFFFFFFF;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530241constexpr auto VLAN_ID_MASK = 0x00000FFF;
242constexpr auto VLAN_ENABLE_MASK = 0x8000;
Ratan Guptab8e99552017-07-27 07:07:48 +0530243
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530244enum class IPOrigin: uint8_t
245{
246 UNSPECIFIED = 0,
247 STATIC = 1,
248 DHCP = 2,
249};
250
251
Ratan Gupta8c31d232017-08-13 05:49:43 +0530252}//namespace network
Ratan Gupta00659052017-02-23 17:29:08 +0530253}//namespace ipmi