blob: d3be704f2d25edebf205025b2f67120c7a7fcc4f [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/**
54 * @struct SetSensorReadingReq
55 *
56 * IPMI Request data for Set Sensor Reading and Event Status Command
57 */
58struct SetSensorReadingReq
59{
60 uint8_t number;
61 uint8_t operation;
62 uint8_t reading;
63 uint8_t assertOffset0_7;
64 uint8_t assertOffset8_14;
65 uint8_t deassertOffset0_7;
66 uint8_t deassertOffset8_14;
67 uint8_t eventData1;
68 uint8_t eventData2;
69 uint8_t eventData3;
70} __attribute__((packed));
71
72/**
73 * @struct GetReadingResponse
74 *
75 * IPMI response data for Get Sensor Reading command.
76 */
77struct GetReadingResponse
78{
79 uint8_t reading; //!< Sensor reading.
80 uint8_t operation; //!< Sensor scanning status / reading state.
81 uint8_t assertOffset0_7; //!< Discrete assertion states(0-7).
82 uint8_t assertOffset8_14; //!< Discrete assertion states(8-14).
83} __attribute__((packed));
84
85constexpr auto inventoryRoot = "/xyz/openbmc_project/inventory";
86
87using GetSensorResponse = std::array<uint8_t, sizeof(GetReadingResponse)>;
88
Ratan Gupta00659052017-02-23 17:29:08 +053089using OffsetValueMap = std::map<Offset,Values>;
90
Ratan Gupta00659052017-02-23 17:29:08 +053091using DbusPropertyMap = std::map<DbusProperty,OffsetValueMap>;
92
Ratan Gupta00659052017-02-23 17:29:08 +053093using DbusInterfaceMap = std::map<DbusInterface,DbusPropertyMap>;
94
95using InstancePath = std::string;
96using Type = uint8_t;
97using ReadingType = uint8_t;
Emily Shaffer10f49592017-05-10 12:01:10 -070098using Multiplier = uint16_t;
99using OffsetB = uint16_t;
100using Exponent = uint8_t;
101using ScaledOffset = int64_t;
Ratan Gupta00659052017-02-23 17:29:08 +0530102
Emily Shaffercc941e12017-06-14 13:06:26 -0700103enum class Mutability
104{
105 Read = 1 << 0,
106 Write = 1 << 1,
107};
108
109inline Mutability operator|(Mutability lhs, Mutability rhs)
110{
111 return static_cast<Mutability>(
112 static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
113}
114
115inline Mutability operator&(Mutability lhs, Mutability rhs)
116{
117 return static_cast<Mutability>(
118 static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
119}
120
Ratan Gupta00659052017-02-23 17:29:08 +0530121struct Info
122{
123 Type sensorType;
124 InstancePath sensorPath;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500125 DbusInterface sensorInterface;
Ratan Gupta00659052017-02-23 17:29:08 +0530126 ReadingType sensorReadingType;
Emily Shaffer10f49592017-05-10 12:01:10 -0700127 Multiplier coefficientM;
128 OffsetB coefficientB;
129 Exponent exponentB;
130 ScaledOffset scaledOffset;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500131 std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
Tom Joseph9f9a9a42017-09-07 01:17:28 +0530132 std::function<GetSensorResponse(const Info&)> getFunc;
Emily Shaffercc941e12017-06-14 13:06:26 -0700133 Mutability mutability;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500134 DbusInterfaceMap propertyInterfaces;
Ratan Gupta00659052017-02-23 17:29:08 +0530135};
136
137using Id = uint8_t;
138using IdInfoMap = std::map<Id,Info>;
139
Ratan Guptadcb10672017-07-10 10:33:50 +0530140using PropertyMap = ipmi::PropertyMap;
Tom Josephbe703f72017-03-09 12:34:35 +0530141
142using InterfaceMap = std::map<DbusInterface, PropertyMap>;
143
144using Object = sdbusplus::message::object_path;
145using ObjectMap = std::map<Object, InterfaceMap>;
146
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500147using IpmiUpdateData = sdbusplus::message::message;
148
Tom Josephdd78a1d2017-05-05 11:04:29 +0530149struct SelData
150{
151 Id sensorID;
152 Type sensorType;
153 ReadingType eventReadingType;
154 Offset eventOffset;
155};
156
157using InventoryPath = std::string;
158
159using InvObjectIDMap = std::map<InventoryPath, SelData>;
160
Ratan Gupta8c31d232017-08-13 05:49:43 +0530161}// namespace sensor
162
163namespace network
164{
165
166constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
167constexpr auto IP_ADDRESS_FORMAT = "%u.%u.%u.%u";
168constexpr auto PREFIX_FORMAT = "%hhd";
169constexpr auto ADDR_TYPE_FORMAT = "%hhx";
170
171constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
172constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;
173
174constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
175constexpr auto DEFAULT_ADDRESS = "0.0.0.0";
176
Ratan Guptab8e99552017-07-27 07:07:48 +0530177constexpr auto MAC_ADDRESS_SIZE_BYTE = 6;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530178constexpr auto VLAN_SIZE_BYTE = 2;
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530179constexpr auto IPSRC_SIZE_BYTE = 1;
Ratan Guptab8e99552017-07-27 07:07:48 +0530180constexpr auto BITS_32 = 32;
181constexpr auto MASK_32_BIT = 0xFFFFFFFF;
Ratan Gupta533d03b2017-07-30 10:39:22 +0530182constexpr auto VLAN_ID_MASK = 0x00000FFF;
183constexpr auto VLAN_ENABLE_MASK = 0x8000;
Ratan Guptab8e99552017-07-27 07:07:48 +0530184
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530185enum class IPOrigin: uint8_t
186{
187 UNSPECIFIED = 0,
188 STATIC = 1,
189 DHCP = 2,
190};
191
192
Ratan Gupta8c31d232017-08-13 05:49:43 +0530193}//namespace network
Ratan Gupta00659052017-02-23 17:29:08 +0530194}//namespace ipmi