blob: 260deb57cdb773fda65fd7b067dd26b57ecc4004 [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
Ratan Gupta00659052017-02-23 17:29:08 +053030namespace sensor
31{
32
33using Offset = uint8_t;
Ratan Gupta00659052017-02-23 17:29:08 +053034
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -050035/**
36 * @enum SkipAssertion
37 * Matching value for skipping the update
38 */
39enum class SkipAssertion
40{
41 NONE, //No skip defined
42 ASSERT, //Skip on Assert
43 DEASSERT, //Skip on Deassert
44};
45
Ratan Gupta00659052017-02-23 17:29:08 +053046struct Values
47{
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -050048 SkipAssertion skip;
Ratan Gupta00659052017-02-23 17:29:08 +053049 Value assert;
50 Value deassert;
51};
52
Tom Joseph816e92b2017-09-06 19:23:00 +053053/**
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -050054 * @enum PreReqValues
55 * Pre-req conditions for a property.
56 */
57struct PreReqValues
58{
59 Value assert; //Value in case of assert.
60 Value deassert; //Value in case of deassert.
61};
62
63using PreReqOffsetValueMap = std::map<Offset, PreReqValues>;
64
65/**
Tom Joseph816e92b2017-09-06 19:23:00 +053066 * @struct SetSensorReadingReq
67 *
68 * IPMI Request data for Set Sensor Reading and Event Status Command
69 */
70struct SetSensorReadingReq
71{
72 uint8_t number;
73 uint8_t operation;
74 uint8_t reading;
75 uint8_t assertOffset0_7;
76 uint8_t assertOffset8_14;
77 uint8_t deassertOffset0_7;
78 uint8_t deassertOffset8_14;
79 uint8_t eventData1;
80 uint8_t eventData2;
81 uint8_t eventData3;
82} __attribute__((packed));
83
84/**
85 * @struct GetReadingResponse
86 *
87 * IPMI response data for Get Sensor Reading command.
88 */
89struct GetReadingResponse
90{
91 uint8_t reading; //!< Sensor reading.
92 uint8_t operation; //!< Sensor scanning status / reading state.
93 uint8_t assertOffset0_7; //!< Discrete assertion states(0-7).
94 uint8_t assertOffset8_14; //!< Discrete assertion states(8-14).
95} __attribute__((packed));
96
97constexpr auto inventoryRoot = "/xyz/openbmc_project/inventory";
98
99using GetSensorResponse = std::array<uint8_t, sizeof(GetReadingResponse)>;
100
Ratan Gupta00659052017-02-23 17:29:08 +0530101using OffsetValueMap = std::map<Offset,Values>;
102
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500103using DbusPropertyValues = std::pair<PreReqOffsetValueMap, OffsetValueMap>;
Ratan Gupta00659052017-02-23 17:29:08 +0530104
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500105using DbusPropertyMap = std::map<DbusProperty, DbusPropertyValues>;
106
107using DbusInterfaceMap = std::map<DbusInterface, DbusPropertyMap>;
Ratan Gupta00659052017-02-23 17:29:08 +0530108
109using InstancePath = std::string;
110using Type = uint8_t;
111using ReadingType = uint8_t;
Emily Shaffer10f49592017-05-10 12:01:10 -0700112using Multiplier = uint16_t;
113using OffsetB = uint16_t;
114using Exponent = uint8_t;
115using ScaledOffset = int64_t;
Emily Shaffer62235612017-06-14 13:06:26 -0700116using Scale = int16_t;
117using Unit = std::string;
Tom Josephb0adbcd2018-01-24 11:51:29 +0530118using EntityType = uint8_t;
119using EntityInst = uint8_t;
120using SensorName = std::string;
Ratan Gupta00659052017-02-23 17:29:08 +0530121
Emily Shaffercc941e12017-06-14 13:06:26 -0700122enum class Mutability
123{
124 Read = 1 << 0,
125 Write = 1 << 1,
126};
127
128inline Mutability operator|(Mutability lhs, Mutability rhs)
129{
130 return static_cast<Mutability>(
131 static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
132}
133
134inline Mutability operator&(Mutability lhs, Mutability rhs)
135{
136 return static_cast<Mutability>(
137 static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
138}
139
Ratan Gupta00659052017-02-23 17:29:08 +0530140struct Info
141{
Tom Joseph31ff6e62018-01-24 16:10:09 +0530142 EntityType entityType;
143 EntityInst instance;
Ratan Gupta00659052017-02-23 17:29:08 +0530144 Type sensorType;
145 InstancePath sensorPath;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500146 DbusInterface sensorInterface;
Ratan Gupta00659052017-02-23 17:29:08 +0530147 ReadingType sensorReadingType;
Emily Shaffer10f49592017-05-10 12:01:10 -0700148 Multiplier coefficientM;
149 OffsetB coefficientB;
150 Exponent exponentB;
151 ScaledOffset scaledOffset;
Emily Shaffer62235612017-06-14 13:06:26 -0700152 bool hasScale;
153 Scale scale;
154 Unit unit;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500155 std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
Tom Joseph9f9a9a42017-09-07 01:17:28 +0530156 std::function<GetSensorResponse(const Info&)> getFunc;
Emily Shaffercc941e12017-06-14 13:06:26 -0700157 Mutability mutability;
Tom Joseph31ff6e62018-01-24 16:10:09 +0530158 std::function<SensorName(const Info&)> sensorNameFunc;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500159 DbusInterfaceMap propertyInterfaces;
Ratan Gupta00659052017-02-23 17:29:08 +0530160};
161
162using Id = uint8_t;
163using IdInfoMap = std::map<Id,Info>;
164
Ratan Guptadcb10672017-07-10 10:33:50 +0530165using PropertyMap = ipmi::PropertyMap;
Tom Josephbe703f72017-03-09 12:34:35 +0530166
167using InterfaceMap = std::map<DbusInterface, PropertyMap>;
168
169using Object = sdbusplus::message::object_path;
170using ObjectMap = std::map<Object, InterfaceMap>;
171
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500172using IpmiUpdateData = sdbusplus::message::message;
173
Tom Josephdd78a1d2017-05-05 11:04:29 +0530174struct SelData
175{
176 Id sensorID;
177 Type sensorType;
178 ReadingType eventReadingType;
179 Offset eventOffset;
180};
181
182using InventoryPath = std::string;
183
184using InvObjectIDMap = std::map<InventoryPath, SelData>;
185
Ratan Gupta8c31d232017-08-13 05:49:43 +0530186}// namespace sensor
187
188namespace network
189{
Patrick Venturec01edf22017-12-22 14:03:06 -0800190using ChannelEthMap = std::map<int, std::string>;
Ratan Gupta8c31d232017-08-13 05:49:43 +0530191
192constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
193constexpr auto IP_ADDRESS_FORMAT = "%u.%u.%u.%u";
194constexpr auto PREFIX_FORMAT = "%hhd";
195constexpr auto ADDR_TYPE_FORMAT = "%hhx";
196
197constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
198constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;
199
200constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
201constexpr auto DEFAULT_ADDRESS = "0.0.0.0";
202
Ratan Guptab8e99552017-07-27 07:07:48 +0530203constexpr auto MAC_ADDRESS_SIZE_BYTE = 6;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530204constexpr auto VLAN_SIZE_BYTE = 2;
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530205constexpr auto IPSRC_SIZE_BYTE = 1;
Ratan Guptab8e99552017-07-27 07:07:48 +0530206constexpr auto BITS_32 = 32;
207constexpr auto MASK_32_BIT = 0xFFFFFFFF;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530208constexpr auto VLAN_ID_MASK = 0x00000FFF;
209constexpr auto VLAN_ENABLE_MASK = 0x8000;
Ratan Guptab8e99552017-07-27 07:07:48 +0530210
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530211enum class IPOrigin: uint8_t
212{
213 UNSPECIFIED = 0,
214 STATIC = 1,
215 DHCP = 2,
216};
217
218
Ratan Gupta8c31d232017-08-13 05:49:43 +0530219}//namespace network
Ratan Gupta00659052017-02-23 17:29:08 +0530220}//namespace ipmi