blob: 258006309f3b77fb9cbaa099afa1e903edda616d [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{
142 Type sensorType;
143 InstancePath sensorPath;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500144 DbusInterface sensorInterface;
Ratan Gupta00659052017-02-23 17:29:08 +0530145 ReadingType sensorReadingType;
Emily Shaffer10f49592017-05-10 12:01:10 -0700146 Multiplier coefficientM;
147 OffsetB coefficientB;
148 Exponent exponentB;
149 ScaledOffset scaledOffset;
Emily Shaffer62235612017-06-14 13:06:26 -0700150 bool hasScale;
151 Scale scale;
152 Unit unit;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500153 std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
Tom Joseph9f9a9a42017-09-07 01:17:28 +0530154 std::function<GetSensorResponse(const Info&)> getFunc;
Emily Shaffercc941e12017-06-14 13:06:26 -0700155 Mutability mutability;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500156 DbusInterfaceMap propertyInterfaces;
Ratan Gupta00659052017-02-23 17:29:08 +0530157};
158
159using Id = uint8_t;
160using IdInfoMap = std::map<Id,Info>;
161
Ratan Guptadcb10672017-07-10 10:33:50 +0530162using PropertyMap = ipmi::PropertyMap;
Tom Josephbe703f72017-03-09 12:34:35 +0530163
164using InterfaceMap = std::map<DbusInterface, PropertyMap>;
165
166using Object = sdbusplus::message::object_path;
167using ObjectMap = std::map<Object, InterfaceMap>;
168
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500169using IpmiUpdateData = sdbusplus::message::message;
170
Tom Josephdd78a1d2017-05-05 11:04:29 +0530171struct SelData
172{
173 Id sensorID;
174 Type sensorType;
175 ReadingType eventReadingType;
176 Offset eventOffset;
177};
178
179using InventoryPath = std::string;
180
181using InvObjectIDMap = std::map<InventoryPath, SelData>;
182
Ratan Gupta8c31d232017-08-13 05:49:43 +0530183}// namespace sensor
184
185namespace network
186{
Patrick Venturec01edf22017-12-22 14:03:06 -0800187using ChannelEthMap = std::map<int, std::string>;
Ratan Gupta8c31d232017-08-13 05:49:43 +0530188
189constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
190constexpr auto IP_ADDRESS_FORMAT = "%u.%u.%u.%u";
191constexpr auto PREFIX_FORMAT = "%hhd";
192constexpr auto ADDR_TYPE_FORMAT = "%hhx";
193
194constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
195constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;
196
197constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
198constexpr auto DEFAULT_ADDRESS = "0.0.0.0";
199
Ratan Guptab8e99552017-07-27 07:07:48 +0530200constexpr auto MAC_ADDRESS_SIZE_BYTE = 6;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530201constexpr auto VLAN_SIZE_BYTE = 2;
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530202constexpr auto IPSRC_SIZE_BYTE = 1;
Ratan Guptab8e99552017-07-27 07:07:48 +0530203constexpr auto BITS_32 = 32;
204constexpr auto MASK_32_BIT = 0xFFFFFFFF;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530205constexpr auto VLAN_ID_MASK = 0x00000FFF;
206constexpr auto VLAN_ENABLE_MASK = 0x8000;
Ratan Guptab8e99552017-07-27 07:07:48 +0530207
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530208enum class IPOrigin: uint8_t
209{
210 UNSPECIFIED = 0,
211 STATIC = 1,
212 DHCP = 2,
213};
214
215
Ratan Gupta8c31d232017-08-13 05:49:43 +0530216}//namespace network
Ratan Gupta00659052017-02-23 17:29:08 +0530217}//namespace ipmi