blob: b6bab94ad6a46dab4e6ddaedc2c44264e4d5ba7f [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
James Feist006d33c2018-06-15 11:36:27 -070019using Value = sdbusplus::message::variant<bool, uint8_t, int16_t, uint16_t,
20 int32_t, uint32_t, int64_t, uint64_t,
21 double, std::string>;
Ratan Guptacc8feb42017-07-25 21:52:10 +053022
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;
Tom Joseph0a1301c2018-02-16 08:27:00 +0530118using OffsetB = int16_t;
119using Exponent = int8_t;
Emily Shaffer10f49592017-05-10 12:01:10 -0700120using 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;
Tom Joseph0a1301c2018-02-16 08:27:00 +0530157 Exponent exponentR;
Emily Shaffer62235612017-06-14 13:06:26 -0700158 bool hasScale;
159 Scale scale;
160 Unit unit;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500161 std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
Tom Joseph9f9a9a42017-09-07 01:17:28 +0530162 std::function<GetSensorResponse(const Info&)> getFunc;
Emily Shaffercc941e12017-06-14 13:06:26 -0700163 Mutability mutability;
Tom Joseph31ff6e62018-01-24 16:10:09 +0530164 std::function<SensorName(const Info&)> sensorNameFunc;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500165 DbusInterfaceMap propertyInterfaces;
Ratan Gupta00659052017-02-23 17:29:08 +0530166};
167
168using Id = uint8_t;
169using IdInfoMap = std::map<Id,Info>;
170
Ratan Guptadcb10672017-07-10 10:33:50 +0530171using PropertyMap = ipmi::PropertyMap;
Tom Josephbe703f72017-03-09 12:34:35 +0530172
173using InterfaceMap = std::map<DbusInterface, PropertyMap>;
174
175using Object = sdbusplus::message::object_path;
176using ObjectMap = std::map<Object, InterfaceMap>;
177
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500178using IpmiUpdateData = sdbusplus::message::message;
179
Tom Josephdd78a1d2017-05-05 11:04:29 +0530180struct SelData
181{
182 Id sensorID;
183 Type sensorType;
184 ReadingType eventReadingType;
185 Offset eventOffset;
186};
187
188using InventoryPath = std::string;
189
190using InvObjectIDMap = std::map<InventoryPath, SelData>;
191
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600192enum class ThresholdMask
193{
194 NON_CRITICAL_LOW_MASK = 0x01,
195 CRITICAL_LOW_MASK = 0x02,
196 NON_CRITICAL_HIGH_MASK = 0x08,
197 CRITICAL_HIGH_MASK = 0x10,
198};
199
Ratan Gupta8c31d232017-08-13 05:49:43 +0530200}// namespace sensor
201
202namespace network
203{
Patrick Venturec01edf22017-12-22 14:03:06 -0800204using ChannelEthMap = std::map<int, std::string>;
Ratan Gupta8c31d232017-08-13 05:49:43 +0530205
206constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
207constexpr auto IP_ADDRESS_FORMAT = "%u.%u.%u.%u";
208constexpr auto PREFIX_FORMAT = "%hhd";
209constexpr auto ADDR_TYPE_FORMAT = "%hhx";
210
211constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
212constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;
213
214constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
215constexpr auto DEFAULT_ADDRESS = "0.0.0.0";
216
Ratan Guptab8e99552017-07-27 07:07:48 +0530217constexpr auto MAC_ADDRESS_SIZE_BYTE = 6;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530218constexpr auto VLAN_SIZE_BYTE = 2;
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530219constexpr auto IPSRC_SIZE_BYTE = 1;
Ratan Guptab8e99552017-07-27 07:07:48 +0530220constexpr auto BITS_32 = 32;
221constexpr auto MASK_32_BIT = 0xFFFFFFFF;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530222constexpr auto VLAN_ID_MASK = 0x00000FFF;
223constexpr auto VLAN_ENABLE_MASK = 0x8000;
Ratan Guptab8e99552017-07-27 07:07:48 +0530224
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530225enum class IPOrigin: uint8_t
226{
227 UNSPECIFIED = 0,
228 STATIC = 1,
229 DHCP = 2,
230};
231
232
Ratan Gupta8c31d232017-08-13 05:49:43 +0530233}//namespace network
Ratan Gupta00659052017-02-23 17:29:08 +0530234}//namespace ipmi