blob: 62f7db7d828d430c050c63ffec5bb8ca27dc5841 [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;
Ratan Gupta00659052017-02-23 17:29:08 +0530118
Emily Shaffercc941e12017-06-14 13:06:26 -0700119enum class Mutability
120{
121 Read = 1 << 0,
122 Write = 1 << 1,
123};
124
125inline Mutability operator|(Mutability lhs, Mutability rhs)
126{
127 return static_cast<Mutability>(
128 static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
129}
130
131inline Mutability operator&(Mutability lhs, Mutability rhs)
132{
133 return static_cast<Mutability>(
134 static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
135}
136
Ratan Gupta00659052017-02-23 17:29:08 +0530137struct Info
138{
139 Type sensorType;
140 InstancePath sensorPath;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500141 DbusInterface sensorInterface;
Ratan Gupta00659052017-02-23 17:29:08 +0530142 ReadingType sensorReadingType;
Emily Shaffer10f49592017-05-10 12:01:10 -0700143 Multiplier coefficientM;
144 OffsetB coefficientB;
145 Exponent exponentB;
146 ScaledOffset scaledOffset;
Emily Shaffer62235612017-06-14 13:06:26 -0700147 bool hasScale;
148 Scale scale;
149 Unit unit;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500150 std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
Tom Joseph9f9a9a42017-09-07 01:17:28 +0530151 std::function<GetSensorResponse(const Info&)> getFunc;
Emily Shaffercc941e12017-06-14 13:06:26 -0700152 Mutability mutability;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500153 DbusInterfaceMap propertyInterfaces;
Ratan Gupta00659052017-02-23 17:29:08 +0530154};
155
156using Id = uint8_t;
157using IdInfoMap = std::map<Id,Info>;
158
Ratan Guptadcb10672017-07-10 10:33:50 +0530159using PropertyMap = ipmi::PropertyMap;
Tom Josephbe703f72017-03-09 12:34:35 +0530160
161using InterfaceMap = std::map<DbusInterface, PropertyMap>;
162
163using Object = sdbusplus::message::object_path;
164using ObjectMap = std::map<Object, InterfaceMap>;
165
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500166using IpmiUpdateData = sdbusplus::message::message;
167
Tom Josephdd78a1d2017-05-05 11:04:29 +0530168struct SelData
169{
170 Id sensorID;
171 Type sensorType;
172 ReadingType eventReadingType;
173 Offset eventOffset;
174};
175
176using InventoryPath = std::string;
177
178using InvObjectIDMap = std::map<InventoryPath, SelData>;
179
Ratan Gupta8c31d232017-08-13 05:49:43 +0530180}// namespace sensor
181
182namespace network
183{
Patrick Venturec01edf22017-12-22 14:03:06 -0800184using ChannelEthMap = std::map<int, std::string>;
Ratan Gupta8c31d232017-08-13 05:49:43 +0530185
186constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
187constexpr auto IP_ADDRESS_FORMAT = "%u.%u.%u.%u";
188constexpr auto PREFIX_FORMAT = "%hhd";
189constexpr auto ADDR_TYPE_FORMAT = "%hhx";
190
191constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
192constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;
193
194constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
195constexpr auto DEFAULT_ADDRESS = "0.0.0.0";
196
Ratan Guptab8e99552017-07-27 07:07:48 +0530197constexpr auto MAC_ADDRESS_SIZE_BYTE = 6;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530198constexpr auto VLAN_SIZE_BYTE = 2;
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530199constexpr auto IPSRC_SIZE_BYTE = 1;
Ratan Guptab8e99552017-07-27 07:07:48 +0530200constexpr auto BITS_32 = 32;
201constexpr auto MASK_32_BIT = 0xFFFFFFFF;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530202constexpr auto VLAN_ID_MASK = 0x00000FFF;
203constexpr auto VLAN_ENABLE_MASK = 0x8000;
Ratan Guptab8e99552017-07-27 07:07:48 +0530204
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530205enum class IPOrigin: uint8_t
206{
207 UNSPECIFIED = 0,
208 STATIC = 1,
209 DHCP = 2,
210};
211
212
Ratan Gupta8c31d232017-08-13 05:49:43 +0530213}//namespace network
Ratan Gupta00659052017-02-23 17:29:08 +0530214}//namespace ipmi