blob: 0177c8f73efcff1edf8a8f1afc9695eb96b791ca [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;
Ratan Gupta00659052017-02-23 17:29:08 +0530116
Emily Shaffercc941e12017-06-14 13:06:26 -0700117enum class Mutability
118{
119 Read = 1 << 0,
120 Write = 1 << 1,
121};
122
123inline Mutability operator|(Mutability lhs, Mutability rhs)
124{
125 return static_cast<Mutability>(
126 static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
127}
128
129inline Mutability operator&(Mutability lhs, Mutability rhs)
130{
131 return static_cast<Mutability>(
132 static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
133}
134
Ratan Gupta00659052017-02-23 17:29:08 +0530135struct Info
136{
137 Type sensorType;
138 InstancePath sensorPath;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500139 DbusInterface sensorInterface;
Ratan Gupta00659052017-02-23 17:29:08 +0530140 ReadingType sensorReadingType;
Emily Shaffer10f49592017-05-10 12:01:10 -0700141 Multiplier coefficientM;
142 OffsetB coefficientB;
143 Exponent exponentB;
144 ScaledOffset scaledOffset;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500145 std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
Tom Joseph9f9a9a42017-09-07 01:17:28 +0530146 std::function<GetSensorResponse(const Info&)> getFunc;
Emily Shaffercc941e12017-06-14 13:06:26 -0700147 Mutability mutability;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500148 DbusInterfaceMap propertyInterfaces;
Ratan Gupta00659052017-02-23 17:29:08 +0530149};
150
151using Id = uint8_t;
152using IdInfoMap = std::map<Id,Info>;
153
Ratan Guptadcb10672017-07-10 10:33:50 +0530154using PropertyMap = ipmi::PropertyMap;
Tom Josephbe703f72017-03-09 12:34:35 +0530155
156using InterfaceMap = std::map<DbusInterface, PropertyMap>;
157
158using Object = sdbusplus::message::object_path;
159using ObjectMap = std::map<Object, InterfaceMap>;
160
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500161using IpmiUpdateData = sdbusplus::message::message;
162
Tom Josephdd78a1d2017-05-05 11:04:29 +0530163struct SelData
164{
165 Id sensorID;
166 Type sensorType;
167 ReadingType eventReadingType;
168 Offset eventOffset;
169};
170
171using InventoryPath = std::string;
172
173using InvObjectIDMap = std::map<InventoryPath, SelData>;
174
Ratan Gupta8c31d232017-08-13 05:49:43 +0530175}// namespace sensor
176
177namespace network
178{
179
180constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
181constexpr auto IP_ADDRESS_FORMAT = "%u.%u.%u.%u";
182constexpr auto PREFIX_FORMAT = "%hhd";
183constexpr auto ADDR_TYPE_FORMAT = "%hhx";
184
185constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
186constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;
187
188constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
189constexpr auto DEFAULT_ADDRESS = "0.0.0.0";
190
Ratan Guptab8e99552017-07-27 07:07:48 +0530191constexpr auto MAC_ADDRESS_SIZE_BYTE = 6;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530192constexpr auto VLAN_SIZE_BYTE = 2;
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530193constexpr auto IPSRC_SIZE_BYTE = 1;
Ratan Guptab8e99552017-07-27 07:07:48 +0530194constexpr auto BITS_32 = 32;
195constexpr auto MASK_32_BIT = 0xFFFFFFFF;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530196constexpr auto VLAN_ID_MASK = 0x00000FFF;
197constexpr auto VLAN_ENABLE_MASK = 0x8000;
Ratan Guptab8e99552017-07-27 07:07:48 +0530198
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530199enum class IPOrigin: uint8_t
200{
201 UNSPECIFIED = 0,
202 STATIC = 1,
203 DHCP = 2,
204};
205
206
Ratan Gupta8c31d232017-08-13 05:49:43 +0530207}//namespace network
Ratan Gupta00659052017-02-23 17:29:08 +0530208}//namespace ipmi