forked from openbmc/phosphor-host-ipmid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.hpp
232 lines (186 loc) · 5.59 KB
/
types.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#pragma once
#include <stdint.h>
#include <map>
#include <sdbusplus/server.hpp>
#include <string>
namespace ipmi
{
using DbusObjectPath = std::string;
using DbusService = std::string;
using DbusInterface = std::string;
using DbusObjectInfo = std::pair<DbusObjectPath, DbusService>;
using DbusProperty = std::string;
using Value = sdbusplus::message::variant<bool, uint8_t, int16_t, uint16_t,
int32_t, uint32_t, int64_t, uint64_t,
double, std::string>;
using PropertyMap = std::map<DbusProperty, Value>;
using ObjectTree =
std::map<DbusObjectPath, std::map<DbusService, std::vector<DbusInterface>>>;
using InterfaceList = std::vector<std::string>;
using DbusInterfaceMap = std::map<DbusInterface, PropertyMap>;
using ObjectValueTree =
std::map<sdbusplus::message::object_path, DbusInterfaceMap>;
namespace sensor
{
using Offset = uint8_t;
/**
* @enum SkipAssertion
* Matching value for skipping the update
*/
enum class SkipAssertion
{
NONE, // No skip defined
ASSERT, // Skip on Assert
DEASSERT, // Skip on Deassert
};
struct Values
{
SkipAssertion skip;
Value assert;
Value deassert;
};
/**
* @enum PreReqValues
* Pre-req conditions for a property.
*/
struct PreReqValues
{
Value assert; // Value in case of assert.
Value deassert; // Value in case of deassert.
};
using PreReqOffsetValueMap = std::map<Offset, PreReqValues>;
/**
* @struct SetSensorReadingReq
*
* IPMI Request data for Set Sensor Reading and Event Status Command
*/
struct SetSensorReadingReq
{
uint8_t number;
uint8_t operation;
uint8_t reading;
uint8_t assertOffset0_7;
uint8_t assertOffset8_14;
uint8_t deassertOffset0_7;
uint8_t deassertOffset8_14;
uint8_t eventData1;
uint8_t eventData2;
uint8_t eventData3;
} __attribute__((packed));
/**
* @struct GetReadingResponse
*
* IPMI response data for Get Sensor Reading command.
*/
struct GetReadingResponse
{
uint8_t reading; //!< Sensor reading.
uint8_t operation; //!< Sensor scanning status / reading state.
uint8_t assertOffset0_7; //!< Discrete assertion states(0-7).
uint8_t assertOffset8_14; //!< Discrete assertion states(8-14).
} __attribute__((packed));
constexpr auto inventoryRoot = "/xyz/openbmc_project/inventory";
using GetSensorResponse = std::array<uint8_t, sizeof(GetReadingResponse)>;
using OffsetValueMap = std::map<Offset, Values>;
using DbusPropertyValues = std::pair<PreReqOffsetValueMap, OffsetValueMap>;
using DbusPropertyMap = std::map<DbusProperty, DbusPropertyValues>;
using DbusInterfaceMap = std::map<DbusInterface, DbusPropertyMap>;
using InstancePath = std::string;
using Type = uint8_t;
using ReadingType = uint8_t;
using Multiplier = uint16_t;
using OffsetB = int16_t;
using Exponent = int8_t;
using ScaledOffset = double;
using Scale = int16_t;
using Unit = std::string;
using EntityType = uint8_t;
using EntityInst = uint8_t;
using SensorName = std::string;
enum class Mutability
{
Read = 1 << 0,
Write = 1 << 1,
};
inline Mutability operator|(Mutability lhs, Mutability rhs)
{
return static_cast<Mutability>(static_cast<uint8_t>(lhs) |
static_cast<uint8_t>(rhs));
}
inline Mutability operator&(Mutability lhs, Mutability rhs)
{
return static_cast<Mutability>(static_cast<uint8_t>(lhs) &
static_cast<uint8_t>(rhs));
}
struct Info
{
EntityType entityType;
EntityInst instance;
Type sensorType;
InstancePath sensorPath;
DbusInterface sensorInterface;
ReadingType sensorReadingType;
Multiplier coefficientM;
OffsetB coefficientB;
Exponent exponentB;
ScaledOffset scaledOffset;
Exponent exponentR;
bool hasScale;
Scale scale;
Unit unit;
std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
std::function<GetSensorResponse(const Info&)> getFunc;
Mutability mutability;
std::function<SensorName(const Info&)> sensorNameFunc;
DbusInterfaceMap propertyInterfaces;
};
using Id = uint8_t;
using IdInfoMap = std::map<Id, Info>;
using PropertyMap = ipmi::PropertyMap;
using InterfaceMap = std::map<DbusInterface, PropertyMap>;
using Object = sdbusplus::message::object_path;
using ObjectMap = std::map<Object, InterfaceMap>;
using IpmiUpdateData = sdbusplus::message::message;
struct SelData
{
Id sensorID;
Type sensorType;
ReadingType eventReadingType;
Offset eventOffset;
};
using InventoryPath = std::string;
using InvObjectIDMap = std::map<InventoryPath, SelData>;
enum class ThresholdMask
{
NON_CRITICAL_LOW_MASK = 0x01,
CRITICAL_LOW_MASK = 0x02,
NON_CRITICAL_HIGH_MASK = 0x08,
CRITICAL_HIGH_MASK = 0x10,
};
} // namespace sensor
namespace network
{
using ChannelEthMap = std::map<int, std::string>;
constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
constexpr auto IP_ADDRESS_FORMAT = "%u.%u.%u.%u";
constexpr auto PREFIX_FORMAT = "%hhd";
constexpr auto ADDR_TYPE_FORMAT = "%hhx";
constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;
constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
constexpr auto DEFAULT_ADDRESS = "0.0.0.0";
constexpr auto MAC_ADDRESS_SIZE_BYTE = 6;
constexpr auto VLAN_SIZE_BYTE = 2;
constexpr auto IPSRC_SIZE_BYTE = 1;
constexpr auto BITS_32 = 32;
constexpr auto MASK_32_BIT = 0xFFFFFFFF;
constexpr auto VLAN_ID_MASK = 0x00000FFF;
constexpr auto VLAN_ENABLE_MASK = 0x8000;
enum class IPOrigin : uint8_t
{
UNSPECIFIED = 0,
STATIC = 1,
DHCP = 2,
};
} // namespace network
} // namespace ipmi